-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to check
nfOptions.roundingMode
for seconds / microseconds…
… / nanoseconds is `"trunc"` (#4115) * Test that `nfOptions.roundingMode` for seconds / microseconds / nanoseconds is `"trunc"` * Add license header * Use `Intl.NumberFormat` instead of `testintl.js` harness * Use correct harness
- Loading branch information
1 parent
8a2229c
commit 27b2551
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
test/intl402/DurationFormat/prototype/format/rounding-mode-trunc-for-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,70 @@ | ||
// 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: | | ||
nfOptions.roundingMode for seconds / microseconds / nanoseconds should be "trunc" | ||
info: | | ||
1.1.14 PartitionDurationFormatPattern | ||
(...) | ||
4. While numericUnitFound is false, repeat for each row in Table 2 in table order, except the header row: | ||
e. If style is "numeric" or "2-digit", then | ||
i. Append FormatNumericUnits(durationFormat, duration, unit, signDisplayed) to result. | ||
(...) | ||
f.Else, | ||
(...) | ||
ii. If unit is "seconds", "milliseconds", or "microseconds", then | ||
(...) | ||
f. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc"). | ||
1.1.12 FormatNumericUnits | ||
(...) | ||
18. If secondsFormatted is true, then | ||
a. Append FormatNumericSeconds(durationFormat, secondsValue, minutesFormatted, signDisplayed) to numericPartsList. | ||
(...) | ||
1.1.11 FormatNumericSeconds | ||
(...) | ||
15. Perform ! CreateDataPropertyOrThrow(nfOpts, "roundingMode", "trunc"). | ||
(...) | ||
locale: [en] | ||
features: [Intl.DurationFormat] | ||
---*/ | ||
|
||
const durations = [ | ||
// 1 | ||
{ | ||
fractionalDigits: 0, | ||
numericValue: 1.5, | ||
duration: { | ||
seconds: 1, | ||
milliseconds: 500, | ||
}, | ||
}, | ||
// 0.001 | ||
{ | ||
fractionalDigits: 3, | ||
numericValue: 0.0015, | ||
duration: { | ||
milliseconds: 1, | ||
microseconds: 500, | ||
} | ||
}, | ||
// 0.000001 | ||
{ | ||
fractionalDigits: 6, | ||
numericValue: 0.0000015, | ||
duration: { | ||
microseconds: 1, | ||
nanoseconds: 500 | ||
} | ||
} | ||
]; | ||
|
||
for (const { numericValue, fractionalDigits, duration } of durations) { | ||
const df = new Intl.DurationFormat("en", { seconds: "numeric", fractionalDigits }); | ||
const nf = new Intl.NumberFormat("en", { maximumFractionDigits: fractionalDigits, roundingMode: "trunc" }); | ||
const expected = nf.format(numericValue); | ||
assert.sameValue(df.format(duration), expected, 'Intl.DurationFormat should format seconds, milliseconds and microseconds with `roundingMode: "trunc"`'); | ||
} |