Skip to content

Commit 70914c0

Browse files
ST-DDTmatthewmayer
authored andcommitted
chore: fix missing defaultRefDate calls (faker-js#1781)
1 parent ebc0a92 commit 70914c0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/modules/date/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { deprecated } from '../../internal/deprecated';
1111
* @param fallback The fallback date to use if the passed date is not valid.
1212
*/
1313
function toDate(
14-
date?: string | Date | number,
15-
fallback: () => Date = () => new Date()
14+
date: string | Date | number | undefined,
15+
fallback: () => Date
1616
): Date {
1717
date = new Date(date);
1818
if (isNaN(date.valueOf())) {
@@ -370,8 +370,8 @@ export class DateModule {
370370

371371
const { from, to } = options;
372372

373-
const fromMs = toDate(from).getTime();
374-
const toMs = toDate(to).getTime();
373+
const fromMs = toDate(from, this.faker.defaultRefDate).getTime();
374+
const toMs = toDate(to, this.faker.defaultRefDate).getTime();
375375
const dateOffset = this.faker.number.int(toMs - fromMs);
376376

377377
return new Date(fromMs + dateOffset);
@@ -948,7 +948,7 @@ export class DateModule {
948948
} = {}
949949
): Date {
950950
const mode = options.mode === 'age' ? 'age' : 'year';
951-
const refDate = toDate(options.refDate);
951+
const refDate = toDate(options.refDate, this.faker.defaultRefDate);
952952
const refYear = refDate.getUTCFullYear();
953953

954954
// If no min or max is specified, generate a random date between (now - 80) years and (now - 18) years respectively

0 commit comments

Comments
 (0)