Polyfill: Avoid TimeClip at edge of DateTimeFormat supported range#3284
Open
Polyfill: Avoid TimeClip at edge of DateTimeFormat supported range#3284
Conversation
In the reference polyfill we have to simulate formatting Plain types by using the existing DateTimeFormat methods to format epoch milliseconds. Since Plain types have a slightly larger range than the exact times that DateTimeFormat could previously format, we need to anticipate when they correspond to an epoch milliseconds value that's out of range. In this case, we calculate a "day adjustment" and apply it to the 'day' part of formatToParts() or formatRangeToParts() to fudge the resulting formatted string back to the day that it should have represented. This is probably not 100% format-accurate. For one thing, it'll lose leading zeroes in the day, if the format calls for them. This workaround is mainly to make sure we can handle the full range of the type, and assumes that the workaround path will rarely be hit in practice.
Collaborator
Author
|
See tc39/test262#4954 for test coverage |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3284 +/- ##
==========================================
- Coverage 97.93% 97.42% -0.51%
==========================================
Files 22 22
Lines 10593 10677 +84
Branches 1829 1840 +11
==========================================
+ Hits 10374 10402 +28
- Misses 201 254 +53
- Partials 18 21 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
(The missing code coverage lines should resolve themselves once we update the tests) |
Contributor
|
I think it's also necessary to adjust the weekday and to take the numbering system into account. For example this test case should print new Temporal.PlainDate(275760, 9, 13).toLocaleString("en-u-nu-thai", {day: "numeric", weekday: "long"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the reference polyfill we have to simulate formatting Plain types by using the existing DateTimeFormat methods to format epoch milliseconds.
Since Plain types have a slightly larger range than the exact times that DateTimeFormat could previously format, we need to anticipate when they correspond to an epoch milliseconds value that's out of range. In this case, we calculate a "day adjustment" and apply it to the 'day' part of formatToParts() or formatRangeToParts() to fudge the resulting formatted string back to the day that it should have represented.
This is probably not 100% format-accurate. For one thing, it'll lose leading zeroes in the day, if the format calls for them. This workaround is mainly to make sure we can handle the full range of the type, and assumes that the workaround path will rarely be hit in practice.