Skip to content

Commit

Permalink
fix: DateTime throws when year is invalid and throwOnInvalid is true (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
oxcened authored Nov 14, 2023
1 parent 825b77a commit 11ad011
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,10 @@ export default class DateTime {
);
}

if (!inst.isValid) {
return DateTime.invalid(inst.invalid);
}

return inst;
}

Expand Down
15 changes: 15 additions & 0 deletions test/datetime/invalid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,18 @@ test("throwOnInvalid throws", () => {
test("DateTime.invalid throws if you don't provide a reason", () => {
expect(() => DateTime.invalid()).toThrow();
});

test("throwOnInvalid throws if year is too big", () => {
try {
Settings.throwOnInvalid = true;
expect(() =>
DateTime.fromObject({
year: 9999999,
month: 5,
day: 25,
})
).toThrow();
} finally {
Settings.throwOnInvalid = false;
}
});

0 comments on commit 11ad011

Please sign in to comment.