Skip to content

Commit c85603f

Browse files
sosukesuzukianba
andauthored
DurationFormat: Add tests for durations with style: "digital", hoursDisplay: "auto" and zero hours (#4367)
Co-authored-by: André Bargull <andre.bargull@gmail.com>
1 parent ab5c086 commit c85603f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (C) 2024 Sosuke Suzuki. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-Intl.DurationFormat.prototype.format
6+
description: >
7+
The separator isn't printed when style is digital, hoursDisplay is auto and hours value is zero
8+
locale: [en-US]
9+
features: [Intl.DurationFormat]
10+
---*/
11+
12+
const df = new Intl.DurationFormat("en", {
13+
style: "digital",
14+
hoursDisplay: "auto",
15+
});
16+
17+
const durations = [
18+
// basic zero hours
19+
[{ hours: 0, minutes: 0, seconds: 2 }, "00:02"],
20+
[{ hours: 0, minutes: 1, seconds: 2 }, "01:02"],
21+
[{ days: 1, hours: 0, minutes: 1, seconds: 2 }, "1 day, 01:02"],
22+
23+
// without hours
24+
[{ minutes: 0, seconds: 2 }, "00:02"],
25+
[{ minutes: 1, seconds: 2 }, "01:02"],
26+
[{ days: 1, minutes: 1, seconds: 2 }, "1 day, 01:02"],
27+
28+
// negative sign
29+
[{ hours: 0, minutes: -1, seconds: -2 }, "-01:02"],
30+
[{ hours: 0, minutes: -1, seconds: -2 }, "-01:02"],
31+
[{ days: -1, hours: 0, minutes: -1, seconds: -2 }, "-1 day, 01:02"],
32+
];
33+
34+
for (const [duration, expected] of durations) {
35+
assert.sameValue(df.format(duration), expected, `Duration is ${JSON.stringify(duration)}`);
36+
}

0 commit comments

Comments
 (0)