|
| 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