Polyfill: Update Meiji era start date - #368
Closed
craig-o-curtis wants to merge 2 commits into
Closed
craig-o-curtis wants to merge 2 commits into
craig-o-curtis wants to merge 2 commits into
Conversation
This was based on erroneous data in CLDR. See https://unicode-org.atlassian.net/browse/CLDR-11375 UPSTREAM_COMMIT=977d11e0d0a47896cb43124c57b6364058e017a8
Update internal era data to change hasYearZero to startingYear, so that we can accommodate the starting year of 6. NOTE: (this info below wasn't in the upstream commit) This implements the normative change in tc39/proposal-intl-era-monthcode#102, from tc39/proposal-temporal#3263. In the Japanese calendar, dates up to and including 1872-12-31 now use the "ce" and "bce" eras, as in the gregory calendar, and the Meiji era starts at year 6 on 1873-01-01. For example, Temporal.PlainDate.from('1872-12-31').withCalendar('japanese') was meiji 5 and is now ce 1872. Dates from 1873-01-01 on are unchanged. Still the same after this commit: toLocaleString() formats through Intl.DateTimeFormat, which still shows 1872-12-31 as 5 Meiji. TypeScript port: the Era type requires startingYear, so HelperBase's placeholder anchorEra sets startingYear: 1. The ported comment "we count years prior to 1872 as CE" should say 1873, since all of 1872 is CE; it is kept word for word here. UPSTREAM_COMMIT=993e6322d56971b68e539d007a32c62bf94a4032
craig-o-curtis
force-pushed
the
port-meiji-era-start
branch
from
September 18, 2026 07:51
df03744 to
45f3b94
Compare
Contributor
|
Thanks for proactively porting this, but I'd prefer to keep the commits ported in order — otherwise the rebases become unmanageable. I apologize that it's been taking a while. |
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.
Ports two tc39/proposal-temporal commits, one commit each:
What was wrong
On
main, the Japanese calendar starts the Meiji era on 1868-09-08, and gives every date from then to the end of 1872 the erameiji:The spec, as changed by tc39/proposal-intl-era-monthcode#102, says that dates up to and including 1872-12-31 use the same years and eras as
gregory, and that ISO year 1873, when Japan switched to the Gregorian calendar, is year 6 of Meiji. So all three calls above should givece1870 orce1872.What this changes
hasYearZeroera flag withstartingYear, so that the Meiji era can start at year 6, on 1873-01-01. Dates before that useceorbce, so the three calls above now givece1870,ce1872 andce1870. Input usingera: 'meiji'witheraYear1 to 5 still works and gives the matchingcedate. For example,{ era: 'meiji', eraYear: 5, month: 12, day: 31 }is 1872-12-31,ce1872. Dates from 1873-01-01 on are unchanged: 1873-01-01 is stillmeiji6.Not fixed by this PR
These behave the same on
mainand on this branch:toLocaleString()still shows the ICU era.Temporal.PlainDate.from('1872-12-31').withCalendar('japanese').toLocaleString('en-u-ca-japanese', { era: 'short', year: 'numeric', month: 'numeric', day: 'numeric' })gives12/31/5 Meiji, although.erais nowce. Formatting goes throughIntl.DateTimeFormat, which uses ICU's era data, not the polyfill's.overflow: 'reject'should throw but doesn't (6 files,*/prototype/{add,subtract}/leap-year-japanese.js), a missingeraYearthrowsRangeErrorinstead ofTypeError(6 files,calendarresolvefields-error-ordering-japanese.js), andPlainMonthDay/from/japanese-month-codes.js(1 file, wrong reference year). April 2026 rebase, part 3 #361 fixes all 13 (see Testing).Testing
Node 24.21.0 (ICU 78.3, CLDR 48): jest passes (607 tests), and test262 at the pinned version passes with no new failures or unexpected passes (intl402/Temporal 330 passed, 8 expected failures; built-ins/Temporal 4330 passed).
Our pinned test262 has no Japanese era tests. So I ran the 125
intl402/Temporal/**/*japanese*.jstests by hand: 124 at test262 3c6180f, the commit that tc39/proposal-temporal#3263 pinned, plusPlainDate/from/japanese-pre-meiji.js, which test262 added later:mainThe 5 tests this PR fixes are
{PlainDate,PlainDateTime,PlainYearMonth,ZonedDateTime}/from/era-boundary-japanese.jsandPlainDate/from/japanese-pre-meiji.js. The 13 still failing are the ones listed under "Not fixed by this PR". This PR applies cleanly on top of #361.Differences from upstream (TypeScript)
lib/calendar.tshas separateInputEraandEratypes where upstream has one JSDoc typedef.startingYearis optional inInputEraand required inEra, soHelperBase's placeholderanchorEra(for calendars without eras) setsstartingYear: 1.