File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { Helpers } from './helpers';
77import { Mersenne } from './mersenne' ;
88import { Name } from './name' ;
99import { Random } from './random' ;
10+ import { Time } from './time' ;
1011
1112export interface FakerOptions {
1213 locales ?: string [ ] ;
@@ -185,7 +186,7 @@ export class Faker {
185186 readonly name : Name = new Name ( this ) ;
186187 readonly phone = new ( require ( './phone_number' ) ) ( this ) ;
187188 readonly system = new ( require ( './system' ) ) ( this ) ;
188- readonly time = new ( require ( './time' ) ) ( this ) ;
189+ readonly time : Time = new Time ( ) ;
189190 readonly vehicle = new ( require ( './vehicle' ) ) ( this ) ;
190191 readonly word = new ( require ( './word' ) ) ( this ) ;
191192
Original file line number Diff line number Diff line change 1+ export class Time {
2+ /**
3+ * recent
4+ *
5+ * @method faker.time.recent
6+ * @param outputType 'abbr' || 'wide' || 'unix' (default choice)
7+ */
8+ recent ( outputType : 'abbr' | 'wide' | 'unix' = 'unix' ) : string | number {
9+ // TODO @Shinigami 92 2022-01-11: This is not non-deterministic
10+ // https://github.com/faker-js/faker/pull/74/files#r781579842
11+ let date : string | number | Date = new Date ( ) ;
12+
13+ switch ( outputType ) {
14+ case 'abbr' :
15+ date = date . toLocaleTimeString ( ) ;
16+ break ;
17+ case 'wide' :
18+ date = date . toTimeString ( ) ;
19+ break ;
20+ case 'unix' :
21+ // TODO @Shinigami 92 2022-01-10: add default case
22+ date = date . getTime ( ) ;
23+ break ;
24+ }
25+
26+ return date ;
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments