From c227fcde40dc7ba293a4d7a598e17409a81532e1 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Tue, 1 Mar 2022 22:13:52 +0100 Subject: [PATCH] fix: fix time.recent method signature --- src/faker.ts | 4 +++- src/time.ts | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/faker.ts b/src/faker.ts index 25046b9a62e..83f59a06259 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 | (U & { zz_IGNORE_ME?: never }); +export type LiteralUnion = + | T + | (U & { zz_IGNORE_ME?: never }); export type UsableLocale = LiteralUnion; export type UsedLocales = Partial>; diff --git a/src/time.ts b/src/time.ts index df9c0c719bb..2d376839a06 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; }