Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/local-event-times.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@cal-sdk/provider-utils': patch
'@cal-sdk/mock': patch
---

Event times without an offset, such as `{ dateTime: '2026-11-09T10:00:00', timeZone: 'Europe/Berlin' }`, are read in their own time zone instead of the machine's. This fixes busy times, listing windows and recurrence expansion in the mock calendar.
11 changes: 8 additions & 3 deletions packages/provider-utils/src/time/event-time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ export function isAllDay(time: EventTimeV1): time is Extract<EventTimeV1, { date
/**
* The instant an event time refers to, in epoch milliseconds.
*
* All-day dates have no instant of their own: they start at midnight in
* `allDayTimeZone` (usually the calendar's zone), UTC when omitted.
* A `dateTime` without an offset is a wall-clock time in its `timeZone`, never in the
* zone of the machine running the code. All-day dates have no instant of their own:
* they start at midnight in `allDayTimeZone` (usually the calendar's zone), UTC when
* omitted.
*/
export function eventTimeToInstant(time: EventTimeV1, allDayTimeZone = 'UTC'): number {
if (!isAllDay(time)) return Date.parse(time.dateTime);
if (!isAllDay(time)) {
const wallClock = parseLocalDateTime(time.dateTime);
return wallClock ? localToInstant(wallClock, time.timeZone) : Date.parse(time.dateTime);
}
const local = parseLocalDateTime(time.date);
if (!local) return Number.NaN;
return localToInstant(local, allDayTimeZone);
Expand Down
10 changes: 10 additions & 0 deletions packages/provider-utils/src/time/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ describe('event time', () => {
expect(eventTimeToInstant({ date: '2026-11-03' })).toBe(Date.parse('2026-11-03T00:00:00Z'));
});

it('reads a date-time without an offset in its own time zone, not the host zone', () => {
expect(eventTimeToInstant({ dateTime: '2026-11-09T10:00:00', timeZone: 'Europe/Berlin' })).toBe(
Date.parse('2026-11-09T09:00:00Z'),
);
// Daylight saving time in New York.
expect(eventTimeToInstant({ dateTime: '2026-07-01T09:30', timeZone: 'America/New_York' })).toBe(
Date.parse('2026-07-01T13:30:00Z'),
);
});

it('adds days across month and year ends', () => {
expect(addDaysToDate('2026-12-31', 1)).toBe('2027-01-01');
expect(addDaysToDate('2028-03-01', -1)).toBe('2028-02-29');
Expand Down
Loading