Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(lab): Schedule writes dates in the provider's calendar (#9994)

nynexman44646e2e2429387b
diff --git a/.changeset/calendar-schedule.md b/.changeset/calendar-schedule.md
new file mode 100644
index 0000000000..58297e1b8f
--- /dev/null
+++ b/.changeset/calendar-schedule.md
@@ -0,0 +1,9 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] Internal: the undocumented `@astryxdesign/core/internal/calendar-system` entry gives Lab's Schedule the calendar that Core's date components resolve, and the helpers that name its months, days, and date ranges as `Calendar` does. Internal entries are outside the public API and its compatibility promise.
+
+Lab's Schedule follows that calendar. Without a provider calendar, the accessible label of a timed event that spans days now writes its dates in the Gregorian calendar; before, the dates followed the locale's default calendar, such as the Persian calendar under `fa-IR`. A locale never selects the calendar.
+
+@nynexman4464
diff --git a/packages/core/package.json b/packages/core/package.json
index e25b0270e7..5acf9891a2 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -843,6 +843,11 @@
"source": "./src/internal/spinner-rotor.ts",
"types": "./dist/internal/spinner-rotor.d.ts",
"default": "./dist/internal/spinner-rotor.js"
+ },
+ "./internal/calendar-system": {
+ "source": "./src/internal/calendar-system.ts",
+ "types": "./dist/internal/calendar-system.d.ts",
+ "default": "./dist/internal/calendar-system.js"
}
},
"files": [
diff --git a/packages/core/src/i18n/InternationalizationProvider.doc.mjs b/packages/core/src/i18n/InternationalizationProvider.doc.mjs
index 0c90ff4239..bf7dea2f6a 100644
--- a/packages/core/src/i18n/InternationalizationProvider.doc.mjs
+++ b/packages/core/src/i18n/InternationalizationProvider.doc.mjs
@@ -53,7 +53,7 @@ export const docs = {
{
guidance: true,
description:
- 'Set `calendar` to show `Calendar` in another calendar system and write Timestamp and PowerSearch dates in it; `DateInput`, `DateRangeInput`, and `DateTimeInput` show Gregorian dates. A locale never selects the calendar: `fa-IR` shows Gregorian dates until you set `calendar="persian"`, and a `-u-ca-` keyword in `locale`, as in `th-TH-u-ca-buddhist`, keeps Gregorian dates too. Date values stay Gregorian ISO strings.',
+ 'Set `calendar` to show `Calendar` in another calendar system and write Timestamp, PowerSearch, and Schedule dates in it; `DateInput`, `DateRangeInput`, and `DateTimeInput` show Gregorian dates. A locale never selects the calendar: `fa-IR` shows Gregorian dates until you set `calendar="persian"`, and a `-u-ca-` keyword in `locale`, as in `th-TH-u-ca-buddhist`, keeps Gregorian dates too. Date values stay Gregorian ISO strings.',
},
{
guidance: false,
@@ -96,7 +96,7 @@ export const docs = {
type: "'gregory' | 'iso8601' | 'buddhist' | 'roc' | 'japanese' | 'persian' | 'indian' | 'hebrew' | 'chinese' | 'dangi' | 'coptic' | 'ethiopic' | 'ethioaa' | 'islamic-civil' | 'islamic-tbla' | 'islamic-umalqura'",
required: false,
description:
- "Calendar system of the subtree, such as 'persian', 'hebrew', or 'buddhist'. `Calendar` shows it, and Timestamp and PowerSearch write their dates in it. `DateInput`, `DateRangeInput`, and `DateTimeInput` show Gregorian dates. When omitted, the calendar is Gregorian: a locale never selects it, neither by its default calendar nor by a `-u-ca-` keyword. A component's own `calendar` prop takes precedence. Values stay Gregorian ISO dates. Calendars other than gregory, iso8601, buddhist, roc, and japanese need `Temporal`; the context keeps the requested calendar, and where the runtime lacks `Temporal`, these components show Gregorian dates and warn in development. Load a polyfill such as `temporal-polyfill/full/global` on the server and in the browser.",
+ "Calendar system of the subtree, such as 'persian', 'hebrew', or 'buddhist'. `Calendar` shows it, and Timestamp, PowerSearch, and Lab's Schedule write their dates in it. `DateInput`, `DateRangeInput`, and `DateTimeInput` show Gregorian dates. When omitted, the calendar is Gregorian: a locale never selects it, neither by its default calendar nor by a `-u-ca-` keyword. A component's own `calendar` prop takes precedence. Values stay Gregorian ISO dates. Calendars other than gregory, iso8601, buddhist, roc, and japanese need `Temporal`; the context keeps the requested calendar, and where the runtime lacks `Temporal`, these components show Gregorian dates and warn in development. Load a polyfill such as `temporal-polyfill/full/global` on the server and in the browser.",
},
{
name: 'children',
@@ -217,6 +217,6 @@ export const docsDense = {
overrides:
'sparse per-locale key overrides applied on top of shipped defaults',
calendar:
- 'calendar system for Calendar, Timestamp, and PowerSearch dates; date inputs stay Gregorian (default: gregory; a -u-ca- keyword in locale does not select it); values stay Gregorian ISO; non-Gregorian-aligned calendars need Temporal',
+ 'calendar system for Calendar, Timestamp, PowerSearch, and Schedule dates; date inputs stay Gregorian (default: gregory; a -u-ca- keyword in locale does not select it); values stay Gregorian ISO; non-Gregorian-aligned calendars need Temporal',
},
};
diff --git a/packages/core/src/i18n/InternationalizationProvider.tsx b/packages/core/src/i18n/InternationalizationProvider.tsx
index da10d0407e..543cca75eb 100644
--- a/packages/core/src/i18n/InternationalizationProvider.tsx
+++ b/packages/core/src/i18n/InternationalizationProvider.tsx
@@ -106,14 +106,15 @@ export interface InternationalizationProviderProps {
dir?: 'ltr' | 'rtl';
/**
* The calendar system of this subtree, such as `'persian'` or `'hebrew'`.
- * `Calendar` shows it, and Timestamp and PowerSearch write their dates in it.
- * The date inputs show Gregorian dates. Values stay Gregorian ISO dates. When
- * omitted, the calendar is Gregorian: a locale never selects it, neither by
- * its default calendar nor by a `-u-ca-` keyword. A component's own
- * `calendar` prop takes precedence. Calendars other than `gregory`,
- * `iso8601`, `buddhist`, `roc`, and `japanese` need `Temporal`. The context
- * keeps the requested calendar; where `Temporal` is missing, these components
- * show Gregorian dates and warn once in development.
+ * `Calendar` shows it, and Timestamp, PowerSearch, and Lab's Schedule write
+ * their dates in it. The date inputs show Gregorian dates. Values stay
+ * Gregorian ISO dates. When omitted, the calendar is Gregorian: a locale
+ * never selects it, neither by its default calendar nor by a `-u-ca-`
+ * keyword. A component's own `calendar` prop takes precedence. Calendars
+ * other than `gregory`, `iso8601`, `buddhist`, `roc`, and `japanese` need
+ * `Temporal`. The context keeps the requested calendar; where `Temporal` is
+ * missing, these components show Gregorian dates and warn once in
+ * development.
*
* @example
* ```
diff --git a/packages/core/src/internal/calendar-system.test.ts b/packages/core/src/internal/calendar-system.test.ts
new file mode 100644
index 0000000000..0729bd2e35
--- /dev/null
+++ b/packages/core/src/internal/calendar-system.test.ts
@@ -0,0 +1,40 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+/**
+ * @file calendar-system.test.ts
+ * @input The internal `internal/calendar-system` entry and the i18n module
+ * @output Proof that the entry re-exports Core's own calendar resolution, by
+ * name, and that the public i18n barrel does not export it
+ * @position Unit tests of packages/core/src/internal/calendar-system.ts
+ */
+import {describe, expect, it} from 'vitest';
+
+describe('internal/calendar-system', () => {
+ it('re-exports the hook and the helpers that Core date components use, and nothing else', async () => {
+ const entry: Record<string, unknown> = await import('./calendar-system');
+ const hook = await import('../i18n/useCalendarSystem');
+ const helpers = await import('../utils/calendarSystem');
+ expect(entry.useCalendarSystem).toBe(hook.useCalendarSystem);
+ expect(entry.calendarMonthLabelDay).toBe(helpers.calendarMonthLabelDay);
+ expect(entry.calendarMonthOf).toBe(helpers.calendarMonthOf);
+ expect(entry.formatCalendarDate).toBe(helpers.formatCalendarDate);
+ expect(entry.formatCalendarDateToParts).toBe(
+ helpers.formatCalendarDateToParts,
+ );
+ expect(entry.formatCalendarInstantRange).toBe(
+ helpers.formatCalendarInstantRange,
+ );
+ expect(Object.keys(entry).sort()).toEqual([
+ 'calendarMonthLabelDay',
+ 'calendarMonthOf',
+ 'formatCalendarDate',
+ 'formatCalendarDateToParts',
+ 'formatCalendarInstantRange',
+ 'useCalendarSystem',
+ ]);
+ });
+
+ it('the public i18n barrel does not export the hook', async () => {
+ const pub: Record<string, unknown> = await import('../i18n');
+ expect(pub).not.toHaveProperty('useCalendarSystem');
+ });
+});
diff --git a/packages/core/src/internal/calendar-system.ts b/packages/core/src/internal/calendar-system.ts
new file mode 100644
index 0000000000..d30e4483f6
--- /dev/null
+++ b/packages/core/src/internal/calendar-system.ts
@@ -0,0 +1,26 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file calendar-system.ts
+ * @input The i18n calendar resolution
+ * @output `@astryxdesign/core/internal/calendar-system`: the hook that
+ * resolves the calendar a date component shows, and the helpers that name
+ * its months and days as Core's Calendar does, for Lab components
+ * @position An internal entry reserved for Astryx's own packages:
+ * undocumented, outside the public API and its compatibility promise,
+ * versioned in lockstep with Core, and allowed only in Core and Lab by the
+ * `@astryx/no-core-internal-import` lint rule. Named re-exports only.
+ *
+ * SYNC: When modified, update calendar-system.test.ts and
+ * scripts/sync-exports.js.
+ */
+
+export {useCalendarSystem} from '../i18n/useCalendarSystem';
+export {
+ calendarMonthLabelDay,
+ calendarMonthOf,
+ formatCalendarDate,
+ formatCalendarDateToParts,
+ formatCalendarInstantRange,
+} from '../utils/calendarSystem';
+export type {CalendarSystem} from '../utils/calendarSystem';
diff --git a/packages/core/src/utils/calendarSystem.test.ts b/packages/core/src/utils/calendarSystem.test.ts
index 3b91b88b05..1f0a6b4c43 100644
--- a/packages/core/src/utils/calendarSystem.test.ts
+++ b/packages/core/src/utils/calendarSystem.test.ts
@@ -15,6 +15,7 @@ import {
calendarShiftYears,
formatCalendarDate,
formatCalendarInstant,
+ formatCalendarInstantRange,
formatCalendarMonthLabel,
isCalendarSystemAvailable,
isGregorianAligned,
@@ -314,13 +315,30 @@ describe('labels where Intl and Temporal disagree', () => {
);
expect(value).toMatch(/^First Month 1, 2027\(ding-wei\) at 12:00\sPM$/);
});
+
+ it('writes each end of a range in full', () => {
+ const value = withChineseTemporalAheadOfIntl(() =>
+ formatCalendarInstantRange(
+ 'chinese',
+ new Date('2027-02-01T12:00:00Z'),
+ noon,
+ longDate,
+ 'en',
+ 'UTC',
+ ),
+ );
+ expect(value).toMatch(
+ /^Twelfth Month 26, 2026\(bing-wu\)\s–\sFirst Month 1, 2027\(ding-wei\)$/,
+ );
+ });
});
describe('iso8601 labels', () => {
+ const start = new Date('2027-02-01T12:00:00Z');
const end = new Date('2027-02-06T12:00:00Z');
const longDate = {year: 'numeric', month: 'long', day: 'numeric'} as const;
- it('writes dates and instants as gregory does', () => {
+ it('writes dates, instants, and ranges as gregory does', () => {
const day = iso('2027-02-06');
expect(formatSharedDate(day, 'date', 'en', 'iso8601')).toBe(
formatSharedDate(day, 'date', 'en'),
@@ -329,6 +347,9 @@ describe('iso8601 labels', () => {
expect(formatCalendarInstant('iso8601', end, dateTime, 'en', 'UTC')).toBe(
formatCalendarInstant('gregory', end, dateTime, 'en', 'UTC'),
);
+ expect(
+ formatCalendarInstantRange('iso8601', start, end, longDate, 'en', 'UTC'),
+ ).toMatch(/^February 1\s–\s6, 2027$/);
});
});
diff --git a/packages/core/src/utils/calendarSystem.ts b/packages/core/src/utils/calendarSystem.ts
index a688f867a5..4ef39b86ed 100644
--- a/packages/core/src/utils/calendarSystem.ts
+++ b/packages/core/src/utils/calendarSystem.ts
@@ -329,11 +329,18 @@ export function isInCalendarMonth(
return plainDateIsInRange(pd, [month.start, month.end]);
}
+/**
+ * The day that names a calendar month: its middle day. In the Japanese
+ * calendar an era can start inside a month, and most days of that month then
+ * belong to the era of its middle day.
+ */
+export function calendarMonthLabelDay(month: CalendarMonth): PlainDate {
+ return plainDateAddDays(month.start, Math.floor(month.length / 2));
+}
+
/**
* The stand-alone month and year label of a calendar month, such as
- * "Aban 1405 AP". It formats a day in the middle of the month: in the
- * Japanese calendar an era can start inside a month, and most days of that
- * month then belong to the era of its middle day.
+ * "Aban 1405 AP", named by `calendarMonthLabelDay`.
*/
export function formatCalendarMonthLabel(
calendar: CalendarSystem,
@@ -341,7 +348,7 @@ export function formatCalendarMonthLabel(
locale: Locale,
): string {
return plainDateFormatStandaloneMonthYear(
- plainDateAddDays(month.start, Math.floor(month.length / 2)),
+ calendarMonthLabelDay(month),
locale,
labelCalendar(calendar),
);
@@ -503,6 +510,39 @@ export function formatCalendarInstant(
return instantLabel(calendar, instant, options, locale, timeZone).text;
}
+/**
+ * Formats the range between two instants. Intl writes the fields that both
+ * ends share once. Where Intl names another month or day than Temporal at
+ * either end, the range writes each end in full.
+ */
+export function formatCalendarInstantRange(
+ calendar: CalendarSystem,
+ start: Date,
+ end: Date,
+ options: Intl.DateTimeFormatOptions,
+ locale: Locale,
+ timeZone?: string,
+): string {
+ const ends = [start, end].map(instant =>
+ instantLabel(calendar, instant, options, locale, timeZone),
+ );
+ const {format} = ends[0];
+ if (ends.every(({isIntl}) => isIntl)) {
+ return format.formatRange(start, end);
+ }
+ // Intl writes a range of different years as two full dates around its
+ // separator, which gives the separator to put between the two full ends.
+ const far = new Date(start.getTime() + 400 * 86_400_000);
+ const both = format.formatRange(start, far);
+ const [from, to] = [format.format(start), format.format(far)];
+ const separator =
+ both.startsWith(from) && both.endsWith(to)
+ ? both.slice(from.length, both.length - to.length)
+ : ' – ';
+ const [first, last] = ends.map(({text}) => text);
+ return first === last ? first : `${first}${separator}${last}`;
+}
+
function instantLabel(
calendar: CalendarSystem,
instant: Date,
diff --git a/packages/lab/package.json b/packages/lab/package.json
index b9f7f571fd..7b6b0561af 100644
--- a/packages/lab/package.json
+++ b/packages/lab/package.json
@@ -85,6 +85,7 @@
"@types/d3-array": "^3.2.2",
"@types/d3-scale": "^4.0.9",
"@types/d3-shape": "^3.1.8",
- "emojibase-data": "17.0.0"
+ "emojibase-data": "17.0.0",
+ "temporal-polyfill": "^1.0.6"
}
}
diff --git a/packages/lab/src/Schedule/DayView.tsx b/packages/lab/src/Schedule/DayView.tsx
index 889c71587a..62502f817f 100644
--- a/packages/lab/src/Schedule/DayView.tsx
+++ b/packages/lab/src/Schedule/DayView.tsx
@@ -16,7 +16,7 @@ import {
} from '@astryxdesign/core/utils';
import {enumerateDates, getScheduleRangeFromDates} from './dateMath';
import {useScheduleContext} from './context';
-import {ScheduleMonthTitle, ScheduleFrame} from './shared';
+import {ScheduleMonthTitle, ScheduleFrame, useScheduleCalendar} from './shared';
import {TimeGridView} from './TimeGridView';
import {scheduleRangeToZonedDateTimeRange} from './zonedDateTime';
import type {
@@ -36,15 +36,16 @@ function ScheduleDayView({
const {minHour = 0, maxHour = 24, hourHeight = 100, renderPopover} = options;
const rangeDate = date.toPlainDate();
const days = enumerateDates(range.startDate, range.endDate);
+ const calendar = useScheduleCalendar();
const titleLabel = plainDateFormat(
rangeDate,
- DATE_FORMAT_WITH_WEEKDAY,
+ {...DATE_FORMAT_WITH_WEEKDAY, calendar},
locale,
);
return (
<ScheduleFrame
- title={<ScheduleMonthTitle date={rangeDate} timezoneID={timezoneID} />}
+ title={<ScheduleMonthTitle date={rangeDate} />}
titleLabel={titleLabel}
isLoading={isLoading}>
<TimeGridView
diff --git a/packages/lab/src/Schedule/ListView.tsx b/packages/lab/src/Schedule/ListView.tsx
index 1cce3a9ba0..f080f0b634 100644
--- a/packages/lab/src/Schedule/ListView.tsx
+++ b/packages/lab/src/Schedule/ListView.tsx
@@ -35,6 +35,7 @@ import {
ScheduleFrame,
ScheduleRangeMonthTitle,
styles,
+ useScheduleCalendar,
} from './shared';
import {useCurrentTime} from './useCurrentTime';
import {scheduleRangeToZonedDateTimeRange} from './zonedDateTime';
@@ -54,6 +55,7 @@ function ScheduleListView(
) {
const {events, timezoneID, locale, range, isLoading, headingLevel} =
useScheduleContext();
+ const calendar = useScheduleCalendar();
const days = enumerateDates(range.startDate, range.endDate);
const currentTime = useCurrentTime();
const currentPlainDate = plainDateFromInstant(currentTime, timezoneID);
@@ -61,8 +63,8 @@ function ScheduleListView(
const titleLabel = formatWeekTitle(
range.startDate,
endDate,
- timezoneID,
locale,
+ calendar,
);
const visibleDays = days
.map(day => {
@@ -82,13 +84,7 @@ function ScheduleListView(
return (
<ScheduleFrame
- title={
- <ScheduleRangeMonthTitle
- start={range.startDate}
- end={endDate}
- timezoneID={timezoneID}
- />
- }
+ title={<ScheduleRangeMonthTitle start={range.startDate} end={endDate} />}
titleLabel={titleLabel}
isLoading={isLoading}>
<div {...stylex.props(styles.list)}>
@@ -102,7 +98,6 @@ function ScheduleListView(
<ListDayHeading
day={day}
isCurrentDay={isCurrentDay}
- timezoneID={timezoneID}
headingLevel={headingLevel}
/>
<div {...stylex.props(styles.listEvents)}>
@@ -123,21 +118,20 @@ function ScheduleListView(
function ListDayHeading({
day,
isCurrentDay,
- timezoneID,
headingLevel,
}: {
day: PlainDate;
isCurrentDay: boolean;
- timezoneID: string;
headingLevel: 2 | 3 | 4 | 5 | 6;
}) {
const {locale} = useScheduleContext();
+ const calendar = useScheduleCalendar();
return (
<Heading
level={headingLevel}
color="secondary"
display="block"
- aria-label={formatFullDate(day, timezoneID, locale)}
+ aria-label={formatFullDate(day, locale, calendar)}
aria-current={isCurrentDay ? 'date' : undefined}
xstyle={styles.listDayHeading}>
<span
@@ -146,10 +140,10 @@ function ListDayHeading({
isCurrentDay && styles.listDayNumberCurrent,
)}>
<span {...stylex.props(styles.listDayNumberText)}>
- {formatDayNumber(day, timezoneID, locale)}
+ {formatDayNumber(day, locale, calendar)}
</span>
</span>
- {formatWeekday(day, timezoneID, 'short', locale)}
+ {formatWeekday(day, 'short', locale, calendar)}
</Heading>
);
}
diff --git a/packages/lab/src/Schedule/MonthlyView.tsx b/packages/lab/src/Schedule/MonthlyView.tsx
index 16ce470f3b..f51d098893 100644
--- a/packages/lab/src/Schedule/MonthlyView.tsx
+++ b/packages/lab/src/Schedule/MonthlyView.tsx
@@ -48,22 +48,24 @@ import {
formatEventAccessibilityLabel,
formatEventTimeRange,
formatFullDate,
- formatMonthTitle,
formatWeekday,
formatWeekRange,
+ formatWeekTitle,
getEventCategory,
isEventInPast,
ListEventRow,
MonthEventPill,
ScheduleFrame,
- ScheduleMonthTitle,
SchedulePopoverBody,
+ ScheduleRangeMonthTitle,
styles,
+ useScheduleCalendar,
} from './shared';
import {useCurrentTime} from './useCurrentTime';
import {useScheduleViewPopover} from './useScheduleViewPopover';
import {scheduleRangeToZonedDateTimeRange} from './zonedDateTime';
import type {Locale} from '@astryxdesign/core/i18n';
+import type {CalendarSystem} from '@astryxdesign/core/internal/calendar-system';
import type {
CalendarEvent,
ScheduleCategory,
@@ -136,6 +138,7 @@ function ScheduleMonthlyView({
isLoading,
headingLevel,
} = useScheduleContext();
+ const calendar = useScheduleCalendar();
const rangeDate = date.toPlainDate();
const highlightedDate = focusDate.toPlainDate();
const currentTime = useCurrentTime();
@@ -166,7 +169,11 @@ function ScheduleMonthlyView({
const dayByISO = new Map<string, PlainDate>(
days.map(day => [plainDateToISO(day), day]),
);
- const monthTitle = formatMonthTitle(rangeDate, timezoneID, locale);
+ // The grid shows one Gregorian month, which can span two months of the
+ // calendar, so its title names both.
+ const monthStart = plainDateSetFirstOfMonth(rangeDate);
+ const monthEnd = plainDateAddDays(plainDateAddMonths(monthStart, 1), -1);
+ const monthTitle = formatWeekTitle(monthStart, monthEnd, locale, calendar);
const tableRef = useRef<HTMLDivElement>(null);
// Where each chip painted so far starts, so focus can land on that cell if
// the chip goes away while its popover is open.
@@ -187,9 +194,7 @@ function ScheduleMonthlyView({
}
if (parsed.kind === 'day') {
const day = dayByISO.get(parsed.dayISO);
- return day == null
- ? monthTitle
- : formatFullDate(day, timezoneID, locale);
+ return day == null ? monthTitle : formatFullDate(day, locale, calendar);
}
return eventByID.get(parsed.eventID)?.title ?? monthTitle;
},
@@ -232,7 +237,7 @@ function ScheduleMonthlyView({
const openDayISO = plainDateToISO(openDay);
openContent = (
<SchedulePopoverBody
- label={`${formatFullDate(openDay, timezoneID, locale)} events`}>
+ label={`${formatFullDate(openDay, locale, calendar)} events`}>
<MonthDayEvents
day={openDay}
events={eventsByDay.get(openDayISO) ?? EMPTY_EVENTS}
@@ -255,7 +260,7 @@ function ScheduleMonthlyView({
return (
<ScheduleFrame
- title={<ScheduleMonthTitle date={rangeDate} timezoneID={timezoneID} />}
+ title={<ScheduleRangeMonthTitle start={monthStart} end={monthEnd} />}
titleLabel={monthTitle}
isLoading={isLoading}>
{/* A table, not an interactive grid (component:Schedule AR7): weekday
@@ -283,7 +288,7 @@ function ScheduleMonthlyView({
<div
key={plainDateToISO(day)}
role="columnheader"
- aria-label={formatWeekday(day, timezoneID, 'long', locale)}
+ aria-label={formatWeekday(day, 'long', locale, calendar)}
aria-colindex={index + 2}
{...stylex.props(styles.weekdayLabel)}>
<Heading
@@ -291,7 +296,7 @@ function ScheduleMonthlyView({
color="secondary"
display="block"
xstyle={styles.weekdayHeading}>
- {formatWeekday(day, timezoneID, 'short', locale)}
+ {formatWeekday(day, 'short', locale, calendar)}
</Heading>
</div>
))}
@@ -312,6 +317,7 @@ function ScheduleMonthlyView({
week[week.length - 1],
timezoneID,
locale,
+ calendar,
)}
</div>
{week.map((day, dayIndex) => {
@@ -324,7 +330,7 @@ function ScheduleMonthlyView({
<div
key={plainDateToISO(day)}
role="cell"
- aria-label={formatFullDate(day, timezoneID, locale)}
+ aria-label={formatFullDate(day, locale, calendar)}
aria-colindex={dayIndex + 2}
// Focus lands here when the day's "+N more" goes away.
tabIndex={-1}
@@ -353,7 +359,7 @@ function ScheduleMonthlyView({
color="inherit"
weight="medium"
hasTabularNumbers>
- {formatDayNumber(day, timezoneID, locale)}
+ {formatDayNumber(day, locale, calendar)}
</Text>
</div>
{(chipsByDay.get(index) ?? EMPTY_CHIPS).map(chip => {
@@ -367,7 +373,7 @@ function ScheduleMonthlyView({
{...stylex.props(styles.visuallyHidden)}>
{formatMonthEventName(
chip.event,
- `since ${formatFullDate(startDay, timezoneID, locale)}`,
+ `since ${formatFullDate(startDay, locale, calendar)}`,
timezoneID,
categories,
locale,
@@ -415,7 +421,7 @@ function ScheduleMonthlyView({
type="button"
aria-label={`${hiddenCount} more ${
hiddenCount === 1 ? 'event' : 'events'
- }, ${formatFullDate(day, timezoneID, locale)}`}
+ }, ${formatFullDate(day, locale, calendar)}`}
{...monthPopover.getTriggerProps(
dayKey(dayISO),
// An event handed over from this day's list
@@ -484,6 +490,7 @@ function MonthChip({
isPast: boolean;
}) {
const {categories, timezoneID, locale} = useScheduleContext();
+ const calendar = useScheduleCalendar();
const placement = [
styles.monthChip(chip.columnEnd - chip.columnStart + 1, chip.level),
isLastColumn && styles.monthChipInLastColumn,
@@ -504,7 +511,7 @@ function MonthChip({
}
const name = formatMonthEventName(
chip.event,
- formatEventDays(chip.event, timezoneID, locale),
+ formatEventDays(chip.event, timezoneID, locale, calendar),
timezoneID,
categories,
locale,
@@ -551,8 +558,9 @@ function MonthDayEvents({
onOpenEvent: (event: CalendarEvent) => void;
}) {
const {categories, timezoneID, locale} = useScheduleContext();
+ const calendar = useScheduleCalendar();
const currentTime = useCurrentTime();
- const fullDate = formatFullDate(day, timezoneID, locale);
+ const fullDate = formatFullDate(day, locale, calendar);
return (
<div {...stylex.props(styles.monthDayEvents)}>
<Text type="supporting" weight="bold" color="secondary">
@@ -620,11 +628,12 @@ function formatEventDays(
event: CalendarEvent,
timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
const [first, last] = getEventDateSpan(event, timezoneID);
return plainDateIsEqual(first, last)
- ? formatFullDate(first, timezoneID, locale)
- : formatWeekRange(first, last, timezoneID, locale);
+ ? formatFullDate(first, locale, calendar)
+ : formatWeekRange(first, last, timezoneID, locale, calendar);
}
function getWeeks(days: ReadonlyArray<PlainDate>): PlainDate[][] {
diff --git a/packages/lab/src/Schedule/Schedule.calendarSystems.test.tsx b/packages/lab/src/Schedule/Schedule.calendarSystems.test.tsx
new file mode 100644
index 0000000000..ac094dd191
--- /dev/null
+++ b/packages/lab/src/Schedule/Schedule.calendarSystems.test.tsx
@@ -0,0 +1,317 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Schedule.calendarSystems.test.tsx
+ * @input Schedule views, the shared date formatters, the full Temporal
+ * polyfill
+ * @output Tests that Schedule date labels follow the provider's calendar
+ * @position Colocated tests; the polyfill stands in for the native Temporal of
+ * a supporting runtime
+ */
+
+import 'temporal-polyfill/full/global';
+import {afterAll, afterEach, beforeAll, describe, expect, it, vi} from 'vitest';
+import {render, screen} from '@testing-library/react';
+import {InternationalizationProvider} from '@astryxdesign/core/i18n';
+import type {CalendarSystem} from '@astryxdesign/core/internal/calendar-system';
+import {Schedule} from './Schedule';
+import {createScheduleDayView} from './DayView';
+import {createScheduleMonthlyView} from './MonthlyView';
+import {
+ formatDayNumber,
+ formatEventDateTimeRange,
+ formatFullDate,
+ formatMonthTitle,
+ formatWeekRange,
+ formatWeekTitle,
+} from './shared';
+import type {CalendarInstantEvent, Instant} from './types';
+
+const DATE = {year: 2026, month: 10, day: 30};
+const NOON = new Date(Date.UTC(2026, 9, 30, 12));
+
+const CALENDAR_LOCALES = [
+ {calendar: 'persian', locale: 'en', year: '1405'},
+ {calendar: 'persian', locale: 'fa', year: '۱۴۰۵'},
+ {calendar: 'hebrew', locale: 'en', year: '5787'},
+ {calendar: 'hebrew', locale: 'he', year: '5787'},
+ {calendar: 'buddhist', locale: 'en', year: '2569'},
+ {calendar: 'buddhist', locale: 'th', year: '2569'},
+] as const;
+
+function oracle(
+ locale: string,
+ calendar: CalendarSystem,
+ options: Intl.DateTimeFormatOptions,
+): string {
+ return new Intl.DateTimeFormat(locale, {
+ ...options,
+ timeZone: 'UTC',
+ calendar,
+ }).format(NOON);
+}
+
+function oracleAt(
+ instant: number,
+ locale: string,
+ calendar: CalendarSystem,
+): string {
+ return new Intl.DateTimeFormat(locale, {
+ month: 'long',
+ year: 'numeric',
+ timeZone: 'UTC',
+ calendar,
+ }).format(instant);
+}
+
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+describe.each(CALENDAR_LOCALES)(
+ 'Schedule date labels in $calendar under $locale',
+ ({calendar, locale, year}) => {
+ it('writes the full date in the calendar', () => {
+ const value = formatFullDate(DATE, locale, calendar);
+ expect(value).toBe(
+ oracle(locale, calendar, {
+ weekday: 'long',
+ month: 'long',
+ day: 'numeric',
+ year: 'numeric',
+ }),
+ );
+ expect(value).toContain(year);
+ expect(value).not.toContain('2026');
+ });
+
+ it('writes the month title in the calendar', () => {
+ const value = formatMonthTitle(DATE, locale, calendar);
+ expect(value).toBe(
+ oracle(locale, calendar, {month: 'long', year: 'numeric'}),
+ );
+ expect(value).toContain(year);
+ });
+
+ it('writes the day number in the calendar', () => {
+ expect(formatDayNumber(DATE, locale, calendar)).toBe(
+ oracle(locale, calendar, {day: 'numeric'}),
+ );
+ });
+
+ it('writes a week range in the calendar', () => {
+ const value = formatWeekRange(
+ {year: 2026, month: 10, day: 25},
+ {year: 2026, month: 10, day: 31},
+ 'UTC',
+ locale,
+ calendar,
+ );
+ expect(value).toContain(year);
+ expect(value).not.toContain('2026');
+ });
+
+ it('writes the dates of a long timed event in the calendar, with its times', () => {
+ const event: CalendarInstantEvent = {
+ id: 'offsite',
+ title: 'Offsite',
+ start: Date.UTC(2026, 9, 30, 9) as Instant,
+ end: Date.UTC(2026, 10, 2, 17) as Instant,
+ };
+ const value = formatEventDateTimeRange(event, 'UTC', locale, calendar);
+ expect(value).toBe(
+ new Intl.DateTimeFormat(locale, {
+ month: 'long',
+ day: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit',
+ timeZone: 'UTC',
+ calendar,
+ }).formatRange(new Date(event.start), new Date(event.end)),
+ );
+ });
+ },
+);
+
+describe('Schedule ranges in another calendar', () => {
+ it('titles a month with an era change by its middle, as Calendar does', () => {
+ // Heisei starts on January 8, 1989. Gregorian January 1989 is one month.
+ const title = formatWeekTitle(
+ {year: 1989, month: 1, day: 1},
+ {year: 1989, month: 1, day: 31},
+ 'en',
+ 'japanese',
+ );
+ expect(title).toBe(oracleAt(Date.UTC(1989, 0, 16, 12), 'en', 'japanese'));
+ expect(title).not.toContain('Shōwa');
+ });
+
+ it('names both calendar months when a Gregorian month spans two', () => {
+ expect(
+ formatWeekTitle(
+ {year: 2026, month: 10, day: 1},
+ {year: 2026, month: 10, day: 31},
+ 'en',
+ 'persian',
+ ),
+ ).toBe('Mehr - Aban 1405 AP');
+ });
+
+ it('keeps one Gregorian month as one title', () => {
+ expect(
+ formatWeekTitle(
+ {year: 2026, month: 10, day: 1},
+ {year: 2026, month: 10, day: 31},
+ 'en',
+ 'gregory',
+ ),
+ ).toBe('October 2026');
+ });
+});
+
+function renderMonth(provider: {locale: string; calendar?: CalendarSystem}) {
+ return render(
+ <InternationalizationProvider {...provider}>
+ <Schedule
+ view={createScheduleMonthlyView()}
+ events={[]}
+ date={Date.UTC(2026, 9, 30)}
+ focusDate={Date.UTC(2026, 9, 30)}
+ timezoneID="UTC"
+ />
+ </InternationalizationProvider>,
+ );
+}
+
+describe('Schedule views under a provider calendar', () => {
+ it('titles the month view with the calendar months it shows', () => {
+ renderMonth({locale: 'en', calendar: 'persian'});
+ expect(
+ screen.getByRole('table', {name: 'Mehr - Aban 1405 AP'}),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole('cell', {
+ name: formatFullDate(DATE, 'en', 'persian'),
+ }),
+ ).toBeInTheDocument();
+ });
+
+ it('keeps the Gregorian month view without a provider calendar', () => {
+ renderMonth({locale: 'fa-IR'});
+ expect(
+ screen.getByRole('table', {
+ name: formatMonthTitle(DATE, 'fa-IR', 'gregory'),
+ }),
+ ).toBeInTheDocument();
+ });
+
+ it('names a long timed event with Gregorian dates without a provider calendar', () => {
+ const event: CalendarInstantEvent = {
+ id: 'offsite',
+ title: 'Offsite',
+ start: Date.UTC(2026, 9, 26, 9) as Instant,
+ end: Date.UTC(2026, 9, 28, 17) as Instant,
+ };
+ render(
+ <InternationalizationProvider locale="fa-IR">
+ <Schedule
+ view={createScheduleDayView()}
+ events={[event]}
+ date={Date.UTC(2026, 9, 27)}
+ focusDate={Date.UTC(2026, 9, 27)}
+ timezoneID="UTC"
+ />
+ </InternationalizationProvider>,
+ );
+ const range = (calendar: CalendarSystem) =>
+ new Intl.DateTimeFormat('fa-IR', {
+ month: 'long',
+ day: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit',
+ timeZone: 'UTC',
+ calendar,
+ }).formatRange(new Date(event.start), new Date(event.end));
+ const labels = Array.from(
+ document.querySelectorAll('[aria-label]'),
+ element => element.getAttribute('aria-label') ?? '',
+ ).filter(label => label.includes('Offsite'));
+ expect(labels).not.toHaveLength(0);
+ for (const label of labels) {
+ expect(label).toContain(range('gregory'));
+ expect(label).not.toContain(range('persian'));
+ }
+ });
+
+ it('writes `iso8601` titles and ranges as Gregorian ones', () => {
+ renderMonth({locale: 'en', calendar: 'iso8601'});
+ expect(
+ screen.getAllByText(
+ (_, element) => element?.textContent === 'October 2026',
+ ),
+ ).not.toHaveLength(0);
+ const start = {year: 2026, month: 10, day: 25};
+ const end = {year: 2026, month: 10, day: 31};
+ expect(formatWeekRange(start, end, 'UTC', 'en', 'iso8601')).toBe(
+ formatWeekRange(start, end, 'UTC', 'en', 'gregory'),
+ );
+ const event: CalendarInstantEvent = {
+ id: 'offsite',
+ title: 'Offsite',
+ start: Date.UTC(2026, 9, 30, 9) as Instant,
+ end: Date.UTC(2026, 10, 2, 17) as Instant,
+ };
+ expect(formatEventDateTimeRange(event, 'UTC', 'en', 'iso8601')).toBe(
+ formatEventDateTimeRange(event, 'UTC', 'en', 'gregory'),
+ );
+ });
+
+ it('labels the day view with the date in the calendar', () => {
+ render(
+ <InternationalizationProvider locale="en" calendar="hebrew">
+ <Schedule
+ view={createScheduleDayView()}
+ events={[]}
+ date={Date.UTC(2026, 9, 30)}
+ focusDate={Date.UTC(2026, 9, 30)}
+ timezoneID="UTC"
+ />
+ </InternationalizationProvider>,
+ );
+ expect(
+ screen.getAllByText(formatFullDate(DATE, 'en', 'hebrew')).length,
+ ).toBeGreaterThan(0);
+ });
+
+ describe('without Temporal', () => {
+ const globals = globalThis as {Temporal?: unknown};
+ let savedTemporal: unknown;
+
+ beforeAll(() => {
+ savedTemporal = globals.Temporal;
+ delete globals.Temporal;
+ });
+
+ afterAll(() => {
+ globals.Temporal = savedTemporal;
+ });
+
+ it('shows Gregorian labels for a calendar that needs Temporal', () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ renderMonth({locale: 'en', calendar: 'persian'});
+ expect(
+ screen.getByRole('table', {name: 'October 2026'}),
+ ).toBeInTheDocument();
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringContaining('The "persian" calendar needs a Temporal'),
+ );
+ });
+
+ it('still shows the buddhist calendar, which needs no Temporal', () => {
+ renderMonth({locale: 'en', calendar: 'buddhist'});
+ expect(
+ screen.getByRole('table', {name: 'October 2569 BE'}),
+ ).toBeInTheDocument();
+ });
+ });
+});
diff --git a/packages/lab/src/Schedule/Schedule.doc.mjs b/packages/lab/src/Schedule/Schedule.doc.mjs
index cea9d8c356..ccda2b0b3a 100644
--- a/packages/lab/src/Schedule/Schedule.doc.mjs
+++ b/packages/lab/src/Schedule/Schedule.doc.mjs
@@ -25,7 +25,7 @@ export const docs = {
{
guidance: true,
description:
- 'Wrap Schedule in InternationalizationProvider to choose the language, numbering, and field order used by its date and time labels. Schedule date values and calendar arithmetic remain Gregorian for every locale.',
+ 'Wrap Schedule in InternationalizationProvider to choose the language, numbering, and field order used by its date and time labels; the provider calendar, such as calendar="persian", writes those labels in another calendar. Schedule date values, its grids, and its date navigation stay Gregorian in every calendar and locale.',
},
{
guidance: true,
diff --git a/packages/lab/src/Schedule/Schedule.test.tsx b/packages/lab/src/Schedule/Schedule.test.tsx
index b30c62d78e..ce6927cd30 100644
--- a/packages/lab/src/Schedule/Schedule.test.tsx
+++ b/packages/lab/src/Schedule/Schedule.test.tsx
@@ -63,12 +63,12 @@ describe('Schedule date formatting', () => {
expect(
formatWithPlainDate(
{year: 2026, month: 8, day: 22},
- 'UTC',
{
year: 'numeric',
calendar: 'buddhist',
},
'en',
+ 'gregory',
),
).toBe('2026');
});
@@ -78,9 +78,9 @@ describe('Schedule date formatting', () => {
expect(
formatWithPlainDate(
date,
- 'UTC',
{month: 'long', year: 'numeric'},
'th-TH',
+ 'gregory',
),
).toBe(
new Intl.DateTimeFormat('th-TH', {
diff --git a/packages/lab/src/Schedule/TimeGridView.tsx b/packages/lab/src/Schedule/TimeGridView.tsx
index bd24feb3ba..a9bc6a5b3e 100644
--- a/packages/lab/src/Schedule/TimeGridView.tsx
+++ b/packages/lab/src/Schedule/TimeGridView.tsx
@@ -24,6 +24,7 @@ import {
} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {Locale} from '@astryxdesign/core/i18n';
+import type {CalendarSystem} from '@astryxdesign/core/internal/calendar-system';
import {layerAnimations} from '@astryxdesign/core/Layer';
import {usePopover} from '@astryxdesign/core/Popover';
import {spacingVars} from '@astryxdesign/core/theme/tokens.stylex';
@@ -63,6 +64,7 @@ import {
ScheduleTime,
styles,
TitleFirstPill,
+ useScheduleCalendar,
} from './shared';
import {layoutTimedEvents, type TimedEventPlacement} from './timeGridLayout';
import {
@@ -102,6 +104,7 @@ export function TimeGridView({
renderPopover?: (event: CalendarEvent) => ReactNode;
}) {
const {categories, headingLevel, locale, range} = useScheduleContext();
+ const calendar = useScheduleCalendar();
const hasPopover = renderPopover != null;
const normalizedMinHour = Math.max(0, Math.min(23, Math.floor(minHour)));
const normalizedMaxHour = Math.max(
@@ -355,6 +358,7 @@ export function TimeGridView({
focusDate={focusDate}
hours={hours}
locale={locale}
+ calendar={calendar}
timezoneID={timezoneID}
timezoneLabel={timezoneLabel}
/>
@@ -378,14 +382,14 @@ export function TimeGridView({
display="block"
xstyle={styles.timeGridHeaderHeading}>
<span {...stylex.props(styles.timeGridHeaderHeadingContent)}>
- {formatWeekday(day, timezoneID, 'short', locale)}
+ {formatWeekday(day, 'short', locale, calendar)}
<span
{...stylex.props(
styles.timeGridDayNumber,
plainDateIsEqual(day, focusDate) &&
styles.timeGridCurrentDayPill,
)}>
- {formatDayNumber(day, timezoneID, locale)}
+ {formatDayNumber(day, locale, calendar)}
</span>
</span>
</Heading>
@@ -460,6 +464,7 @@ export function TimeGridView({
timezoneID,
categories,
locale,
+ calendar,
)}
{...stylex.props(placement)}>
{pill}
@@ -482,6 +487,7 @@ export function TimeGridView({
timezoneID,
categories,
locale,
+ calendar,
)}
aria-haspopup="dialog"
aria-expanded={isOpen}
@@ -527,7 +533,7 @@ export function TimeGridView({
{...(hasPopover
? {
role: 'group',
- 'aria-label': formatFullDate(day, timezoneID, locale),
+ 'aria-label': formatFullDate(day, locale, calendar),
}
: {'aria-hidden': true})}
{...stylex.props(
@@ -613,6 +619,7 @@ export function TimeGridView({
timezoneID,
categories,
locale,
+ calendar,
);
if (popoverContent == null) {
return (
@@ -697,6 +704,7 @@ function TimeGridAccessibilityGrid({
focusDate,
hours,
locale,
+ calendar,
timezoneID,
timezoneLabel,
}: {
@@ -707,6 +715,7 @@ function TimeGridAccessibilityGrid({
focusDate: PlainDate;
hours: ReadonlyArray<number>;
locale: Locale;
+ calendar: CalendarSystem;
timezoneID: string;
timezoneLabel: string;
}) {
@@ -728,7 +737,7 @@ function TimeGridAccessibilityGrid({
aria-current={
plainDateIsEqual(day, focusDate) ? 'date' : undefined
}>
- {formatFullDate(day, timezoneID, locale)}
+ {formatFullDate(day, locale, calendar)}
</div>
))}
</div>
@@ -749,8 +758,9 @@ function TimeGridAccessibilityGrid({
categories,
day,
events: cellEvents,
- label: `${formatFullDate(day, timezoneID, locale)} all day`,
+ label: `${formatFullDate(day, locale, calendar)} all day`,
locale,
+ calendar,
timezoneID,
})}
/>
@@ -775,11 +785,12 @@ function TimeGridAccessibilityGrid({
categories,
day,
events: cellEvents,
- label: `${formatFullDate(day, timezoneID, locale)} ${formatHour(
+ label: `${formatFullDate(day, locale, calendar)} ${formatHour(
hour,
locale,
)}`,
locale,
+ calendar,
timezoneID,
})}
/>
@@ -797,6 +808,7 @@ function formatTimeGridAccessibilityCellLabel({
events,
label,
locale,
+ calendar,
timezoneID,
}: {
categories: ReadonlyArray<ScheduleCategory>;
@@ -804,6 +816,7 @@ function formatTimeGridAccessibilityCellLabel({
events: ReadonlyArray<CalendarEvent>;
label: string;
locale: Locale;
+ calendar: CalendarSystem;
timezoneID: string;
}): string {
if (events.length === 0) {
@@ -816,6 +829,7 @@ function formatTimeGridAccessibilityCellLabel({
day,
timezoneID,
locale,
+ calendar,
)}`,
);
return `${label}. ${eventLabels.join('. ')}`;
@@ -837,13 +851,20 @@ function formatEventButtonLabel(
timezoneID: string,
categories: ReadonlyArray<ScheduleCategory>,
locale: Locale,
+ calendar: CalendarSystem,
): string {
const category = getEventCategory(event, categories);
- const timeLabel = formatTimeGridEventTime(event, day, timezoneID, locale);
- return `${event.title}, ${timeLabel}, ${category.label}, ${formatFullDate(
+ const timeLabel = formatTimeGridEventTime(
+ event,
day,
timezoneID,
locale,
+ calendar,
+ );
+ return `${event.title}, ${timeLabel}, ${category.label}, ${formatFullDate(
+ day,
+ locale,
+ calendar,
)}`;
}
@@ -857,12 +878,13 @@ function formatTimeGridEventTime(
day: PlainDate,
timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
if (isDayEvent(event)) {
return 'all day';
}
return isAllDaySpan(event)
- ? formatEventDateTimeRange(event, timezoneID, locale)
+ ? formatEventDateTimeRange(event, timezoneID, locale, calendar)
: formatEventTime(event, day, timezoneID, locale);
}
diff --git a/packages/lab/src/Schedule/WeeklyView.tsx b/packages/lab/src/Schedule/WeeklyView.tsx
index d5b61ec66b..bbdbd1bd62 100644
--- a/packages/lab/src/Schedule/WeeklyView.tsx
+++ b/packages/lab/src/Schedule/WeeklyView.tsx
@@ -19,6 +19,7 @@ import {
formatWeekTitle,
ScheduleFrame,
ScheduleRangeMonthTitle,
+ useScheduleCalendar,
} from './shared';
import {TimeGridView} from './TimeGridView';
import {scheduleRangeToZonedDateTimeRange} from './zonedDateTime';
@@ -39,24 +40,21 @@ function ScheduleWeeklyView({
}: ScheduleViewComponentProps<ScheduleWeeklyViewOptions>) {
const {events, focusDate, timezoneID, locale, range, isLoading} =
useScheduleContext();
+ const calendar = useScheduleCalendar();
const {minHour = 0, maxHour = 24, hourHeight = 100, renderPopover} = options;
const days = enumerateDates(range.startDate, range.endDate);
const highlightedDate = focusDate.toPlainDate();
const titleLabel = formatWeekTitle(
days[0],
days[days.length - 1],
- timezoneID,
locale,
+ calendar,
);
return (
<ScheduleFrame
title={
- <ScheduleRangeMonthTitle
- start={days[0]}
- end={days[days.length - 1]}
- timezoneID={timezoneID}
- />
+ <ScheduleRangeMonthTitle start={days[0]} end={days[days.length - 1]} />
}
titleLabel={titleLabel}
isLoading={isLoading}>
diff --git a/packages/lab/src/Schedule/shared.tsx b/packages/lab/src/Schedule/shared.tsx
index 26afb84c86..5ec1c23483 100644
--- a/packages/lab/src/Schedule/shared.tsx
+++ b/packages/lab/src/Schedule/shared.tsx
@@ -4,7 +4,8 @@
/**
* @file shared.tsx
- * @input Schedule events, dates, timezone IDs, provider locale, and display metadata
+ * @input Schedule events, dates, timezone IDs, provider locale and calendar,
+ * and display metadata
* @output Shared rendering primitives, formatters, and styles for schedule views
* @position Internal view utility module; consumed by Monthly, Weekly, Day, and List views
*/
@@ -13,6 +14,15 @@ import {type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import {useScrollableArea} from '@astryxdesign/core/hooks';
import {getLocaleDirection, type Locale} from '@astryxdesign/core/i18n';
+import {
+ calendarMonthLabelDay,
+ calendarMonthOf,
+ formatCalendarDate,
+ formatCalendarDateToParts,
+ formatCalendarInstantRange,
+ useCalendarSystem,
+ type CalendarSystem,
+} from '@astryxdesign/core/internal/calendar-system';
import {
borderVars,
colorVars,
@@ -28,6 +38,7 @@ import {HStack} from '@astryxdesign/core/Stack';
import {Heading, Text} from '@astryxdesign/core/Text';
import {
plainDateFromInstant,
+ plainDateIsEqual,
plainDateIsBefore,
plainDateToInstant,
type PlainDate,
@@ -115,34 +126,38 @@ export function ScheduleFrame({
);
}
-export function ScheduleMonthTitle({
- date,
- timezoneID,
-}: {
- date: PlainDate;
- timezoneID: string;
-}) {
+/**
+ * The calendar that Schedule writes its date labels in: the provider's
+ * resolved calendar, as Core's date components resolve it. The views still lay
+ * out and step Gregorian days, weeks, and months.
+ */
+export function useScheduleCalendar(): CalendarSystem {
+ return useCalendarSystem(undefined, 'Schedule');
+}
+
+export function ScheduleMonthTitle({date}: {date: PlainDate}) {
const {locale} = useScheduleContext();
+ const calendar = useScheduleCalendar();
return (
- <LocalizedMonthTitle date={date} timezoneID={timezoneID} locale={locale} />
+ <LocalizedMonthTitle date={date} locale={locale} calendar={calendar} />
);
}
function LocalizedMonthTitle({
date,
- timezoneID,
locale,
+ calendar,
}: {
date: PlainDate;
- timezoneID: string;
locale: Locale;
+ calendar: CalendarSystem;
}) {
- const parts = new Intl.DateTimeFormat(locale, {
- month: 'long',
- year: 'numeric',
- timeZone: timezoneID,
- calendar: 'gregory',
- }).formatToParts(new Date(plainDateToInstant(date, timezoneID, 12)));
+ const parts = formatCalendarDateToParts(
+ calendar,
+ monthLabelDate(date, calendar),
+ {month: 'long', year: 'numeric'},
+ locale,
+ );
return parts.map((part, index) =>
part.type === 'month' ? (
@@ -158,39 +173,34 @@ function LocalizedMonthTitle({
export function ScheduleRangeMonthTitle({
start,
end,
- timezoneID,
}: {
start: PlainDate;
end: PlainDate;
- timezoneID: string;
}) {
const {locale} = useScheduleContext();
- if (start.year === end.year && start.month === end.month) {
- return <ScheduleMonthTitle date={start} timezoneID={timezoneID} />;
+ const calendar = useScheduleCalendar();
+ if (isSameCalendarMonth(start, end, calendar)) {
+ return <ScheduleMonthTitle date={start} />;
}
const startMonth = formatWithPlainDate(
- start,
- timezoneID,
+ monthLabelDate(start, calendar),
{month: 'long'},
locale,
+ calendar,
);
const endMonthTitle = (
- <LocalizedMonthTitle date={end} timezoneID={timezoneID} locale={locale} />
+ <LocalizedMonthTitle date={end} locale={locale} calendar={calendar} />
);
- return start.year === end.year ? (
+ return isSameCalendarYear(start, end, locale, calendar) ? (
<>
<span {...stylex.props(styles.titleEmphasis)}>{startMonth}</span> -{' '}
{endMonthTitle}
</>
) : (
<>
- <LocalizedMonthTitle
- date={start}
- timezoneID={timezoneID}
- locale={locale}
- />{' '}
- - {endMonthTitle}
+ <LocalizedMonthTitle date={start} locale={locale} calendar={calendar} /> -{' '}
+ {endMonthTitle}
</>
);
}
@@ -477,62 +487,94 @@ export function eventPastSurfaceColorStyle(
export function formatWithPlainDate(
date: PlainDate,
- timezoneID: string,
options: Intl.DateTimeFormatOptions,
locale: Locale,
+ calendar: CalendarSystem,
): string {
- return new Intl.DateTimeFormat(locale, {
- ...options,
- timeZone: timezoneID,
- calendar: 'gregory',
- }).format(new Date(plainDateToInstant(date, timezoneID, 12)));
+ // Core's helper names the month and day that Calendar shows. Raw Intl can
+ // start a month of the Chinese or Dangi calendar on another day.
+ return formatCalendarDate(calendar, date, options, locale);
+}
+
+function monthLabelDate(date: PlainDate, calendar: CalendarSystem): PlainDate {
+ return calendarMonthLabelDay(calendarMonthOf(calendar, date));
+}
+
+// A Gregorian month or year can span two months or years of another calendar,
+// so ranges compare the calendar's own months and years.
+function isSameCalendarMonth(
+ a: PlainDate,
+ b: PlainDate,
+ calendar: CalendarSystem,
+): boolean {
+ return plainDateIsEqual(
+ calendarMonthOf(calendar, a).start,
+ calendarMonthOf(calendar, b).start,
+ );
+}
+
+function isSameCalendarYear(
+ a: PlainDate,
+ b: PlainDate,
+ locale: Locale,
+ calendar: CalendarSystem,
+): boolean {
+ const options = {year: 'numeric'} as const;
+ return (
+ formatWithPlainDate(
+ monthLabelDate(a, calendar),
+ options,
+ locale,
+ calendar,
+ ) ===
+ formatWithPlainDate(monthLabelDate(b, calendar), options, locale, calendar)
+ );
}
export function formatMonthTitle(
date: PlainDate,
- timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
return formatWithPlainDate(
- date,
- timezoneID,
+ monthLabelDate(date, calendar),
{
month: 'long',
year: 'numeric',
},
locale,
+ calendar,
);
}
export function formatWeekTitle(
start: PlainDate,
end: PlainDate,
- timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
- if (start.year === end.year && start.month === end.month) {
- return formatMonthTitle(start, timezoneID, locale);
+ if (isSameCalendarMonth(start, end, calendar)) {
+ return formatMonthTitle(start, locale, calendar);
}
const startMonth = formatWithPlainDate(
- start,
- timezoneID,
+ monthLabelDate(start, calendar),
{month: 'long'},
locale,
+ calendar,
);
- const endMonthTitle = formatMonthTitle(end, timezoneID, locale);
- return start.year === end.year
+ const endMonthTitle = formatMonthTitle(end, locale, calendar);
+ return isSameCalendarYear(start, end, locale, calendar)
? `${startMonth} - ${endMonthTitle}`
- : `${formatMonthTitle(start, timezoneID, locale)} - ${endMonthTitle}`;
+ : `${formatMonthTitle(start, locale, calendar)} - ${endMonthTitle}`;
}
export function formatFullDate(
date: PlainDate,
- timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
return formatWithPlainDate(
date,
- timezoneID,
{
weekday: 'long',
month: 'long',
@@ -540,6 +582,7 @@ export function formatFullDate(
year: 'numeric',
},
locale,
+ calendar,
);
}
@@ -549,34 +592,33 @@ export function formatWeekRange(
end: PlainDate,
timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
- return new Intl.DateTimeFormat(locale, {
- month: 'long',
- day: 'numeric',
- year: 'numeric',
- timeZone: timezoneID,
- calendar: 'gregory',
- }).formatRange(
+ return formatCalendarInstantRange(
+ calendar,
new Date(plainDateToInstant(start, timezoneID, 12)),
new Date(plainDateToInstant(end, timezoneID, 12)),
+ {month: 'long', day: 'numeric', year: 'numeric'},
+ locale,
+ timezoneID,
);
}
export function formatWeekday(
date: PlainDate,
- timezoneID: string,
weekday: 'short' | 'long',
locale: Locale,
+ calendar: CalendarSystem,
): string {
- return formatWithPlainDate(date, timezoneID, {weekday}, locale);
+ return formatWithPlainDate(date, {weekday}, locale, calendar);
}
export function formatDayNumber(
date: PlainDate,
- timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
- return formatWithPlainDate(date, timezoneID, {day: 'numeric'}, locale);
+ return formatWithPlainDate(date, {day: 'numeric'}, locale, calendar);
}
export function formatHour(hour: number, locale: Locale): string {
@@ -640,14 +682,16 @@ export function formatEventDateTimeRange(
event: CalendarInstantEvent,
timezoneID: string,
locale: Locale,
+ calendar: CalendarSystem,
): string {
- return new Intl.DateTimeFormat(locale, {
- month: 'long',
- day: 'numeric',
- hour: 'numeric',
- minute: '2-digit',
- timeZone: timezoneID,
- }).formatRange(new Date(event.start), new Date(event.end));
+ return formatCalendarInstantRange(
+ calendar,
+ new Date(event.start),
+ new Date(event.end),
+ {month: 'long', day: 'numeric', hour: 'numeric', minute: '2-digit'},
+ locale,
+ timezoneID,
+ );
}
export function formatEventStartTime(
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3ea8fea3d2..97f6bb167b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1003,6 +1003,9 @@ importers:
emojibase-data:
specifier: 17.0.0
version: 17.0.0([email protected])
+ temporal-polyfill:
+ specifier: ^1.0.6
+ version: 1.0.6
packages/native:
devDependencies:
diff --git a/scripts/sync-exports.js b/scripts/sync-exports.js
index 4277ddbe61..abbcf7cf43 100644
--- a/scripts/sync-exports.js
+++ b/scripts/sync-exports.js
@@ -241,6 +241,7 @@ const FILE_MODULE_SUBPATH_EXPORTS = [
'internal/touch',
'internal/selectable-card',
'internal/spinner-rotor',
+ 'internal/calendar-system',
];
/**