DurationFormat: Add tests for durations with `style: "digital"`, `hoursDisplay: "auto"` and zero hours (#4367)

Co-authored-by: André Bargull <andre.bargull@gmail.com>
This commit is contained in:
SUZUKI Sosuke 2025-01-13 19:25:44 +09:00 committed by GitHub
parent ab5c086db4
commit c85603ff11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
// Copyright (C) 2024 Sosuke Suzuki. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DurationFormat.prototype.format
description: >
The separator isn't printed when style is digital, hoursDisplay is auto and hours value is zero
locale: [en-US]
features: [Intl.DurationFormat]
---*/
const df = new Intl.DurationFormat("en", {
style: "digital",
hoursDisplay: "auto",
});
const durations = [
// basic zero hours
[{ hours: 0, minutes: 0, seconds: 2 }, "00:02"],
[{ hours: 0, minutes: 1, seconds: 2 }, "01:02"],
[{ days: 1, hours: 0, minutes: 1, seconds: 2 }, "1 day, 01:02"],
// without hours
[{ minutes: 0, seconds: 2 }, "00:02"],
[{ minutes: 1, seconds: 2 }, "01:02"],
[{ days: 1, minutes: 1, seconds: 2 }, "1 day, 01:02"],
// negative sign
[{ hours: 0, minutes: -1, seconds: -2 }, "-01:02"],
[{ hours: 0, minutes: -1, seconds: -2 }, "-01:02"],
[{ days: -1, hours: 0, minutes: -1, seconds: -2 }, "-1 day, 01:02"],
];
for (const [duration, expected] of durations) {
assert.sameValue(df.format(duration), expected, `Duration is ${JSON.stringify(duration)}`);
}