aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/faker.ts4
-rw-r--r--src/time.ts18
2 files changed, 16 insertions, 6 deletions
diff --git a/src/faker.ts b/src/faker.ts
index 25046b9a..83f59a06 100644
--- a/src/faker.ts
+++ b/src/faker.ts
@@ -28,7 +28,9 @@ import { Vehicle } from './vehicle';
import { Word } from './word';
// https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
-type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });
+export type LiteralUnion<T extends U, U = string> =
+ | T
+ | (U & { zz_IGNORE_ME?: never });
export type UsableLocale = LiteralUnion<KnownLocale>;
export type UsedLocales = Partial<Record<UsableLocale, LocaleDefinition>>;
diff --git a/src/time.ts b/src/time.ts
index df9c0c71..2d376839 100644
--- a/src/time.ts
+++ b/src/time.ts
@@ -1,3 +1,5 @@
+import type { LiteralUnion } from './faker';
+
/**
* Module to generate time of dates in various formats.
*/
@@ -5,17 +7,24 @@ export class Time {
/**
* Returns recent time.
*
- * @param format 'abbr' || 'wide' || 'unix' (default)
+ * @param format The format to use. Defaults to `'unix'`.
+ *
+ * - `'abbr'` Return a string with only the time. `Date.toLocaleTimeString`.
+ * - `'date'` Return a date instance.
+ * - `'wide'` Return a string with a long time. `Date.toTimeString()`.
+ * - `'unix'` Returns a unix timestamp.
*
* @example
* faker.time.recent() // 1643067231856
* faker.time.recent('abbr') // '12:34:07 AM'
+ * faker.time.recent('date') // 2022-03-01T20:35:47.402Z
* 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
+ recent(
+ format: LiteralUnion<'abbr' | 'date' | 'wide' | 'unix'> = 'unix'
+ ): string | number | Date {
+ // TODO ST-DDT 2022-03-01: Deprecate for removal - #557
let date: string | number | Date = new Date();
switch (format) {
@@ -26,7 +35,6 @@ export class Time {
date = date.toTimeString();
break;
case 'unix':
- // TODO @Shinigami92 2022-01-10: add default case
date = date.getTime();
break;
}