Skip to content

Commit

Permalink
fixed ISO [±YYYYY] formating (#505)
Browse files Browse the repository at this point in the history
* fixed ISO [±YYYYY] formating
  • Loading branch information
waseemahmad31 authored and icambron committed May 8, 2019
1 parent 5cd2e7a commit 236f2ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/datetime.js
Expand Up @@ -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);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/datetime/format.test.js
Expand Up @@ -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()
//------
Expand Down

0 comments on commit 236f2ba

Please sign in to comment.