Skip to content

Commit

Permalink
fix plus operations that cross AD 100
Browse files Browse the repository at this point in the history
  • Loading branch information
icambron committed Feb 4, 2019
1 parent 652cd94 commit c16d7d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/impl/util.js
Expand Up @@ -138,7 +138,7 @@ export function objToLocalTS(obj) {
// for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
if (obj.year < 100 && obj.year >= 0) {
d = new Date(d);
d.setUTCFullYear(obj.year);
d.setUTCFullYear(d.getUTCFullYear() - 1900);
}
return +d;
}
Expand Down
14 changes: 14 additions & 0 deletions test/datetime/math.test.js
Expand Up @@ -89,6 +89,13 @@ test("DateTime#plus maintains invalidity", () => {
expect(DateTime.invalid("because").plus({ day: 1 }).isValid).toBe(false);
});

test("DateTime#plus works across the 100 barrier", () => {
const d = DateTime.fromISO("0099-12-31").plus({ day: 2 });
expect(d.year).toBe(100);
expect(d.month).toBe(1);
expect(d.day).toBe(2);
});

//------
// #minus()
//------
Expand Down Expand Up @@ -130,6 +137,13 @@ test("DateTime#minus maintains invalidity", () => {
expect(DateTime.invalid("because").minus({ day: 1 }).isValid).toBe(false);
});

test("DateTime#minus works across the 100 barrier", () => {
const d = DateTime.fromISO("0100-01-02").minus({ day: 2 });
expect(d.year).toBe(99);
expect(d.month).toBe(12);
expect(d.day).toBe(31);
});

//------
// #startOf()
//------
Expand Down

0 comments on commit c16d7d1

Please sign in to comment.