Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Integrate Intl.DurationFormat into Temporal #3088

Merged
merged 6 commits into from
Feb 14, 2025
Merged

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Feb 13, 2025

Intl.DurationFormat is stage 4, so we can now incorporate the necessary changes to use it in Temporal.Duration.prototype.toLocaleString and to accept Temporal.Duration as an argument to Intl.DurationFormat.prototype.format and formatToParts. Some operations need to move from ECMA-402 into ECMA-262.

Closes: #452

Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 52.72727% with 26 lines in your changes missing coverage. Please review.

Project coverage is 96.14%. Comparing base (2454970) to head (cf54568).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
polyfill/lib/intl.mjs 50.00% 23 Missing ⚠️
polyfill/lib/duration.mjs 33.33% 2 Missing ⚠️
polyfill/lib/primordials.mjs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3088      +/-   ##
==========================================
- Coverage   96.37%   96.14%   -0.24%     
==========================================
  Files          21       21              
  Lines        9874     9928      +54     
  Branches     1800     1801       +1     
==========================================
+ Hits         9516     9545      +29     
- Misses        311      336      +25     
  Partials       47       47              

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

ToIntegerIfIntegral no longer needs to be defined by Temporal, as it's now
part of ECMA-402. However, when Temporal becomes part of ECMA-262, we do
need to move ToIntegerIfIntegral into ECMA-262. Remove it from
abstractops.html and put it in an <ins> block in mainadditions.html, and
in a <del> block in intl.html.
ToIntegerIfIntegral no longer needs to be defined by Temporal, as it's now
part of ECMA-402. However, when Temporal becomes part of ECMA-262, we do
need to move ToIntegerIfIntegral into ECMA-262. Put it in a <del> block in
intl.html. We can keep the new definition in its current place in the spec
while adjusting its ID.
DurationSign no longer needs to be defined by Temporal, as it's now part
of ECMA-402. However, when Temporal becomes part of ECMA-262, we do need
to move Duration#to ECMA-262. Put it in a <del> block in intl.html.
We can keep the new definition in its current place in the spec while
adjusting its ID.

Once Temporal.Duration objects are introduced, there is no longer any need
for Duration Records. So, make the ECMA-402 DurationSign accept a
Temporal.Duration object (as it already did in Temporal), delete the
ToDurationRecord operation and the Duration Record definition, and change
several other operations from ECMA-402 to use Temporal.Duration objects
instead of Duration Records.

Temporarily, since these operations aren't yet in ecma402-biblio pending
tc39/ecma402#943, add a JSON bibliography file so
the references aren't dangling.
@ptomato ptomato force-pushed the 452-integrate-durationformat branch from 0b11e62 to 2736777 Compare February 13, 2025 19:21
Copy link
Contributor

@anba anba left a comment

Choose a reason for hiding this comment

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

Thanks!

spec/intl.html Outdated Show resolved Hide resolved
Copy link
Member

@ryzokuken ryzokuken left a comment

Choose a reason for hiding this comment

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

LGTM except for the comment already made by anba.

This operation had a placeholder note until the Intl.DurationFormat
proposal would reach stage 4. Now that the proposal is stage 4, we can
replace the placeholder note with the real implementation.

Closes: #452
The previous implementation in the reference code was non-conformant on
hosts with Intl.DurationFormat implemented without Temporal.Duration
integration. On those hosts, the argument to format() would be treated as
a Duration-like property bag and its properties would be observably read,
even if it was a Temporal.Duration. The correct behaviour would be to get
the information from the Temporal.Duration object's internal slots.
An additional modification to ECMA-402 that Temporal makes, is for
DurationFormat.p.format and formatToParts to accept a Temporal.Duration
object as input. This monkeypatches those methods to conform to that
requirement.
@ptomato ptomato force-pushed the 452-integrate-durationformat branch from 2736777 to cf54568 Compare February 14, 2025 17:05
@ptomato ptomato merged commit 69f46d5 into main Feb 14, 2025
10 checks passed
@ptomato ptomato deleted the 452-integrate-durationformat branch February 14, 2025 17:11
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate with Intl.DurationFormat
3 participants