Skip to content

Commit

Permalink
feat: migrate time
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed Jan 10, 2022
1 parent 75bebff commit 36b1080
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Datatype } from './datatype';
import { Mersenne } from './mersenne';
import { Random } from './random';
import { Time } from './time';

export interface FakerOptions {
locales?: string[];
Expand All @@ -17,6 +18,7 @@ export class Faker {

readonly mersenne: Mersenne = new Mersenne();
random = new Random(this);
time: Time = new Time();
datatype: Datatype = new Datatype(this);

constructor(opts: FakerOptions = {}) {
Expand Down
26 changes: 26 additions & 0 deletions src/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export class Time {
/**
* recent
*
* @method faker.time.recent
* @param outputType 'abbr' || 'wide' || 'unix' (default choice)
*/
recent(outputType: 'abbr' | 'wide' | 'unix' = 'unix'): string | number {
let date: string | number | Date = new Date();

switch (outputType) {
case 'abbr':
date = date.toLocaleTimeString();
break;
case 'wide':
date = date.toTimeString();
break;
case 'unix':
// TODO @Shinigami92 2022-01-10: add default case
date = date.getTime();
break;
}

return date;
}
}

0 comments on commit 36b1080

Please sign in to comment.