Polyfill: fix Chinese/Dangi calendar at extreme date ranges#3277
Polyfill: fix Chinese/Dangi calendar at extreme date ranges#3277
Conversation
cc6c51f to
803508f
Compare
Use Metonic cycle (19-year) offset to shift extreme ISO years into ICU4C's safe range before calling Intl.DateTimeFormat, then adjust the calendar year back. Fixes tc39#3081.
803508f to
c9d13f2
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3277 +/- ##
==========================================
- Coverage 98.09% 98.09% -0.01%
==========================================
Files 22 22
Lines 10457 10504 +47
Branches 1808 1813 +5
==========================================
+ Hits 10258 10304 +46
- Misses 182 184 +2
+ Partials 17 16 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ptomato
left a comment
There was a problem hiding this comment.
Cool, thanks!
This fix means you can probably also add "chinese" and "dangi" to the list of calendars in test/thorough/calendardaymath.js and remove the comment explaining why they need to be skipped.
I like the solution of shifting the year into range. I had a half-started branch for this issue where I did something similar only instead of shifting the year, I made a fake Metonic cycle going into the past and future. I like your solution better.
One thing from my branch that might be helpful to have here, I added a method to helperChinese:
// https://unicode-org.atlassian.net/browse/ICU-23286
isVulnerableTo70000Bug() {
if (this.vulnerableTo70000Bug === undefined) {
const formatter = this.getFormatter();
try {
Call(IntlDateTimeFormatPrototypeFormatToParts, formatter, [2146851043199999 + 1]);
} catch {
this.vulnerableTo70000Bug = true;
}
this.vulnerableTo70000Bug = false;
}
return this.vulnerableTo70000Bug;
},(And only do the shifting if this flag is true.) This way, if a runtime ships a fix to the bug, we won't override their data.
I've incorporated this helper; thanks! I've also ungated the Chinese and Dangi calendars, so they won't be skipped now. |
Move the standalone chineseMetonicOffset function into helperChinese as a metonicOffset method, using `this` instead of the `helper` parameter. helperDangi inherits it via ObjectAssign spread. Thanks to ptomato for the suggestion.
Attempt to fix #3081 by using the 19-year Metonic cycle to shift extreme ISO years into ICU4C's safe range before calling Intl.DateTimeFormat, then adjusting the calendar year back. This produces approximate but non-throwing results for dates outside ICU4C's supported range, which should be sufficient for the test262 extreme-dates tests that only check that no error is thrown. Happy to adjust the approach if there's a better way to handle this.