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

Normative: Merge PrepareTemporalFields #2472

Merged
merged 5 commits into from
Mar 8, 2023

Conversation

FrankYFTang
Copy link
Contributor

Avoiding two different versions of PrepareTemporalFields for unneeded reason by adding the 'era' and 'eraYear' check into the ECAM262 version and remove the ECMA402 version.

Close #2465

@codecov
Copy link

codecov bot commented Jan 12, 2023

Codecov Report

Merging #2472 (d8c8bb1) into main (f973e18) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2472      +/-   ##
==========================================
+ Coverage   95.47%   95.50%   +0.02%     
==========================================
  Files          20       20              
  Lines       10929    10931       +2     
  Branches     2034     2035       +1     
==========================================
+ Hits        10435    10440       +5     
+ Misses        432      430       -2     
+ Partials       62       61       -1     
Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 98.28% <ø> (+0.05%) ⬆️
polyfill/lib/calendar.mjs 84.41% <100.00%> (+0.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

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

To be clear, this means that even in an engine without 402, it would be an error to provide only one of era and eraYear, right? (ie, only neither or both is allowed)

Comment on lines 1701 to 1705
1. If _requiredFields_ is not ~partial~, then
1. Let _era_ be ? Get(_result_, *"era"*).
1. Let _eraYear_ be ? Get(_result_, *"eraYear"*).
1. If _era_ is *undefined* and _eraYear_ is not *undefined*, throw a *RangeError* exception.
1. If _era_ is not *undefined* and _eraYear_ is *undefined*, throw a *RangeError* exception.
Copy link
Collaborator

Choose a reason for hiding this comment

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

As per #2465 (comment) we'll remove this part because it is already done in dateFromFields/yearMonthFromFields/monthDayFromFields anyway, after each call to PrepareTemporalFields.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a harm in validating it here as well?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it "leaks" calendar-specific logic outside of Temporal.Calendar methods.

Copy link
Member

Choose a reason for hiding this comment

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

Is there likely to be any calendar that supports one of these two properties but not both?

Copy link
Collaborator

Choose a reason for hiding this comment

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

No. Calendars either use eras or they won't. If they do use eras (which is, BTW, the vast majority of CLDR calendars) then era/eraYear are used as a pair. One of then without the other is not meaningful.

This means that discussions relating to validation and eras are focused on relatively narrow questions:

  • In non-era-using calendars, or in 262 without 402, what should happen if callers provide (in a property bag passed to from, with, etc.) one of era/eraYear without the other? Throw? Ignore?
  • Where exactly should the validation take place that ensures that those two properties are either both present or both undefined?

Copy link
Member

Choose a reason for hiding this comment

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

I think that unknown properties should be ignored, but known ones should be validated as early as possible.

Given that these two properties are really just one property, that contains two items, and should only come as a pair, it seems reasonable to me to validate for them here as well, since they're known property names.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That is validated already, this just removes a duplicate validation. I get what you are saying about validating as early as possible, but I don't think that weighs against having calendar-specific logic live outside of Temporal.Calendar methods.

Copy link
Member

Choose a reason for hiding this comment

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

This AO is called "PrepareTemporalFields" and Calendar is part of Temporal - since this is logic that would apply to any era-using calendar, it doesn't feel calendar-specific to me, it feels calendar-general, which doesn't imo need to be contained to calendar methods.

@ptomato
Copy link
Collaborator

ptomato commented Feb 1, 2023

This achieved consensus at the 2021-01-31 TC39 plenary meeting. @ljharb, I assume your open question was resolved by the question you asked during the presentation about era and eraYear being either completely present or completely absent?

I think before merging this we should have a test262 test to verify it. Something based on the code sample I gave in my slides (https://ptomato.name/talks/tc39-2023-01/#12) would be sufficient, I think; that code sample should work for the ISO calendar regardless of whether the implementation has other calendars or just ISO.

@ljharb
Copy link
Member

ljharb commented Feb 1, 2023

@ptomato yes, as long as ecma262 has zero mention of era/eraYear, and all of it is in ecma402, then I can tolerate it :-) (altho my preference would be for everything to be in 262, and for 402 to only patch methods or AOs as needed to add intl-specific logic).

FrankYFTang and others added 3 commits March 7, 2023 22:55
Avoiding two different version of PrepareTemporalFields
for unneeded reason by adding the era and eraYear check into the
ECAM262 version and remove the ECMA402 version.
@Aditi-1400
Copy link
Collaborator

Tests are in: tc39/test262#3792

@ptomato ptomato force-pushed the mergePrepareTemporalFields branch from e4b2001 to d8c8bb1 Compare March 8, 2023 00:06
@ptomato
Copy link
Collaborator

ptomato commented Mar 8, 2023

Thanks, merging now!

@ptomato ptomato merged commit 32460a7 into tc39:main Mar 8, 2023
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.

Merge two PrepareTemporalFields into one
5 participants