1 // |reftest| skip -- Intl.DurationFormat is not supported
2 // Copyright 2024 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
6 esid: sec-Intl.DurationFormat.prototype.format
7 description: Test if format method formats duration correctly with mixed non-numeric settings for unit styles. Compares output from format method to output produced through using NumberFormat and ListFormat as used by DurationFormat.
9 PartitionDurationFormatPattern ( durationFormat, duration )
11 9. While done is false, repeat for each row in Table 2 in table order, except the header row:
13 k. If value is not 0 or display is not "auto" or displayRequired is "true", then
15 v. If style is not "fractional", "numeric", or "2-digit", then
16 1. Perform ! CreateDataPropertyOrThrow(nfOpts, "style", "unit").
17 2. Perform ! CreateDataPropertyOrThrow(nfOpts, "unit", numberFormatUnit).
18 3. Perform ! CreateDataPropertyOrThrow(nfOpts, "unitDisplay", style).
20 ix. Let parts be ! PartitionNumberPattern(nf, value).
22 14. Perform ! CreateDataPropertyOrThrow(lfOpts, "style", listStyle).
23 15. Let lf be ! Construct(%ListFormat%, « durationFormat.[[Locale]], lfOpts »).
25 18. Let formatted be CreatePartsFromList(lf, strings).
28 features: [Intl.DurationFormat]
31 function formatDuration(locale, duration, dfOpts){
33 for (const unit in duration){
34 let nfUnit = unit.substring(0, unit.length - 1);
35 let nf = new Intl.NumberFormat(locale, {style: "unit", unit: nfUnit, unitDisplay: dfOpts[unit]});
36 result.push(nf.format(duration[unit]));
39 for (const baseStyle of ["long", "short", "narrow"]){
40 let lf = new Intl.ListFormat(locale, {type: "unit", style: baseStyle});
41 let expected = lf.format(result);
42 dfOpts.style = baseStyle;
43 let df = new Intl.DurationFormat(locale, dfOpts);
44 let actual = df.format(duration);
45 assert.sameValue(actual, expected);
64 formatDuration(locale, duration, {
74 nanoseconds: "narrow", });
76 formatDuration(locale, duration, {
84 milliseconds: "short",
85 microseconds: "narrow",
86 nanoseconds: "long", });