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
|
// |reftest| skip -- Intl.DurationFormat is not supported
// Copyright (C) 2023 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-partitiondurationformatpattern
description: >
Test to ensure that correct number of fractional digits is displayed (i.e. however many are necessary to represent the data fully) if the fractionalDigits option is left *undefined*
info: |
4. If durationFormat.[[FractionalDigits]] is undefined, then
a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", 9).
b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", 0).
5. Else,
a. Perform ! CreateDataPropertyOrThrow(nfOpts, "maximumFractionDigits", durationFormat.[[FractionalDigits]]).
b. Perform ! CreateDataPropertyOrThrow(nfOpts, "minimumFractionDigits", durationFormat.[[FractionalDigits]]).
features: [Intl.DurationFormat]
---*/
const durationNano = {
hours: 1,
minutes: 22,
seconds: 33,
milliseconds: 111,
microseconds: 222,
nanoseconds: 333
};
const durationMicro = {
hours: 1,
minutes: 22,
seconds: 33,
milliseconds: 111,
microseconds: 222
};
const durationMill = {
hours: 1,
minutes: 22,
seconds: 33,
milliseconds: 111
};
const durationNoSubsecond = {
hours: 1,
minutes: 22,
seconds: 33
};
const durationSevenFractional = {
hours: 2,
minutes: 30,
seconds: 10,
milliseconds: 111,
microseconds: 220,
nanoseconds: 300
};
const style = "digital";
const df = new Intl.DurationFormat(undefined, {style, fractionalDigits: undefined});
assert.sameValue(df.format(durationNano), "1:22:33.111222333", `format output with nanosecond digits and fractionalDigits: undefined using ${style} style option`);
assert.sameValue(df.format(durationMicro), "1:22:33.111222", `format output with microsecond digits and fractionalDigits: undefined using ${style} style option`);
assert.sameValue(df.format(durationMilli), "1:22:33.111", `format output with millisecond digits and fractionalDigits: undefined using ${style} style option`);
assert.sameValue(df.format(durationNoSubsecond), "1:22:33", `format output with no subsecond digits and fractionalDigits: undefined using ${style} style option`);
assert.sameValue(df.format(durationFiveFractional), "2:30:11122", `format output with five subsecond digits and fractionalDigits: undefined using ${style} style option`);
assert.sameValue(df.format(durationSevenFractional), "2:30:1112203", `format output with seven subsecond digits and fractionalDigits: undefined using ${style} style option`);
reportCompare(0, 0);
|