Files
eleith 6c2a8ba2d2
ci/woodpecker/pr/calendar Pipeline was successful
ci/woodpecker/pr/cli Pipeline was successful
ci/woodpecker/pr/web Pipeline was successful
ci/woodpecker/pr/worker Pipeline was successful
fix(calendar): consume server-expanded busy occurrences
2026-10-26 05:21:15 -07:00

23 lines
745 B
TypeScript

import type { ResolvedCalendar } from '@when/config';
import type { BusyWindow, Interval } from './types.js';
import { getCalendarAdapter } from './adapter.js';
export async function fetchBusyIntervals(
cal: ResolvedCalendar,
window: BusyWindow,
opts: { excludeUids?: Set<string> } = {}
): Promise<Interval[]> {
const adapter = getCalendarAdapter(cal);
const events = await adapter.fetchBusy(window);
const exclude = opts.excludeUids;
return events
.filter((event) => !exclude?.has(event.uid))
.filter(
({ start, end }) =>
Temporal.Instant.compare(start, end) < 0 &&
Temporal.Instant.compare(start, window.end) < 0 &&
Temporal.Instant.compare(end, window.start) > 0
)
.map(({ start, end }) => ({ start, end }));
}