-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for numeric hours with zero minutes and non-zero seconds
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...02/DurationFormat/prototype/format/numeric-hour-with-zero-minutes-and-non-zero-seconds.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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: > | ||
The correct separator is used for numeric hours with zero minutes and non-zero seconds. | ||
locale: [en-US] | ||
features: [Intl.DurationFormat] | ||
---*/ | ||
|
||
const df = new Intl.DurationFormat("en", { | ||
// hours must be numeric, so that a time separator is used for the following units. | ||
hours: "numeric", | ||
}); | ||
|
||
const lf = new Intl.ListFormat("en", { | ||
type: "unit", | ||
style: "short", | ||
}); | ||
|
||
const duration = { | ||
hours: 1, | ||
|
||
// Minutes is omitted from the output when its value is zero. | ||
minutes: 0, | ||
|
||
// Either seconds or sub-seconds must be non-zero. | ||
seconds: 3, | ||
}; | ||
|
||
const expected = lf.format([ | ||
new Intl.NumberFormat("en", {minimumIntegerDigits: 1}).format(duration.hours), | ||
new Intl.NumberFormat("en", {minimumIntegerDigits: 2}).format(duration.seconds), | ||
]); | ||
|
||
assert.sameValue( | ||
df.format(duration), | ||
expected, | ||
`No time separator is used when minutes is zero` | ||
); |