Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chrome prints "1 day:01:02" for this, which is correct?


// 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 ${duration}`);
}
Loading