Skip to content

Commit a29b33e

Browse files
authored
chore: improve error message for faker.date.birthday (#1843)
1 parent e7230f6 commit a29b33e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/modules/date/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,12 @@ export class DateModule {
949949
refDate?: string | Date | number;
950950
} = {}
951951
): Date {
952+
if (options.max < options.min) {
953+
throw new FakerError(
954+
`Max ${options.max} should be larger than or equal to min ${options.min}.`
955+
);
956+
}
957+
952958
const mode = options.mode === 'age' ? 'age' : 'year';
953959
const refDate = toDate(options.refDate, this.faker.defaultRefDate);
954960
const refYear = refDate.getUTCFullYear();
@@ -973,10 +979,6 @@ export class DateModule {
973979
);
974980
}
975981

976-
if (max < min) {
977-
throw new FakerError(`Max ${max} should be larger then min ${min}.`);
978-
}
979-
980982
return new Date(this.faker.number.int({ min, max }));
981983
}
982984
}

test/date.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ describe('date', () => {
567567
faker.date.birthdate({ min, max, mode: 'year' })
568568
).toThrow(
569569
new FakerError(
570-
`Max 662515200000 should be larger then min 946771200000.`
570+
`Max 1990 should be larger than or equal to min 2000.`
571571
)
572572
);
573573
});

0 commit comments

Comments
 (0)