..
Viewing
time.ts
33 lines (31 loc) • 939.0 B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 | export class Time {
/**
* Returns recent time
*
* @param format 'abbr' || 'wide' || 'unix' (default)
*
* @example
* faker.time.recent() // 1643067231856
* faker.time.recent('abbr') // '12:34:07 AM'
* faker.time.recent('wide') // '00:34:11 GMT+0100 (Central European Standard Time)'
* faker.time.recent('unix') // 1643067231856
*/
recent(format: '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 (format) {
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;
}
}
|
|