From a29b33ed2019c78f2c11f67e11aca154543202b0 Mon Sep 17 00:00:00 2001 From: John Mal <56036354+johnmal-dev@users.noreply.github.com> Date: Thu, 16 Feb 2023 18:31:51 -0500 Subject: chore: improve error message for faker.date.birthday (#1843) --- src/modules/date/index.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/modules') diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index d7a0f12a..7156bf22 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -949,6 +949,12 @@ export class DateModule { refDate?: string | Date | number; } = {} ): Date { + if (options.max < options.min) { + throw new FakerError( + `Max ${options.max} should be larger than or equal to min ${options.min}.` + ); + } + const mode = options.mode === 'age' ? 'age' : 'year'; const refDate = toDate(options.refDate, this.faker.defaultRefDate); const refYear = refDate.getUTCFullYear(); @@ -973,10 +979,6 @@ export class DateModule { ); } - if (max < min) { - throw new FakerError(`Max ${max} should be larger then min ${min}.`); - } - return new Date(this.faker.number.int({ min, max })); } } -- cgit v1.2.3