diff --git a/src/datetime.js b/src/datetime.js index f98d183f5..9472cb531 100644 --- a/src/datetime.js +++ b/src/datetime.js @@ -810,6 +810,10 @@ export default class DateTime { ); } + if (!inst.isValid) { + return DateTime.invalid(inst.invalid); + } + return inst; } diff --git a/test/datetime/invalid.test.js b/test/datetime/invalid.test.js index a776e1854..d13fb8643 100644 --- a/test/datetime/invalid.test.js +++ b/test/datetime/invalid.test.js @@ -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; + } +});