1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// |reftest| skip -- Intl.DurationFormat is not supported
// Copyright (C) 2023 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.format
description: >
PartitionDurationFormatPattern computes on exact mathematical values.
info: |
PartitionDurationFormatPattern ( durationFormat, duration )
...
4. While done is false, repeat for each row in Table 1 in order, except the header row:
...
j. If unit is "seconds", "milliseconds", or "microseconds", then
i. If unit is "seconds", then
1. Let nextStyle be durationFormat.[[MillisecondsStyle]].
...
iv. If nextStyle is "numeric", then
1. If unit is "seconds", then
a. Set value to value + duration.[[Milliseconds]] / 10^3 + duration.[[Microseconds]] / 10^6 + duration.[[Nanoseconds]] / 10^9.
...
l. If value is not 0 or display is not "auto", then
ii. If style is "2-digit" or "numeric", then
...
7. Let parts be ! PartitionNumberPattern(nf, value).
...
locale: [en-US]
includes: [testIntl.js]
features: [Intl.DurationFormat]
---*/
const durations = [
// 10000000 + (1 / 10^9)
// = 10000000.000000001
{
seconds: 10_000_000,
nanoseconds: 1,
},
// 9007199254740991 + (9007199254740991 / 10^3) + (9007199254740991 / 10^6) + (9007199254740991 / 10^9)
// = 9.016215470202185986731991 × 10^15
{
seconds: Number.MAX_SAFE_INTEGER,
milliseconds: Number.MAX_SAFE_INTEGER,
microseconds: Number.MAX_SAFE_INTEGER,
nanoseconds: Number.MAX_SAFE_INTEGER,
},
{
seconds: Number.MIN_SAFE_INTEGER,
milliseconds: Number.MIN_SAFE_INTEGER,
microseconds: Number.MIN_SAFE_INTEGER,
nanoseconds: Number.MIN_SAFE_INTEGER,
},
// 1 + (2 / 10^3) + (3 / 10^6) + (9007199254740991 / 10^9)
// = 9.007200256743991 × 10^6
{
seconds: 1,
milliseconds: 2,
microseconds: 3,
nanoseconds: Number.MAX_SAFE_INTEGER,
},
// 9007199254740991 + (10^3 / 10^3) + (10^6 / 10^6) + (10^9 / 10^9)
// = 9007199254740991 + 3
// = 9007199254740994
{
seconds: Number.MAX_SAFE_INTEGER,
milliseconds: 10 ** 3,
microseconds: 10 ** 6,
nanoseconds: 10 ** 9,
},
// ~1.7976931348623157e+308 / 10^9
// = ~1.7976931348623157 × 10^299
{
seconds: 0,
milliseconds: 0,
microseconds: 0,
nanoseconds: Number.MAX_VALUE,
},
];
const df = new Intl.DurationFormat("en", {style: "digital"});
for (let duration of durations) {
let expected = formatDurationFormatPattern(duration, "digital");
assert.sameValue(
df.format(duration),
expected,
`Duration is ${JSON.stringify(duration)}`
);
}
reportCompare(0, 0);
|