aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorJohn Mal <[email protected]>2023-02-16 18:31:51 -0500
committerGitHub <[email protected]>2023-02-17 00:31:51 +0100
commita29b33ed2019c78f2c11f67e11aca154543202b0 (patch)
tree51eff5718feca5ed1b44375146ec78b5d9181699 /src/modules
parente7230f6f10af9633cf0eca18910cbafaaba9ecba (diff)
downloadfaker-a29b33ed2019c78f2c11f67e11aca154543202b0.tar.xz
faker-a29b33ed2019c78f2c11f67e11aca154543202b0.zip
chore: improve error message for faker.date.birthday (#1843)
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/date/index.ts10
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 }));
}
}