# Calendar data

Store timed and all-day events so they land on the right dates.

## Pick the right date format

Use YYYY-MM-DD for dates on a calendar. For a timed event, use ISO timestamps with Z or an offset such as -07:00. Pass an IANA timeZone to choose the local day and clock label where the event appears.

resolveCalendarLocalDateTime(date, hour, minute, second, millisecond, timeZone) resolves a wall time only if it maps to exactly one instant. It throws for a spring-forward time that does not exist and a fall-back time that occurs twice. The caller must choose how to handle those cases. getCalendarDay also throws when the requested local date does not exist in that zone.

## Give each event an ID and a time span

Give each event a unique, stable id and a non-empty title. See the [Calendar API](/libraries/calendar-api) for optional fields such as status, participants, and edit permissions.

For timed events, omit allDay or set it to false. The end is exclusive. Omit end for a point event, which can be moved but cannot be resized.

For all-day events, set allDay: true. Omit end for a one-day event. For an event that runs October 26 through October 28, set start: "2026-10-26" and end: "2026-10-29".

## Assign events to resources

Give each resource a unique, non-empty id and label. Set an event’s resourceId to that ID, or omit it to put the event in the unassigned lane. Schedule views use lanes to display the supplied events. Check availability and conflicts in your app.

## Validate before rendering

validateCalendarData checks the date and timezone, supported view, required event and resource identity, duplicate IDs, resource references, selected field shapes, timestamp validity, and positive duration for non-point intervals. It returns { valid, errors }; it does not repair records. Invalid offset-free timed values, impossible dates, unsupported statuses, duplicate IDs, and non-positive explicit durations produce errors. Callers remain responsible for validating server data and application rules.

```ts
import { validateCalendarData, type CalendarEvent } from "@collectivecreation/ghost-ui/calendar-core";

const events: CalendarEvent[] = [{
  id: "review-1", title: "Design review", allDay: false,
  start: "2026-10-26T09:00:00-07:00", end: "2026-10-26T09:30:00-07:00",
  resourceId: "room-a",
}];
const result = validateCalendarData({ events, date: "2026-10-26", timeZone: "America/Los_Angeles", resources: [{ id: "room-a", label: "Room A" }] });
if (!result.valid) throw new Error(result.errors.join("\n"));
```

For React view props and callback payloads, see [Calendar API](/libraries/calendar-api). For the distinction between proposals and saved events, see [Calendar state](/libraries/calendar-state).

## Store and load events

Serialize event dates and timestamps as strings. Keep all-day values in YYYY-MM-DD form. If you normalize timed values to UTC, store the IANA zone separately when you need the original scheduling zone. A numeric offset has no daylight-saving rules.

CalendarInterval, CalendarDay and CalendarSegment are calculated views of those records. Recompute them for the requested date/zone rather than treating cached milliseconds, lane positions or a 24-hour assumption as persisted event truth. Do not round-trip a Date object through JSON and assume it revives as a Date.

Validate network payload shape before supplying typed records; a TypeScript assertion does not validate JSON. validateCalendarData checks Calendar's contract, while the application validates permissions, recurrence expansion, supported resource policy and any additional metadata. For interval comparisons use half-open bounds: an end equal to the next start is adjacency, not overlap. Display hit targets may be larger than the semantic interval.
