mirror of
https://github.com/RGBCube/serenity
synced 2025-06-11 07:32:07 +00:00
LibJS/Tests: Compare results in Temporal.Now.plainDateTimeISO() test
This commit is contained in:
parent
2c85f076c8
commit
9ea8aa7ffe
1 changed files with 17 additions and 10 deletions
|
@ -15,17 +15,24 @@ describe("correct behavior", () => {
|
||||||
return 86400000000000;
|
return 86400000000000;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const plainDateTimeToEpochSeconds = plainDateTime =>
|
||||||
|
(plainDateTime.year - 1970) * 31_556_952 +
|
||||||
|
plainDateTime.month * 2_630_000 +
|
||||||
|
plainDateTime.day * 86_400 +
|
||||||
|
plainDateTime.hour * 3_600 +
|
||||||
|
plainDateTime.minute * 60 +
|
||||||
|
plainDateTime.second +
|
||||||
|
plainDateTime.millisecond / 1_000 +
|
||||||
|
plainDateTime.microsecond / 1_000_000 +
|
||||||
|
plainDateTime.nanosecond / 1_000_000_000;
|
||||||
|
|
||||||
const plainDateTime = Temporal.Now.plainDateTimeISO();
|
const plainDateTime = Temporal.Now.plainDateTimeISO();
|
||||||
const plainDateTimeWithOffset = Temporal.Now.plainDateTimeISO(timeZone);
|
const plainDateTimeWithOffset = Temporal.Now.plainDateTimeISO(timeZone);
|
||||||
// Yes, this will fail if a day, month, or year change happens between the above two lines :^)
|
// Let's hope the duration between the above two lines is less than a second :^)
|
||||||
// FIXME: enable these once the getters are implemented
|
const differenceSeconds =
|
||||||
// expect(plainDateTimeWithOffset.year).toBe(plainDateTime.year);
|
plainDateTimeToEpochSeconds(plainDateTimeWithOffset) -
|
||||||
// expect(plainDateTimeWithOffset.month).toBe(plainDateTime.month);
|
plainDateTimeToEpochSeconds(plainDateTime);
|
||||||
// expect(plainDateTimeWithOffset.day).toBe(plainDateTime.day + 1);
|
expect(Math.floor(differenceSeconds)).toBe(86400);
|
||||||
// expect(plainDateTimeWithOffset.hour).not.toBe(plainDateTime.hour);
|
|
||||||
// expect(plainDateTimeWithOffset.minute).not.toBe(plainDateTime.minute);
|
|
||||||
// expect(plainDateTimeWithOffset.second).not.toBe(plainDateTime.second);
|
|
||||||
// expect(plainDateTimeWithOffset.millisecond).not.toBe(plainDateTime.millisecond);
|
|
||||||
// microsecond, and nanosecond not checked here as they could easily be the same for both
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue