mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:17:46 +00:00
LibJS/Tests: Fix Temporal.Now.plainDate{,ISO}() at end of month/year
Evidently, going one day forward on the last day of month increases the month number by one and resets the day to 1. Doing the same on the last day of the year resets the month to 1.
This commit is contained in:
parent
57e2a38de0
commit
cab1015a03
2 changed files with 28 additions and 8 deletions
|
@ -19,9 +19,19 @@ describe("correct behavior", () => {
|
|||
};
|
||||
const plainDate = Temporal.Now.plainDate(calendar);
|
||||
const plainDateWithOffset = Temporal.Now.plainDate(calendar, timeZone);
|
||||
// Yes, this will fail if a day, month, or year change happens between the above two lines :^)
|
||||
expect(plainDateWithOffset.year).toBe(plainDate.year);
|
||||
expect(plainDateWithOffset.month).toBe(plainDate.month);
|
||||
expect(plainDateWithOffset.day).toBe(plainDate.day + 1);
|
||||
if (plainDate.dayOfYear === plainDate.daysInYear) {
|
||||
expect(plainDateWithOffset.year).toBe(plainDate.year + 1);
|
||||
expect(plainDateWithOffset.month).toBe(1);
|
||||
expect(plainDateWithOffset.day).toBe(1);
|
||||
} else {
|
||||
expect(plainDateWithOffset.year).toBe(plainDate.year);
|
||||
if (plainDate.day === plainDate.daysInMonth) {
|
||||
expect(plainDateWithOffset.month).toBe(plainDate.month + 1);
|
||||
expect(plainDateWithOffset.day).toBe(1);
|
||||
} else {
|
||||
expect(plainDateWithOffset.month).toBe(plainDate.month);
|
||||
expect(plainDateWithOffset.day).toBe(plainDate.day + 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue