mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-30 06:06:48 +00:00
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:
parent
912e38c5fb
commit
3c64e4595a
Notes:
github-actions[bot]
2024-12-04 13:02:26 +00:00
Author: https://github.com/trflynn89
Commit: 3c64e4595a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2731
Reviewed-by: https://github.com/shannonbooth
3 changed files with 57 additions and 30 deletions
|
@ -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", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue