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

Ensure reference ISO year/day is always given by the calendar #1331

Merged
merged 1 commit into from
Jan 27, 2021

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Jan 27, 2021

In PlainYearMonth and PlainMonthDay, when constructing via the from()
method, the reference ISO day or year should always be given by the
calendar ("canonicalized") and never by user code. This was already the
case when the argument to from() is a property bag or another Temporal
object, but was not the case when the argument is a string.

This requires, slightly weirdly, calling the intrinsic PMD/PYM constructor
and then calling calendar.monthDayFromFields/yearMonthFromFields on the
result of that, but it is more consistent this way.

The constructor functionality remains the same, where the reference ISO
day or year is used without any change.

Closes: #1316

@codecov
Copy link

codecov bot commented Jan 27, 2021

Codecov Report

Merging #1331 (8599c03) into main (2e5cc51) will increase coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1331      +/-   ##
==========================================
+ Coverage   94.82%   94.94%   +0.12%     
==========================================
  Files          19       19              
  Lines        9681     9682       +1     
  Branches     1525     1519       -6     
==========================================
+ Hits         9180     9193      +13     
+ Misses        491      481      -10     
+ Partials       10        8       -2     
Flag Coverage Δ
test262 54.42% <100.00%> (+0.01%) ⬆️
tests 90.86% <100.00%> (+0.15%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 95.55% <100.00%> (+<0.01%) ⬆️
polyfill/lib/plainyearmonth.mjs 94.60% <0.00%> (+2.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e5cc51...4e88349. Read the comment docs.

Copy link
Collaborator

@cjtenny cjtenny left a comment

Choose a reason for hiding this comment

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

lgtm, maybe one name change for spec clarity - if _canonicalize... is standard for empty/default value, then fine to keep as is

spec/plainmonthday.html Outdated Show resolved Hide resolved
spec/plainyearmonth.html Outdated Show resolved Hide resolved
In PlainYearMonth and PlainMonthDay, when constructing via the from()
method, the reference ISO day or year should always be given by the
calendar ("canonicalized") and never by user code. This was already the
case when the argument to from() is a property bag or another Temporal
object, but was not the case when the argument is a string.

This requires, slightly weirdly, calling the intrinsic PMD/PYM constructor
and then calling calendar.monthDayFromFields/yearMonthFromFields on the
result of _that_, but it is more consistent this way.

The constructor functionality remains the same, where the reference ISO
day or year is used without any change.

Closes: #1316
@ptomato ptomato force-pushed the 1316-canonicalize-reference-year-day branch from 0c4b6cd to 4e88349 Compare January 27, 2021 05:55
@ptomato ptomato merged commit ebd2df4 into main Jan 27, 2021
@ptomato ptomato deleted the 1316-canonicalize-reference-year-day branch January 27, 2021 06:04
Copy link
Collaborator

@justingrant justingrant left a comment

Choose a reason for hiding this comment

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

Looks good. I noted an optimization in comments that could be in a follow-up if needed.

return result;

const PlainMonthDay = GetIntrinsic('%Temporal.PlainMonthDay%');
let result = new PlainMonthDay(month, day, calendar, referenceISOYear);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the vast majority of cases, calendar will be ISO and referenceISOYear will not be included in the string. In that case, is the double-construction needed? Seems like a worthwhile optimization to only construct twice if there's a year in the input.

Also (out of scope for this PR?), is there a case where we'll have a string like 09-04[c=japanese] where the year is omitted? Seems like that format should be disallowed; if the calendar is in the string, then a year should be required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree it's weird, and does add more observable calls to methods of calendar. I'll take a look at this tomorrow.

We do already disallow mm-dd[calendar].
Thanks for taking a look!

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.

from and with must set canonical reference day (for PlainYearMonth) or reference year (for PlainMonthDay)
3 participants