Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate time #74

Merged
merged 2 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Helpers } from './helpers';
import { Mersenne } from './mersenne';
import { Name } from './name';
import { Random } from './random';
import { Time } from './time';

export interface FakerOptions {
locales?: string[];
Expand Down Expand Up @@ -185,7 +186,7 @@ export class Faker {
readonly name: Name = new Name(this);
readonly phone = new (require('./phone_number'))(this);
readonly system = new (require('./system'))(this);
readonly time = new (require('./time'))(this);
readonly time: Time = new Time();
readonly vehicle = new (require('./vehicle'))(this);
readonly word = new (require('./word'))(this);

Expand Down
28 changes: 28 additions & 0 deletions src/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export class Time {
/**
* recent
*
* @method faker.time.recent
* @param outputType 'abbr' || 'wide' || 'unix' (default choice)
*/
recent(outputType: 'abbr' | 'wide' | 'unix' = 'unix'): string | number {
// TODO @Shinigami92 2022-01-11: This is not non-deterministic
// https://github.com/faker-js/faker/pull/74/files#r781579842
let date: string | number | Date = new Date();
prisis marked this conversation as resolved.
Show resolved Hide resolved

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;
}
}