-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bb491c
commit 6d57002
Showing
2 changed files
with
30 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
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; | ||
} | ||
} |