diff --git a/src/datetime.js b/src/datetime.js index 28cd40ce6..1856b0b3a 100644 --- a/src/datetime.js +++ b/src/datetime.js @@ -1502,7 +1502,12 @@ export default class DateTime { * @return {string} */ toISODate() { - return toTechFormat(this, "yyyy-MM-dd"); + let format = "yyyy-MM-dd"; + if (this.year > 9999) { + format = "+" + format; + } + + return toTechFormat(this, format); } /** diff --git a/test/datetime/format.test.js b/test/datetime/format.test.js index c6c14095b..6251d7507 100644 --- a/test/datetime/format.test.js +++ b/test/datetime/format.test.js @@ -54,6 +54,15 @@ test("DateTime#toISODate() returns null for invalid DateTimes", () => { expect(invalid.toISODate()).toBe(null); }); +test("DateTime#toISODate() returns ISO 8601 date in format [±YYYYY]", () => { + expect(DateTime.fromObject({ year: 118040, month: 5, day: 25, zone: "utc" }).toISODate()).toBe( + "+118040-05-25" + ); + expect(DateTime.fromObject({ year: -118040, month: 5, day: 25, zone: "utc" }).toISODate()).toBe( + "-118040-05-25" + ); +}); + //------ // #toISOWeekDate() //------