fix: detect PlainDate by calendarId in resolveFirstWeekSpec - #20
Merged
Conversation
The PlainDate branch tested `"calendar" in spec`, but modern Temporal
(native + @js-temporal/polyfill 0.5+) exposes `calendarId`, not
`calendar`. So a PlainDate spec always fell through to the
`{month, year, day}` branch — correct by accident for ISO dates, but a
non-ISO-calendar PlainDate had its calendar fields (e.g. Buddhist year
2569) reinterpreted as ISO, landing ~543 years off.
Detect via `calendarId` and convert non-ISO calendars to ISO with
`withCalendar("iso8601")` before snapping (the snap is
calendar-independent), keeping the ISO-only pipeline consistent.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
🎉 This PR is included in version 2.0.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Audit medium M2.
Problem
resolveFirstWeekSpecdetected aTemporal.PlainDatewith"calendar" in spec, but modern Temporal — native and@js-temporal/polyfill0.5+ — exposescalendarId, notcalendar(verified:"calendar" in PlainDate.from(...)isfalse). So thePlainDatebranch was dead: everyPlainDatespec fell through to the{ month, year, day }branch and was rebuilt viaT.PlainDate.from({ year, month, day }).For ISO dates that's correct by accident (same fields). For a non-ISO-calendar
PlainDateit's the centuries-off bug: a Buddhist2026-03-15readsyear: 2569, so reconstruction yields ISO2569-03-15. Internal callers reach this (e.g.grid.tsxpasses aPlainDatetoscrollToWeek).Fix
Detect the
PlainDatevia"calendarId" in spec, and convert non-ISO calendars to ISO withwithCalendar("iso8601")before snapping (the week snap usesdayOfWeek/subtract, which are calendar-independent), keeping the ISO-only pipeline consistent.Tests
Added: a Buddhist-calendar
PlainDateresolves to the correct ISO week start (2026-03-15,calendarId: "iso8601") — RED before the fix (produced2569-03-12). The existing ISOPlainDate/isoWeek/week/month+year/ native-Datecases still pass (they now go through the corrected detection).vp run ready: lint+typecheck 0/0, all suites green.🤖 Generated with Claude Code