Skip to content

Commit

Permalink
fix: remove redundant precision from datatype.datetime options (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkuczynski authored Jan 30, 2022
1 parent 4d81ac4 commit 9d5a7a2
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/datatype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}

/**
Expand Down

0 comments on commit 9d5a7a2

Please sign in to comment.