-
Notifications
You must be signed in to change notification settings - Fork 172
Polyfill fix to format plain Temporal objects in UTC #3257
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3257 +/- ##
=======================================
Coverage 97.91% 97.91%
=======================================
Files 22 22
Lines 10367 10373 +6
Branches 1805 1807 +2
=======================================
+ Hits 10151 10157 +6
Misses 197 197
Partials 19 19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
without regard to DST. This implements normative change of PR tc39#3246 in the polyfill.
9d7c2dd to
c0abd32
Compare
…ones. These are basic tests for proposal-temporal's normative change PR tc39/proposal-temporal#3246 and polyfill fix PR tc39/proposal-temporal#3257 More tests will be added here to include tests of .toLocaleString for PlainTime, PlainDate, PlainYearMonth, PlainMonthDay, and tests for formatToParts, formatRange, and formatRangeToParts.
|
Some basic tests are in this test262 draft PR: tc39/test262#4878 |
…ones. These are tests for proposal-temporal's normative change PR tc39/proposal-temporal#3246 and polyfill fix PR tc39/proposal-temporal#3257
ptomato
left a comment
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.
Thanks!
I will probably end up closing this PR and pulling the commit into #3246 when landing it, but I'll figure that out tomorrow.
| function getSlotLazy(obj, slot, isPlain) { | ||
| let val = GetSlot(obj, slot); | ||
| if (typeof val === 'function') { | ||
| val = new IntlDateTimeFormat(GetSlot(obj, LOCALE), val(GetSlot(obj, OPTIONS))); | ||
| const baseOptions = val(GetSlot(obj, OPTIONS)); | ||
| const options = ObjectAssign({}, baseOptions); | ||
| const amendedOptions = val(options); | ||
| if (isPlain) { | ||
| amendedOptions.timeZone = 'UTC'; | ||
| } | ||
| val = new IntlDateTimeFormat(GetSlot(obj, LOCALE), amendedOptions); |
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.
This works, but can be optimized further: I think we can set options.timeZone = 'UTC' in each of the amend functions, rather than here, because when we read e.g. the DATE slot, it will always be with isPlain = true.
…ones. These are tests for proposal-temporal's normative change PR tc39/proposal-temporal#3246 and polyfill fix PR tc39/proposal-temporal#3257
|
Rebased, pushed a commit to address my own comment, and merged into #3246. Thanks! |
without regard to DST.
This implements normative change of PR #3246 in the polyfill.
Related to issue #3212
This adds a new (boolean) argument
isPlaintogetSlotLazy, which, whenisPlainis set totruecopies the options object of the cachedIntl.DateTimeFormatobject and amends the copied options to havetimeZone = 'UTC'.Then from
extractOverrideswe useGetUTCEpochNanosecondsto calculate the nanoseconds of the plain temporal objects, and get a formatter for these usinggetSlotLazywith theisPlainargument set totrue. Thus the formatter for the plain objects can be aware that the nanoseconds calculated for these objects are UTC based, independent of the actual timezone it was created in.This makes the plain* objects be UTC based, implementing the changes in #3246 as closely as possible.