diff options
| author | Piotr Kuczynski <[email protected]> | 2022-01-30 22:08:59 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-01-30 22:08:59 +0100 |
| commit | 9d5a7a2533c569fa1cad2dacb6ae223644bb98cb (patch) | |
| tree | d499f709c5f48a562e427be0c69d61ddd2fda2fe /src | |
| parent | 4d81ac46f169c4150f59ef3a3e790578028b57d1 (diff) | |
| download | faker-9d5a7a2533c569fa1cad2dacb6ae223644bb98cb.tar.xz faker-9d5a7a2533c569fa1cad2dacb6ae223644bb98cb.zip | |
fix: remove redundant precision from datatype.datetime options (#335)
Diffstat (limited to 'src')
| -rw-r--r-- | src/datatype.ts | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/datatype.ts b/src/datatype.ts index 7cf28012..ef7f5709 100644 --- a/src/datatype.ts +++ b/src/datatype.ts @@ -95,29 +95,21 @@ export class Datatype { * @method faker.datatype.datetime * @param options pass min OR max as number of milliseconds since 1. Jan 1970 UTC */ - datetime( - options?: number | { min?: number; max?: number; precision?: number } - ): Date { - if (typeof options === 'number') { - options = { - max: options, - }; - } - + datetime(options?: number | { min?: number; max?: number }): Date { const minMax = 8640000000000000; - options = options || {}; + let min = typeof options === 'number' ? undefined : options?.min; + let max = typeof options === 'number' ? options : options?.max; - if (typeof options.min === 'undefined' || options.min < minMax * -1) { - options.min = new Date().setFullYear(1990, 1, 1); + if (typeof min === 'undefined' || min < minMax * -1) { + min = new Date().setFullYear(1990, 1, 1); } - if (typeof options.max === 'undefined' || options.max > minMax) { - options.max = new Date().setFullYear(2100, 1, 1); + if (typeof max === 'undefined' || max > minMax) { + max = new Date().setFullYear(2100, 1, 1); } - const random = this.faker.datatype.number(options); - return new Date(random); + return new Date(this.faker.datatype.number({ min, max })); } /** |
