File tree 2 files changed +30
-1
lines changed 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { Helpers } from './helpers';
7
7
import { Mersenne } from './mersenne' ;
8
8
import { Name } from './name' ;
9
9
import { Random } from './random' ;
10
+ import { Time } from './time' ;
10
11
11
12
export interface FakerOptions {
12
13
locales ?: string [ ] ;
@@ -185,7 +186,7 @@ export class Faker {
185
186
readonly name : Name = new Name ( this ) ;
186
187
readonly phone = new ( require ( './phone_number' ) ) ( this ) ;
187
188
readonly system = new ( require ( './system' ) ) ( this ) ;
188
- readonly time = new ( require ( './time' ) ) ( this ) ;
189
+ readonly time : Time = new Time ( ) ;
189
190
readonly vehicle = new ( require ( './vehicle' ) ) ( this ) ;
190
191
readonly word = new ( require ( './word' ) ) ( this ) ;
191
192
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