-
-
Notifications
You must be signed in to change notification settings - Fork 626
feat(intl): implement Temporal.PlainYearMonth.prototype.toLocaleString #5098
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
Open
alienx5499
wants to merge
10
commits into
boa-dev:main
Choose a base branch
from
alienx5499:feat/5083-plainyearmonth-tolocalestring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fceb44a
feat(intl): implement Temporal.PlainYearMonth.prototype.toLocaleString
alienx5499 3f5d49e
fix(intl): align Temporal.PlainYearMonth.prototype.toLocaleString wit…
alienx5499 2220871
Merge branch 'main' into feat/5083-plainyearmonth-tolocalestring
alienx5499 e887556
fix(intl): avoid Date style defaults in PlainYearMonth.toLocaleString
alienx5499 f911f96
Merge branch 'main' into feat/5083-plainyearmonth-tolocalestring
alienx5499 ea730d8
refactor(intl): extract HandleDateTimeValue dispatcher for Temporal f…
alienx5499 0b41c72
Merge branch 'main' into feat/5083-plainyearmonth-tolocalestring
alienx5499 c1b5bfb
Merge branch 'main' into feat/5083-plainyearmonth-tolocalestring
alienx5499 a1db048
fix(intl): stop forcing dateStyle/timeStyle defaults in Date locale f…
alienx5499 a3ed91b
Merge branch 'main' into feat/5083-plainyearmonth-tolocalestring
alienx5499 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
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
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
79 changes: 79 additions & 0 deletions
79
core/engine/src/builtins/temporal/plain_year_month/tests.rs
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,79 @@ | ||
| use crate::{JsNativeErrorKind, TestAction, run_test_actions}; | ||
|
|
||
| #[test] | ||
| fn to_locale_string_returns_string() { | ||
| run_test_actions([ | ||
| TestAction::assert( | ||
| "typeof Temporal.PlainYearMonth.from('2024-03').toLocaleString() === 'string'", | ||
| ), | ||
| TestAction::assert("Temporal.PlainYearMonth.from('2024-03').toLocaleString().length > 0"), | ||
| ]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn to_locale_string_invalid_receiver_throws() { | ||
| run_test_actions([TestAction::assert_native_error( | ||
| "Temporal.PlainYearMonth.prototype.toLocaleString.call({})", | ||
| JsNativeErrorKind::Type, | ||
| "this value must be a PlainYearMonth object.", | ||
| )]); | ||
| } | ||
|
|
||
| #[cfg(feature = "intl")] | ||
| #[test] | ||
| fn to_locale_string_different_locales_produce_different_output() { | ||
| run_test_actions([TestAction::assert( | ||
| "Temporal.PlainYearMonth.from('2024-03').toLocaleString('en-US') !== \ | ||
| Temporal.PlainYearMonth.from('2024-03').toLocaleString('de-DE')", | ||
| )]); | ||
| } | ||
|
|
||
| #[cfg(feature = "intl")] | ||
| #[test] | ||
| fn to_locale_string_options_affect_output() { | ||
| run_test_actions([ | ||
| TestAction::assert( | ||
| "typeof Temporal.PlainYearMonth.from('2024-03').toLocaleString('en-US', { dateStyle: 'short' }) === 'string'", | ||
| ), | ||
| TestAction::assert( | ||
| "Temporal.PlainYearMonth.from('2024-03').toLocaleString('en-US', { dateStyle: 'short' }).length > 0", | ||
| ), | ||
| ]); | ||
| } | ||
|
|
||
| #[cfg(feature = "intl")] | ||
| #[test] | ||
| fn to_locale_string_ignores_time_zone_for_plain_values() { | ||
| run_test_actions([TestAction::assert( | ||
| "Temporal.PlainYearMonth.from('2024-03').toLocaleString('en-US', { timeZone: 'America/New_York' }) === \ | ||
| Temporal.PlainYearMonth.from('2024-03').toLocaleString('en-US', { timeZone: '+00:00' })", | ||
| )]); | ||
| } | ||
|
|
||
| #[cfg(feature = "intl")] | ||
| #[test] | ||
| fn to_locale_string_default_excludes_reference_day_time_and_zone_name() { | ||
| // Mirrors test262 `default-does-not-include-day-time-and-time-zone-name.js`. | ||
| run_test_actions([TestAction::assert( | ||
| "(() => { \ | ||
| const p = new Temporal.PlainYearMonth(2024, 12, 'iso8601', 26); \ | ||
| const r = p.toLocaleString('en-u-ca-iso8601', { timeZone: 'UTC' }); \ | ||
| return r.includes('2024') \ | ||
| && (r.includes('12') || r.includes('Dec')) \ | ||
| && !r.includes('26') \ | ||
| && !r.includes('00') \ | ||
| && !r.includes('UTC') \ | ||
| && !r.includes('Coordinated Universal Time'); \ | ||
| })()", | ||
| )]); | ||
| } | ||
|
|
||
| #[cfg(feature = "intl")] | ||
| #[test] | ||
| fn to_locale_string_incompatible_calendar_throws() { | ||
| run_test_actions([TestAction::assert_native_error( | ||
| "Temporal.PlainYearMonth.from('2024-03').toLocaleString('en-US', { calendar: 'japanese' })", | ||
| JsNativeErrorKind::Range, | ||
| "Temporal.PlainYearMonth calendar must match Intl.DateTimeFormat calendar.", | ||
| )]); | ||
| } |
Oops, something went wrong.
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.
issue: this should ideally not be inlined from
HandleDateTimeValue.The implementation here should probably stick as close to the specification as possible while also being able to expand to support the other temporal built-ins