1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:28:11 +00:00

LibJS: Fix modulo in get_iso_parts_from_epoch() for negative epoch ns

This now matches the spec change from reminder() to modulo which was
done here: bdf60f5
This commit is contained in:
Linus Groh 2021-12-21 21:38:12 +01:00
parent 61410e05eb
commit c56e5139f5
2 changed files with 7 additions and 1 deletions

View file

@ -121,7 +121,7 @@ ISODateTime get_iso_parts_from_epoch(BigInt const& epoch_nanoseconds)
// 1. Assert: epochNanoseconds is an integer.
// 2. Let remainderNs be epochNanoseconds modulo 10^6.
auto remainder_ns_bigint = epoch_nanoseconds.big_integer().divided_by(Crypto::UnsignedBigInteger { 1'000'000 }).remainder;
auto remainder_ns_bigint = modulo(epoch_nanoseconds.big_integer(), Crypto::UnsignedBigInteger { 1'000'000 });
auto remainder_ns = remainder_ns_bigint.to_double();
// 3. Let epochMilliseconds be (epochNanoseconds remainderNs) / 10^6.

View file

@ -10,6 +10,12 @@ describe("correct behavior", () => {
expect(zonedDateTime.toString()).toBe("2021-11-03T01:33:05.1002003+00:00[UTC]");
});
test("negative epoch nanoseconds", () => {
const timeZone = new Temporal.TimeZone("UTC");
const zonedDateTime = new Temporal.ZonedDateTime(-999_999_999n, timeZone);
expect(zonedDateTime.toString()).toBe("1969-12-31T23:59:59.000000001+00:00[UTC]");
});
test("fractionalSecondDigits option", () => {
const plainDateTime = new Temporal.PlainDateTime(2021, 11, 3, 1, 33, 5, 100, 200, 300);
const timeZone = new Temporal.TimeZone("UTC");