-
Notifications
You must be signed in to change notification settings - Fork 533
Add tests to Intl.DateTimeFormat and Intl.RelativeTimeFormat for various numbering systems
#4276
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
Merged
ptomato
merged 2 commits into
tc39:main
from
ben-allen:pr-919-datetimeformat-relativetimeformat-numbering-system
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
test/intl402/DateTimeFormat/prototype/format/numbering-system.js
This file contains hidden or 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,59 @@ | ||
| // Copyright 2024 Igalia, S.L. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-formatdatetimepattern | ||
| description: | | ||
| Checks that numberingSystem property used correctly. | ||
| info: > | ||
| 11.5.5 FormatDateTimePattern ( dateTimeFormat, format, pattern, epochNanoseconds ) | ||
| ... | ||
| 3. Perform ! CreateDataPropertyOrThrow(nfOptions, "numberingSystem", dateTimeFormat.[[NumberingSystem]]). | ||
| ... | ||
| 8. Perform ! CreateDataPropertyOrThrow(nf2Options, "numberingSystem", dateTimeFormat.[[NumberingSystem]]). | ||
| ... | ||
| 11. If format has a field [[fractionalSecondDigits]], then | ||
| ... | ||
| d. Perform ! CreateDataPropertyOrThrow(nf3Options, "numberingSystem", dateTimeFormat.[[NumberingSystem]]). | ||
|
|
||
| locale: [en-US, en-US-u-nu-arab, en-US-u-nu-deva, en-US-u-nu-hanidec] | ||
| ---*/ | ||
|
|
||
| const localesAndResults = [ | ||
| [ "en-US", "2:35:06", "2:35:06.789", "02:35:06", "6" ], | ||
| [ "en-US-u-nu-arab", "٢:٣٥:٠٦", "٢:٣٥:٠٦٫٧٨٩", "٠٢:٣٥:٠٦", "٦" ], | ||
| [ "en-US-u-nu-deva", "२:३५:०६", "२:३५:०६.७८९", "०२:३५:०६", "६" ], | ||
| [ "en-US-u-nu-hanidec", "二:三五:〇六", "二:三五:〇六.七八九", "〇二:三五:〇六 AM", "六" ], | ||
| ] | ||
| const time = new Date(2024, 0, 1, 2, 35, 6, 789); | ||
|
|
||
| for (const [locale, expectedNoFractional, expectedFractional, expectedTwoDigit, expectedAllNumeric] of localesAndResults) { | ||
| const formattedNoFractional = new Intl.DateTimeFormat(locale, { | ||
| hour: "numeric", | ||
| minute: "numeric", | ||
| second: "numeric", | ||
| }).format(time); | ||
|
|
||
| const formattedFractional = new Intl.DateTimeFormat(locale, { | ||
| hour: "numeric", | ||
| minute: "numeric", | ||
| second: "numeric", | ||
| fractionalSecondDigits: 3, | ||
| }).format(time); | ||
|
|
||
| const formattedTwoDigit = new Intl.DateTimeFormat(locale, { | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| second: "2-digit", | ||
| }).format(time); | ||
|
|
||
| const formattedAllNumeric = new Intl.DateTimeFormat(locale, { | ||
| second: "numeric", | ||
| }).format(time); | ||
|
|
||
| assert.sameValue(formattedNoFractional.includes(expectedNoFractional), true, `${locale}: display without fractionalSecondDigits`); | ||
| assert.sameValue(formattedFractional.includes(expectedFractional), true, `${locale}: display with fractionalSecondDigits`); | ||
| assert.sameValue(formattedTwoDigit.includes(expectedTwoDigit), true, `${locale}: display all time units in 2-digit`); | ||
| assert.sameValue(formattedAllNumeric.includes(expectedAllNumeric), true,`${locale}: display one numeric-styled unit`); | ||
| } | ||
|
|
27 changes: 27 additions & 0 deletions
27
test/intl402/RelativeTimeFormat/prototype/format/en-us-numbering-systems.js
This file contains hidden or 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,27 @@ | ||
| // Copyright 2024 Igalia, S.L. All rights reserved. | ||
| // This code is governed by the BSD license found in the LICENSE file. | ||
|
|
||
| /*--- | ||
| esid: sec-Intl.RelativeTimeFormat.prototype.format | ||
| description: Checks that numberingSystem option used correctly. | ||
| info: | | ||
| 17.5.2 PartitionRelativeTimePattern ( relativeTimeFormat, value, unit ) | ||
|
|
||
| 11. Let fv be PartitionNumberPattern(relativeTimeFormat.[[NumberFormat]], ℝ(value)). | ||
|
|
||
| locale: [en-US] | ||
| ---*/ | ||
|
|
||
| const localesAndResults = [ | ||
| ["en-US"], | ||
| ["en-US-u-nu-arab"], | ||
| ["en-US-u-nu-deva"], | ||
| ["en-US-u-nu-hanidec"], | ||
| ]; | ||
| const seconds = 1234567890; | ||
|
|
||
| for (const locale of localesAndResults){ | ||
| const formatted = new Intl.RelativeTimeFormat(locale, {style: "short"}).format(seconds, "seconds"); | ||
| const expected = new Intl.NumberFormat(locale).format(seconds); | ||
| assert.sameValue(formatted.includes(expected), true, `locale: ${locale}`); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.