fix: upgrade to polyfill 0.5.1 (wip)#92
Draft
KaiVandivier wants to merge 1 commit into
Draft
Conversation
|
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.




This is a big AI attempt to upgrade to
@js-temporal/polyfill, and it required remaking the Nepali calendar since theTemporal.Calendarobject no longer exists. All the tests and type checks pass, and it seems to be at least mostly working when dropped into the UI library/storybook, but I think there are still things to iron out for the Nepali calendar (liketimeZone is undefinederrors)Haven't looked through it thoroughly yet, but it might be useful. Here's the full Claude Code output:
Upgrade:
@js-temporal/polyfill0.4.3 → 0.5.1Validation
tsc --noEmitcleananywarnings inconvert-date.spec.ts/validate-date-string.ts)yarn buildsucceeds (package +.d.ts)Breaking changes in 0.5.1 that drove the work
The 0.5.0 release (June 2024 TC39) cut Temporal's scope at engine-implementer request, with cascading effects here:
Temporal.Calendarclass + subclassingTemporal.CalendarProtocol/CalendarLike: objectstring | <existing Temporal value>Temporal.TimeZoneclass,Temporal.TimeZone.from.calendar,.timeZone(object getters).calendarId,.timeZoneId(strings)getISOFields().withCalendar('iso8601')+ individual getterszdt.toPlainYearMonth()/toPlainMonthDay().toPlainDate()first'era1''ethiopic'(and'ethioaa'for the older era)Temporal.YearOrEraAndEraYear/MonthOrMonthCodetypeseraYeargetterundefined(we fall back toyear)Temporal.ZonedDateTime.from({...})withouttimeZonetimeZoneis requiredtoLocaleString({calendar: X})How Nepali (the custom calendar) was preserved
This was the hard part — 0.5.x has no in-polyfill way to register a user calendar. The Nepali implementation in
src/custom-calendars/nepaliCalendar.tsis now a pair of shadow types that live outside Temporal:NepaliPlainDateandNepaliZonedDateTimemirror theTemporal.PlainDate/ZonedDateTimeAPI surface the library uses (year/month/day/eraYear/daysInMonth/dayOfWeek/dayOfYear/monthsInYear/calendarId, pluswith,add,subtract,equals,since,withCalendar,toIso/toPlainDate,toString,toLocaleString,toPlainYearMonth)._isoToNepali/_nepaliToIsoconversion logic and theNEPALI_CALENDAR_DATAtable are unchanged from 0.4.x.src/custom-calendars/calendar-routing.tsexposes polymorphic helpers —plainDateFrom,zonedDateTimeFrom,withCalendar,zonedDateTimeWithCalendar,comparePlainDates— that branch on'nepali'and return the right type. The rest of the library (hooks, period generation, validators) consumes these instead ofTemporal.PlainDate.from({calendar: ...})or.withCalendar(...).Public-API impact for downstream consumers
Most exports are calendar-agnostic and unchanged. Two surface-level changes affect anyone who imports types directly:
NepaliCalendarclass is gone. It was aTemporal.Calendarsubclass that can't exist in 0.5.x. Replaced byNepaliPlainDate/NepaliZonedDateTimeshadow classes (not currently re-exported fromsrc/index.ts— they're internal). ThecustomCalendarsmap no longer contains acalendar:field; onlylocales+defaultLocale.PickerOptionsWithResolvedCalendar.calendaris nowSupportedCalendar(string) instead ofTemporal.CalendarProtocol. Consumers passing this type need to update.Likely consumer code (
@dhis2/uiCalendar / CalendarInput) shouldn't be affected unless it importsNepaliCalendardirectly. Worth a manual smoke-test against@dhis2/uibefore publishing.Behavioral notes worth flagging
convertFromIso8601now returnseraYear: yearas a fallback when the polyfill omits it (Islamic calendar in particular), preserving the existing contract.useDatePickerre-projectsfirstZdtOfVisibleMonthto the active calendar before passing it intouseNavigation/useCalendarWeekDays. This was implicit in 0.4.x (because.toLocaleString({calendar:X})did silent reprojection) and is now explicit.Temporal.ZonedDateTime.from({calendar: 'ethiopic', year, era: 'ethiopic'})raises if bothyearandera/eraYearare present and inconsistent.useDatePickernow picks one form per calendar.