diff options
| author | John Mal <[email protected]> | 2023-02-16 18:31:51 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-17 00:31:51 +0100 |
| commit | a29b33ed2019c78f2c11f67e11aca154543202b0 (patch) | |
| tree | 51eff5718feca5ed1b44375146ec78b5d9181699 /src/modules/date | |
| parent | e7230f6f10af9633cf0eca18910cbafaaba9ecba (diff) | |
| download | faker-a29b33ed2019c78f2c11f67e11aca154543202b0.tar.xz faker-a29b33ed2019c78f2c11f67e11aca154543202b0.zip | |
chore: improve error message for faker.date.birthday (#1843)
Diffstat (limited to 'src/modules/date')
| -rw-r--r-- | src/modules/date/index.ts | 10 |
1 files changed, 6 insertions, 4 deletions
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 })); } } |
