Skip to content

fix: detect PlainDate by calendarId in resolveFirstWeekSpec - #20

Merged
dogmar merged 1 commit into
mainfrom
fix/m2-resolve-first-week
Jun 15, 2026
Merged

fix: detect PlainDate by calendarId in resolveFirstWeekSpec#20
dogmar merged 1 commit into
mainfrom
fix/m2-resolve-first-week

Conversation

@dogmar

@dogmar dogmar commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Audit medium M2.

Problem

resolveFirstWeekSpec detected a Temporal.PlainDate with "calendar" in spec, but modern Temporal — native and @js-temporal/polyfill 0.5+ — exposes calendarId, not calendar (verified: "calendar" in PlainDate.from(...) is false). So the PlainDate branch was dead: every PlainDate spec fell through to the { month, year, day } branch and was rebuilt via T.PlainDate.from({ year, month, day }).

For ISO dates that's correct by accident (same fields). For a non-ISO-calendar PlainDate it's the centuries-off bug: a Buddhist 2026-03-15 reads year: 2569, so reconstruction yields ISO 2569-03-15. Internal callers reach this (e.g. grid.tsx passes a PlainDate to scrollToWeek).

Fix

Detect the PlainDate via "calendarId" in spec, and convert non-ISO calendars to ISO with withCalendar("iso8601") before snapping (the week snap uses dayOfWeek/subtract, which are calendar-independent), keeping the ISO-only pipeline consistent.

Tests

Added: a Buddhist-calendar PlainDate resolves to the correct ISO week start (2026-03-15, calendarId: "iso8601") — RED before the fix (produced 2569-03-12). The existing ISO PlainDate / isoWeek / week / month+year / native-Date cases still pass (they now go through the corrected detection).

vp run ready: lint+typecheck 0/0, all suites green.

🤖 Generated with Claude Code

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>
@dogmar
dogmar merged commit e3c861c into main Jun 15, 2026
6 checks passed
@dogmar
dogmar deleted the fix/m2-resolve-first-week branch June 15, 2026 03:41
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant