Skip to content

feat(Calendar): useCalendarDays and useCalendarNavigation take an optional calendar - #10007

Merged
nynexman4464 merged 1 commit into
mainfrom
nynexman4464/feat/calendar-hooks
Nov 4, 2026
Merged

nynexman4464 merged 1 commit into
mainfrom
nynexman4464/feat/calendar-hooks

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Base is main. #9622, which this builds on, is merged.

This implements spec:AST-111 (approved in #9605) FR20.

User need

Teams build their own month views on the public hooks when Calendar does not fit: a team availability grid, an archive browsed month by month, or a compact month strip beside a list. Since #9622, Calendar shows other calendar systems, but the hooks still lay out Gregorian months only. A team that needs Persian, Hebrew or Ethiopic months must rebuild month starts, lengths, leap months and labels on its own.

Problem and solution fit

  • useCalendarDays takes calendar?: CalendarSystem (default gregory). With a calendar, year and month are the calendar's year and the month's position in that year, as Temporal.PlainDate numbers them (1–13 in a Hebrew leap year). Each day keeps its Gregorian date and iso. dayNumber is the day of the calendar month, and isOutside is relative to the calendar month. dayNames do not change.
  • useCalendarNavigation takes the same option. navigateMonth steps calendar months, and monthYearLabel is written in the calendar with the same helper as Calendar's heading. A new visibleCalendarMonths: {year, month}[] gives each visible month in the calendar's numbers, so it feeds useCalendarDays directly. baseMonth and visibleMonths stay the Gregorian first day of each month.
  • Neither hook reads the InternationalizationProvider calendar, so a caller's numbers keep their meaning when the application adds a provider calendar.
  • Without Temporal, a calendar that needs it falls back to Gregorian months and warns once in development (FR5), through the same helpers as Calendar.
  • One code path: Calendar now lays out its grids through the public useCalendarDays, and the internal month-days hook is removed.

Current specification

Public delta and caller burden

  • UseCalendarDaysOptions.calendar?: CalendarSystem = 'gregory'
  • UseCalendarNavigationOptions.calendar?: CalendarSystem = 'gregory'
  • UseCalendarNavigationReturn.visibleCalendarMonths: {year: number; month: number}[] (in Gregorian numbers when no calendar is set)
  • Without calendar, both hooks give the released output. The option is additive.
  • Caller decisions: pick a calendar, and pass the same one to both hooks. Calendars other than gregory, iso8601, buddhist, roc and japanese need Temporal, as for Calendar.
const nav = useCalendarNavigation({initialValue: '2026-10-30', calendar: 'persian'});
// nav.visibleCalendarMonths[0] is {year: 1405, month: 8}; nav.monthYearLabel is "Aban 1405 AP"
const {weeks} = useCalendarDays({...nav.visibleCalendarMonths[0], calendar: 'persian'});
// weeks[0][5] is {iso: '2026-10-23', dayNumber: 1, isOutside: false, ...}
nav.navigateMonth(1); // Azar 1405

Design and alternatives

  • The hooks take an explicit calendar and never read the provider's calendar, as FR20 decides; weekday names and the month label still use the provider's locale. Reading the provider would change what a caller's year and month mean when an application adds a provider calendar.
  • useCalendarDays keeps its year/month input and reads it in the calendar's numbers. The other option, a Gregorian date range or a Temporal object, would change the hook's shape for every caller.
  • navigateMonth's focus target stays a day offset (offset, default 7), as released. A day offset needs no clamping, and the default stays the same as calendar: 'gregory'. Calendar's Page-key clamping is outside this hook's API.
  • Two small calendar helpers convert between a calendar month and its year and month numbers. buddhist and roc count years from another epoch (2569 and 115 for 2026) and work without Temporal.

Evidence

  • Released-output equality: useCalendarDays without calendar deep-equals a verbatim copy of the released grid algorithm for six months (a six-row month, a 28-day month that starts on weekStartsOn, a leap February, two variable-row months including a six-row one, and a month across a year end), with days, weeks, totalCells and dayNames. calendar: 'gregory' gives the same output.
  • useCalendarNavigation without calendar matches the released months and label in en, th-TH, fa-IR and ca.
  • The existing useCalendarDays.test.ts and useCalendarNavigation.test.ts pass unchanged.
  • Persian Aban 1405: Gregorian dates 2026-10-23 to 2026-11-21, dayNumber 1..30, and Mehr days outside.
  • Hebrew 5784: month 6 is Adar I, month 7 is Adar II, and month 13 (Elul) exists. Navigation steps Adar I → Adar II → month 13.
  • Buddhist 2569 and Minguo 115 read as October 2026.
  • A provider calendar changes neither hook.
  • monthYearLabel matches Calendar's heading for Persian and Hebrew two-month views, Japanese and Buddhist.
  • visibleCalendarMonths round-trips into useCalendarDays in Persian, Hebrew, Ethiopic, Chinese calendar and Minguo, and the second month starts the day after the first ends.
  • Without Temporal, a Persian calendar falls back to Gregorian months and warns once. Buddhist keeps its years with no warning.
  • All existing Calendar tests pass through the folded code path.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • tsc --noEmit (core)
  • vitest run --maxWorkers=2 packages/core/src/Calendar packages/core/src/i18n packages/core/src/utils packages/core/src/docPropLiterals.test.ts: 1315 of 1316 pass. The one failure, hitArea.test.ts "batches every pending control into one frame", fails the same way on the base branch.
  • CLI component tests (packages/cli/api/component), docPropLiterals.test.ts
  • pnpm check:knowledge, pnpm check:changesets, ESLint on the changed files
  • pre-review: 812 authored lines, no findings

Writing rubric results

Record touched: component:Calendar.

  • R1 narration: one found. The first FR11 draft said the hooks "give their released Gregorian output". It now reads "show Gregorian months, exactly as with calendar: 'gregory'".
  • R2 research: none in the record.
  • R3 evidence: the new FR11 verification cell names the test file and cases. It contains no change references.
  • R4 rejected alternatives: none added.
  • R5 change references: none added.
  • R6 open questions: none.

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 4, 2026 11:25pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 4, 2026, 11:44 PM UTC

@nynexman4464

Copy link
Copy Markdown
Contributor Author

/approve-spec c330720

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 4, 2026
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/calendar-systems-core branch from babf230 to 5ec2dc4 Compare November 4, 2026 22:53
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/calendar-hooks branch from c330720 to af09a12 Compare November 4, 2026 22:54
…ional calendar

Both hooks take `calendar?: CalendarSystem`, default `gregory`, and never
read the provider calendar. With a calendar, `useCalendarDays` reads `year`
and `month` in the calendar's numbers and keeps Gregorian dates, and
`useCalendarNavigation` steps and labels calendar months and returns
`visibleCalendarMonths` to feed `useCalendarDays`. Calendar now lays out its
grids through the public hook. Without `calendar`, both hooks give the same
Gregorian output as before.
@nynexman4464
nynexman4464 force-pushed the nynexman4464/feat/calendar-hooks branch from af09a12 to 18715cb Compare November 4, 2026 23:14
@nynexman4464
nynexman4464 changed the base branch from nynexman4464/feat/calendar-systems-core to main November 4, 2026 23:15
@nynexman4464 nynexman4464 reopened this Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 18715cb

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Calendar · Storybook 57.1 kB (+172 B) · 9.3 kB CSS (0) 1,714 (+6) ✗ · ✓ · ✓
DateRangeInput 75.7 kB (+170 B) · 11.2 kB CSS (0) — — · — · —
DateInput 154.4 kB (+157 B) · 15.5 kB CSS (0) — — · — · —
2 more components
Component Size LoC Visual · A11y · RTL
DateTimeInput 176.3 kB (+145 B) · 17.2 kB CSS (0) — — · — · —
PowerSearch 248.7 kB (+87 B) · 22.3 kB CSS (0) — — · — · —
Visual changes: 2 snapshots in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
Calendar · Default (neutral, light) before frame after frame diff frame
Calendar · Default (neutral, dark) before frame after frame diff frame

Package size: @astryxdesign/core 6.48 MB packed (+1.9 kB); no new dependencies.

API changes: core +3 · ~0 · −0

Committed API report behind this build: cli 9 rows, core 5 rows; run pnpm api:report.

3 API changes (advisory)
Package Where Signature Usage
+ core . · Types · interface UseCalendarDaysOptions calendar?: CalendarSystem = 'gregory' import type {UseCalendarDaysOptions} from '@astryxdesign/core'; const x: UseCalendarDaysOptions = {calendar: …}
+ core . · Types · interface UseCalendarNavigationOptions calendar?: CalendarSystem = 'gregory' import type {UseCalendarNavigationOptions} from '@astryxdesign/core'; const x: UseCalendarNavigationOptions = {calendar: …}
+ core . · Types · interface UseCalendarNavigationReturn visibleCalendarMonths: { year: number; month: number }[] import type {UseCalendarNavigationReturn} from '@astryxdesign/core'; const x: UseCalendarNavigationReturn = {visibleCalendarMonths: …}

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: some CI jobs are still running on this head.

useCalendarDays and useCalendarNavigation now take an optional calendar. Without it, both hooks return their released Gregorian output. The new tests cover Persian, Hebrew leap years, Ethiopic, Chinese, Minguo and the other Gregorian-aligned calendars, and the new calendar cases fail without this change. The Calendar spec change (FR11) has an engineering owner's approval at this head.

  • Non-blocking: the doc comment on calendarMonthFromYearMonth (packages/core/src/utils/calendarSystem.ts, lines 251–252) says a month past the end of its year becomes the year's last month. That is true only for calendars that use Temporal, so consider narrowing it.

[Automated review]

Comment on lines +251 to +252
* The calendar month with these year and month numbers. A month past the end
* of its year becomes the last month of that year, as Temporal constrains it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this holds only on the Temporal branch. The Gregorian-aligned branch does not constrain: calendarMonthFromYearMonth('gregory', {year: 2026, month: 13}) returns a start of 2026-13-01 with no length, while Persian month 13 becomes Esfand. Suggested wording: "Temporal constrains a month past the end of its year to that year's last month. Gregorian-aligned calendars do not."

@nynexman4464
nynexman4464 merged commit aa7c501 into main Nov 4, 2026
65 checks passed
@github-actions
github-actions Bot deleted the nynexman4464/feat/calendar-hooks branch November 5, 2026 06:03
vjeux added a commit to vjeux/astryx that referenced this pull request Nov 5, 2026
Only packages/core/api-report.md changes, as pnpm api:report writes it on
main bfc1dcc: useClickableContainer's parameter spelling (meta#8085), the
colorVars and inputWrapperStyles hashes after the dark-mode accent change
(meta#9818), and the array spelling of visibleCalendarMonths (meta#10007).
cixzhang pushed a commit that referenced this pull request Nov 6, 2026
…le (#10056)

chore: regenerate the four core API report rows three merges left stale

Only packages/core/api-report.md changes, as pnpm api:report writes it on
main bfc1dcc: useClickableContainer's parameter spelling (#8085), the
colorVars and inputWrapperStyles hashes after the dark-mode accent change
(#9818), and the array spelling of visibleCalendarMonths (#10007).

This branch was successfully deployed

1 active deployment
Preview — 18715cbf Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant