Skip to content

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

TypeScript

fix(storybook): Lab Schedule stories build their demo week from a fixed date in the Schedule's timezone (#9243)

Cindy Zhangc091cf102f5a
diff --git a/apps/storybook/stories/Schedule.stories.tsx b/apps/storybook/stories/Schedule.stories.tsx
index 902891b7e3..c7900cc967 100644
--- a/apps/storybook/stories/Schedule.stories.tsx
+++ b/apps/storybook/stories/Schedule.stories.tsx
@@ -18,10 +18,24 @@ import {
useSchedulePaginationPlugin,
useScheduleViewSelectorPlugin,
} from '@astryxdesign/lab';
+import {
+ plainDateAddDays,
+ plainDateFromISO,
+ plainDateFromInstant,
+ plainDateToISO,
+ plainDateToInstant,
+ type PlainDate,
+} from '@astryxdesign/core/utils';
-const storyNow = new Date();
-const focusDate = storyNow.getTime() as Instant;
-const currentWeekStart = startOfWeek(storyNow);
+// The demo week is fixed and its events are built in the Schedule's own
+// timezone, so every viewer, and CI's browser, sees the same week with its
+// events on the 7-19 grid, whatever the viewer's own timezone or today's date.
+const STORY_TIMEZONE = 'America/Los_Angeles';
+// A Wednesday.
+const STORY_DATE = plainDateFromISO('2026-05-13');
+const focusDate = plainDateToInstant(STORY_DATE, STORY_TIMEZONE, 12) as Instant;
+const currentWeekStart = plainDateAddDays(STORY_DATE, -3);
+const storyNow = STORY_DATE;
const categories: ScheduleCategory[] = [
{label: 'Company', color: 'blue'},
@@ -46,15 +60,15 @@ const events: CalendarEvent[] = [
id: 'all-hands-previous-day',
title: 'Company all hands',
category: 'Company',
- start: dateTimeISO(addDays(storyNow, -1), 9),
- end: dateTimeISO(addDays(storyNow, -1), 10),
+ start: dateTimeISO(plainDateAddDays(storyNow, -1), 9),
+ end: dateTimeISO(plainDateAddDays(storyNow, -1), 10),
}),
createEventFromISO({
id: 'all-hands-next-day',
title: 'Company all hands',
category: 'Company',
- start: dateTimeISO(addDays(storyNow, 1), 9),
- end: dateTimeISO(addDays(storyNow, 1), 10),
+ start: dateTimeISO(plainDateAddDays(storyNow, 1), 9),
+ end: dateTimeISO(plainDateAddDays(storyNow, 1), 10),
}),
createEventFromISO({
id: 'design-review',
@@ -67,43 +81,43 @@ const events: CalendarEvent[] = [
id: 'launch',
title: 'Launch window',
category: 'Launch',
- start: dateISO(addDays(currentWeekStart, 3)),
- end: dateISO(addDays(currentWeekStart, 4)),
+ start: plainDateToISO(plainDateAddDays(currentWeekStart, 3)),
+ end: plainDateToISO(plainDateAddDays(currentWeekStart, 4)),
}),
createEventFromISO({
id: 'focus-day',
title: 'Focus day',
category: 'Focus',
- start: dateISO(storyNow),
- end: dateISO(storyNow),
+ start: plainDateToISO(storyNow),
+ end: plainDateToISO(storyNow),
}),
createEventFromISO({
id: 'company-holiday',
title: 'Company holiday',
category: 'Holiday',
- start: dateISO(addDays(currentWeekStart, 6)),
- end: dateISO(addDays(currentWeekStart, 6)),
+ start: plainDateToISO(plainDateAddDays(currentWeekStart, 6)),
+ end: plainDateToISO(plainDateAddDays(currentWeekStart, 6)),
}),
createEventFromISO({
id: 'retro',
title: 'Weekly retro',
category: 'Retro',
- start: dateTimeISO(addDays(currentWeekStart, 5), 14),
- end: dateTimeISO(addDays(currentWeekStart, 5), 15),
+ start: dateTimeISO(plainDateAddDays(currentWeekStart, 5), 14),
+ end: dateTimeISO(plainDateAddDays(currentWeekStart, 5), 15),
}),
createEventFromISO({
id: 'incident',
title: 'Incident review',
category: 'Incident',
- start: dateTimeISO(addDays(currentWeekStart, 1), 10, 30),
- end: dateTimeISO(addDays(currentWeekStart, 1), 11, 30),
+ start: dateTimeISO(plainDateAddDays(currentWeekStart, 1), 10, 30),
+ end: dateTimeISO(plainDateAddDays(currentWeekStart, 1), 11, 30),
}),
createEventFromISO({
id: 'overnight-migration',
title: 'Overnight migration',
category: 'Migration',
- start: dateTimeISO(addDays(currentWeekStart, 5), 23, 30),
- end: dateTimeISO(addDays(currentWeekStart, 6), 2),
+ start: dateTimeISO(plainDateAddDays(currentWeekStart, 5), 23, 30),
+ end: dateTimeISO(plainDateAddDays(currentWeekStart, 6), 2),
}),
];
@@ -127,30 +141,15 @@ export default meta;
type Story = StoryObj<typeof Schedule>;
-function addDays(date: Date, days: number): Date {
- const nextDate = new Date(date);
- nextDate.setDate(nextDate.getDate() + days);
- return nextDate;
-}
-
-function startOfWeek(date: Date): Date {
- const startDate = new Date(date);
- startDate.setHours(12, 0, 0, 0);
- startDate.setDate(startDate.getDate() - startDate.getDay());
- return startDate;
-}
-
-function dateISO(date: Date): string {
- const year = date.getFullYear();
- const month = String(date.getMonth() + 1).padStart(2, '0');
- const day = String(date.getDate()).padStart(2, '0');
- return `${year}-${month}-${day}`;
-}
-
-function dateTimeISO(date: Date, hour: number, minute: number = 0): string {
- const dateTime = new Date(date);
- dateTime.setHours(hour, minute, 0, 0);
- return dateTime.toISOString();
+// A wall-clock time on a story date in STORY_TIMEZONE, as an ISO instant.
+function dateTimeISO(
+ date: PlainDate,
+ hour: number,
+ minute: number = 0,
+): string {
+ return new Date(
+ plainDateToInstant(date, STORY_TIMEZONE, hour, minute),
+ ).toISOString();
}
function makeSeededRandom(seed: number): () => number {
@@ -176,7 +175,11 @@ function createAsyncEvents(start: Instant, end: Instant): CalendarEvent[] {
for (let dayStart = start; dayStart < end; dayStart += 24 * 60 * 60 * 1000) {
const eventCount = 1 + Math.floor(random() * 3);
- const day = new Date(dayStart);
+ // Midday, so a 23- or 25-hour daylight-saving day still lands on its date.
+ const day = plainDateFromInstant(
+ dayStart + 12 * 60 * 60 * 1000,
+ STORY_TIMEZONE,
+ );
for (let index = 0; index < eventCount; index++) {
const startHour = 8 + Math.floor(random() * 8);
@@ -204,8 +207,8 @@ function createAsyncEvents(start: Instant, end: Instant): CalendarEvent[] {
category:
asyncCategories[Math.floor(random() * asyncCategories.length)]
.label,
- start: dateISO(day),
- end: dateISO(day),
+ start: plainDateToISO(day),
+ end: plainDateToISO(day),
}),
);
}
@@ -227,7 +230,7 @@ export const Monthly: Story = {
date={date}
focusDate={focusDate}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
/>
);
},
@@ -248,7 +251,7 @@ export const Weekly: Story = {
categories={categories}
date={date}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
/>
);
},
@@ -270,7 +273,7 @@ export const WeeklyFixedHeight: Story = {
categories={categories}
date={date}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
style={{height: '100%'}}
/>
</div>
@@ -291,7 +294,7 @@ export const Day: Story = {
date={date}
focusDate={focusDate}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
/>
);
},
@@ -310,7 +313,7 @@ export const List: Story = {
date={date}
focusDate={focusDate}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
/>
);
},
@@ -335,7 +338,7 @@ export const RightToLeftLocale: Story = {
date={date}
focusDate={focusDate}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
/>
</div>
</InternationalizationProvider>
@@ -366,7 +369,7 @@ export const AsyncLoader: Story = {
date={date}
focusDate={focusDate}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
/>
);
},
@@ -970,7 +973,7 @@ export const ViewSelectorPlugin: Story = {
date={date}
focusDate={focusDate}
onChangeDate={setDate}
- timezoneID="America/Los_Angeles"
+ timezoneID={STORY_TIMEZONE}
plugins={plugins}
/>
);
diff --git a/packages/lab/src/Schedule/__tests__/ScheduleTimeDirection.a11y.chromium.spec.ts b/packages/lab/src/Schedule/__tests__/ScheduleTimeDirection.a11y.chromium.spec.ts
index 308a7bcd7e..39b99ec699 100644
--- a/packages/lab/src/Schedule/__tests__/ScheduleTimeDirection.a11y.chromium.spec.ts
+++ b/packages/lab/src/Schedule/__tests__/ScheduleTimeDirection.a11y.chromium.spec.ts
@@ -34,17 +34,9 @@ const RTL_LOCALE = 'lab-schedule--right-to-left-locale';
let evidence: Evidence;
-// The stories build their events from the browser's clock, at fixed hours of
-// the browser's own day and week, and the Schedule shows them in
-// America/Los_Angeles in a 7–19 grid. Run the browser in that zone, so every
-// event lands at its hour in the week the Schedule shows, and pin the clock to
-// the week US daylight saving time ends, so this contract also covers that
-// week, whatever day it runs.
-test.use({timezoneId: 'America/Los_Angeles'});
-const PINNED_NOW = new Date('2026-11-01T10:00:00-08:00');
-test.beforeEach(async ({page}) => {
- await page.clock.install({time: PINNED_NOW});
-});
+// The stories show one fixed week, built in the Schedule's own
+// America/Los_Angeles (Schedule.stories.tsx), so this contract reads the same
+// events in any browser zone and on any day; it needs no zone or clock pin.
test.beforeAll(async () => {
evidence = await startEvidence();
});