LibJS: Use exact mathematical values for Intl.DurationFormat

We can't use doubles due to precision loss for extremely large values.
This commit is contained in:
Timothy Flynn 2024-12-03 11:51:09 -05:00 committed by Tim Flynn
commit 3c64e4595a
Notes: github-actions[bot] 2024-12-04 13:02:26 +00:00
3 changed files with 57 additions and 30 deletions

View file

@ -145,6 +145,24 @@ describe("correct behavior", () => {
const de = new Intl.DurationFormat("de", { style: "digital" });
expect(de.format(duration)).toBe("123456:456789:789123");
});
test("precise mathematical values", () => {
const en = new Intl.DurationFormat("en", { style: "digital" });
let duration = {
seconds: 10000000,
nanoseconds: 1,
};
expect(en.format(duration)).toBe("0:00:10000000.000000001");
duration = {
seconds: 1,
milliseconds: 2,
microseconds: 3,
nanoseconds: Number.MAX_SAFE_INTEGER,
};
expect(en.format(duration)).toBe("0:00:9007200.256743991");
});
});
describe("errors", () => {