From 5d03dbfb4e1a698d78d64d6a25ef67f337232646 Mon Sep 17 00:00:00 2001 From: John Malapit Date: Tue, 14 Feb 2023 18:19:51 -0500 Subject: [PATCH 1/2] improve error message in birthday --- src/modules/date/index.ts | 8 ++++---- test/date.spec.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index c99a7d19be6..5dfe9456443 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -947,6 +947,10 @@ 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(); @@ -971,10 +975,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 })); } } diff --git a/test/date.spec.ts b/test/date.spec.ts index b0eec16c9b4..af55508c8bf 100644 --- a/test/date.spec.ts +++ b/test/date.spec.ts @@ -567,7 +567,7 @@ describe('date', () => { faker.date.birthdate({ min, max, mode: 'year' }) ).toThrow( new FakerError( - `Max 662515200000 should be larger then min 946771200000.` + `Max 1990 should be larger than or equal to min 2000.` ) ); }); From 857f4d7067b528f6b749aa5e6dae9029c9130ac9 Mon Sep 17 00:00:00 2001 From: John Malapit Date: Wed, 15 Feb 2023 12:38:13 -0500 Subject: [PATCH 2/2] fix lint error --- src/modules/date/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/date/index.ts b/src/modules/date/index.ts index 5dfe9456443..747ae16a36d 100644 --- a/src/modules/date/index.ts +++ b/src/modules/date/index.ts @@ -948,7 +948,9 @@ export class DateModule { } = {} ): Date { if (options.max < options.min) { - throw new FakerError(`Max ${options.max} should be larger than or equal to min ${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';