Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove redundant precision from datatype.datetime options #335

Merged
merged 3 commits into from
Jan 30, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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