Skip to content
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

Editorial: Fixes for remaining issues from Anba #2995

Merged
merged 6 commits into from
Oct 8, 2024
Merged

Editorial: Fixes for remaining issues from Anba #2995

merged 6 commits into from
Oct 8, 2024

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Oct 4, 2024

Fixes #2962 and #2795. Includes a start on #2948 as well.

Test262 tests are in tc39/test262#4248.

Best reviewed commit by commit. I'd especially appreciate extra eyes on the spec text in "Throw TypeError if no overlap between options and Temporal object" and "Avoid formatting irrelevant parts of dateStyle/timeStyle for Temporal types", as I'm less confident that I know what I'm doing in CreateDateTimeFormat.

spec/intl.html Outdated
@@ -701,17 +701,17 @@ <h1>
1. Let _bestFormat_ be DateTimeStyleFormat(_dateStyle_, _timeStyle_, _styles_).
1. <ins>If _dateStyle_ is not *undefined*, then</ins>
1. <ins>Set _dateTimeFormat_.[[TemporalPlainDateFormat]] to _bestFormat_.</ins>
1. <ins>Set _dateTimeFormat_.[[TemporalPlainYearMonthFormat]] to _bestFormat_.</ins>
1. <ins>Set _dateTimeFormat_.[[TemporalPlainMonthDayFormat]] to _bestFormat_.</ins>
1. <ins>Set _dateTimeFormat_.[[TemporalPlainYearMonthFormat]] to GetDateTimeFormat(_styles_, _formatMatcher_, _bestFormat_, ~year-month~, ~year-month~, ~relevant~).</ins>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

styles is a DateTime Styles Record, but GetDateTimeFormat requires a List of DateTime Format Records.

For context, these are the relevant CLDR patterns: https://github.com/unicode-org/cldr/blob/8fdb9a1ba925ea7dee6669fb11f2bf3a9077d34c/common/main/en.xml#L2573-L2628

The <datetimeSkeleton> element is relatively new, earlier CLDR versions only had <pattern>.

So implementation-wise it's maybe possible to map the pattern to a skeleton, remove the unwanted parts of the skeleton and then find a new pattern which matches the modified skeleton. (If ICU doesn't provide an API to get the skeleton, the skeleton needs to be retrieved from the pattern. There are some cases where computing a skeleton from a pattern gives slightly worse results than directly using a skeleton, but I don't know if this matters here.)

The spec could maybe then do something like:

  • Determine the base format using DateTimeStyleFormat(dateStyle, timeStyle, styles).
  • Extract the relevant parts from the returned DateTime Format Record into a new options Record.
  • Call GetDateTimeFormat with that new options Record.

I don't know how good the results will be when using this approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. For the moment, I've updated this PR with a prose description of what should happen. I'll see if that can be improved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anba I've updated the PR again with a better description of this. It is similar to what you suggested, except that I don't think we really need to call GetDateTimeFormat since we know whether relevant options are present or not, and we don't need defaults. Instead we can just pass the options directly to the format matcher. Please let me know if this works for you.

spec/intl.html Outdated Show resolved Hide resolved
@ptomato ptomato force-pushed the editorial branch 2 times, most recently from 3410769 to 2bd89f8 Compare October 4, 2024 18:02
@ptomato ptomato mentioned this pull request Oct 4, 2024
27 tasks
@anba
Copy link
Contributor

anba commented Oct 7, 2024

The ParseDateTimeUTCOffset calls in the following functions/operations should now be infallible:

  • Temporal.ZonedDateTime.prototype.with
  • ToTemporalZonedDateTime
  • GetTemporalRelativeToOption

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 96.90722% with 3 lines in your changes missing coverage. Please review.

Project coverage is 95.88%. Comparing base (cb2e0ff) to head (c57aa66).

Files with missing lines Patch % Lines
polyfill/lib/intl.mjs 95.52% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2995      +/-   ##
==========================================
- Coverage   95.88%   95.88%   -0.01%     
==========================================
  Files          21       21              
  Lines        9605     9674      +69     
  Branches     1793     1836      +43     
==========================================
+ Hits         9210     9276      +66     
- Misses        342      345       +3     
  Partials       53       53              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ptomato ptomato force-pushed the editorial branch 3 times, most recently from 78f4034 to e5dccd8 Compare October 8, 2024 03:31
…sets

This did not actually lead to any buggy behaviour, as far as I could tell.
But it should match the spec text, which parses
UTCOffset[~SubMinutePrecision] here.
This is a follow-up request from Anba, to the normative change in #2925.
It moves syntactic validation of month codes and offset strings into
PrepareCalendarFields. This allows implementations to store month codes
and offset strings as integers in their equivalents of Calendar Fields
Records, instead of allocated strings.

Closes: #2962
It is valid to format e.g. a PlainDate with only { era }, or a PlainTime
with only { fractionalSecondDigits }, as those things are part of the data
model.

See: #2795
Somewhere along the line the spec text got out of sync with the consensus,
probably in one of the rebases on newer ECMA-402. When attempting to
format a Temporal object, if the DateTimeFormat has options that do not
overlap with the data model of the Temporal object, toLocaleString() and
format() are supposed to throw a TypeError.

Previously, this worked correctly with dateStyle and timeStyle, but not
with other options. We would treat the options as if the DateTimeFormat
had been created with only default options, which was incorrect.

Closes: #2795
… types

timeStyle: 'long' and timeStyle: 'full' include the time zone name for
legacy Date formatting. However, PlainTime and PlainDateTime don't include
a time zone in their data model, so they shouldn't format a time zone name
when using timeStyle. Similarly, PlainYearMonth and PlainMonthDay
shouldn't format a day or year respectively when using dateStyle. This was
already the consensus but somewhere along the line the spec text got out
of sync, probably in a rebase on latest ECMA-402.

In the polyfill, we already handled dateStyle for PlainYearMonth and
PlainMonthDay. Try to hack around this the same way for timeStyle.

Closes: #2795
Copy link
Collaborator

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Ms2ger Ms2ger merged commit 180a354 into main Oct 8, 2024
10 checks passed
@Ms2ger Ms2ger deleted the editorial branch October 8, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PrepareCalendarFields: Replace TO-PRIMITIVE-AND-REQUIRE-STRING conversion
3 participants