@moltenship/calendar 1.0.0-rc.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +27 -6
  2. package/dist/index.d.mts +3 -3
  3. package/dist/index.mjs +2 -2
  4. package/docs/accessibility.md +305 -0
  5. package/docs/agents/changes.md +449 -0
  6. package/docs/agents/coding-agents.md +116 -0
  7. package/docs/agents/connect.md +444 -0
  8. package/docs/agents/deleting.md +296 -0
  9. package/docs/agents/reference.md +511 -0
  10. package/docs/agents/server.md +317 -0
  11. package/docs/agents/webmcp.md +153 -0
  12. package/docs/agents.md +355 -0
  13. package/docs/annotations.md +198 -0
  14. package/docs/api/changes.md +264 -0
  15. package/docs/api/components.md +245 -0
  16. package/docs/api/dnd-kit.md +265 -0
  17. package/docs/api/events.md +153 -0
  18. package/docs/api/primitives.md +218 -0
  19. package/docs/api/store.md +92 -0
  20. package/docs/api.md +57 -0
  21. package/docs/availability.md +576 -0
  22. package/docs/comparison.md +278 -0
  23. package/docs/concepts/anatomy.md +73 -0
  24. package/docs/concepts/events.md +163 -0
  25. package/docs/concepts/how-it-works.md +112 -0
  26. package/docs/concepts/state.md +244 -0
  27. package/docs/concepts/time.md +168 -0
  28. package/docs/customization.md +271 -0
  29. package/docs/frameworks.md +116 -0
  30. package/docs/guides/dnd-kit.md +333 -0
  31. package/docs/guides/google-calendar-sync.md +1246 -0
  32. package/docs/guides/google-calendar.md +367 -0
  33. package/docs/guides/motion.md +414 -0
  34. package/docs/guides/nextjs-app-router.md +630 -0
  35. package/docs/guides/nextjs.md +149 -0
  36. package/docs/guides/performance.md +103 -0
  37. package/docs/guides/tanstack-query.md +485 -0
  38. package/docs/ics/feed.md +484 -0
  39. package/docs/ics/import.md +183 -0
  40. package/docs/ics/reference.md +482 -0
  41. package/docs/ics.md +142 -0
  42. package/docs/index.md +149 -0
  43. package/docs/installation.md +209 -0
  44. package/docs/interactions.md +441 -0
  45. package/docs/llms.txt +99 -0
  46. package/docs/migrating-to-2.md +497 -0
  47. package/docs/quick-start.md +163 -0
  48. package/docs/recurrence/calendar.md +598 -0
  49. package/docs/recurrence/model.md +128 -0
  50. package/docs/recurrence/reference.md +547 -0
  51. package/docs/recurrence.md +122 -0
  52. package/docs/stylex.md +290 -0
  53. package/docs/temporal/daylight-saving-time.md +172 -0
  54. package/docs/temporal/month-grid.md +119 -0
  55. package/docs/temporal/reference.md +167 -0
  56. package/docs/temporal.md +105 -0
  57. package/docs/testing.md +600 -0
  58. package/docs/theme-builder.md +82 -0
  59. package/docs/theming.md +275 -0
  60. package/docs/undo-redo.md +347 -0
  61. package/docs/views/agenda.md +222 -0
  62. package/docs/views/custom-views.md +195 -0
  63. package/docs/views/month.md +110 -0
  64. package/docs/views/resource-columns.md +265 -0
  65. package/docs/views/resource-timeline.md +226 -0
  66. package/docs/views/scrolling.md +193 -0
  67. package/docs/views/week-and-day.md +258 -0
  68. package/docs/views/year.md +138 -0
  69. package/docs/views.md +69 -0
  70. package/package.json +42 -14
  71. package/skills/moltenship-time/SKILL.md +77 -0
  72. package/skills/moltenship-time/references/agent-ready.md +272 -0
  73. package/skills/moltenship-time/references/changes.md +188 -0
  74. package/skills/moltenship-time/references/compose.md +175 -0
  75. package/skills/moltenship-time/references/mistakes.md +100 -0
  76. package/skills/moltenship-time/references/solid.md +213 -0
  77. package/skills/moltenship-time/references/state.md +129 -0
  78. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,122 @@
1
+ # Overview
2
+
3
+ What @moltenship/calendar-recurrence is, how to install it, and a first expansion of a rule into dates.
4
+
5
+ Source: https://time.molten.sh/docs/react/recurrence
6
+
7
+ `@moltenship/calendar-recurrence` handles events that repeat. A series is stored the way
8
+ iCalendar, Google Calendar and Outlook store it: one master event with a rule, plus events that
9
+ replace single occurrences. The package does two things with a series:
10
+
11
+ - **It expands it** into the occurrences inside a range of dates, usually the dates on screen.
12
+ - **It turns a change to one occurrence into what to save** for "this event", "this and following
13
+ events" or "all events".
14
+
15
+ ## Use it without the calendar
16
+
17
+ The package imports no UI framework. It depends on `@moltenship/calendar-core` and
18
+ `@moltenship/ics`, which import none either, so it expands a series on a server, in a worker or in
19
+ a script as it does in a browser.
20
+
21
+ The calendar doesn't need it, and doesn't re-export it. Occurrences reach a calendar as ordinary
22
+ events, through an adapter, so views, dragging and the event engine work the same with or without
23
+ it.
24
+
25
+ ## Install
26
+
27
+ **pnpm**
28
+
29
+ ```bash
30
+ pnpm add @moltenship/calendar-recurrence
31
+ ```
32
+
33
+ **npm**
34
+
35
+ ```bash
36
+ npm install @moltenship/calendar-recurrence
37
+ ```
38
+
39
+ **yarn**
40
+
41
+ ```bash
42
+ yarn add @moltenship/calendar-recurrence
43
+ ```
44
+
45
+ **bun**
46
+
47
+ ```bash
48
+ bun add @moltenship/calendar-recurrence
49
+ ```
50
+
51
+ The package is versioned with the calendar. Keep it on the same version as the calendar, so both share one copy of
52
+ the engine.
53
+
54
+ It needs a runtime with `Temporal`, or a polyfill loaded first, and TypeScript's `ESNext` library.
55
+ [Installation](./installation.md#temporal) shows both.
56
+
57
+ ## From a rule to dates
58
+
59
+ `parseRecurrenceRule` reads a rule as iCalendar writes it, and `expandRecurrenceRule` lists the
60
+ starts it gives from a first occurrence:
61
+
62
+ ```ts title="starts.ts"
63
+ import { expandRecurrenceRule, parseRecurrenceRule } from "@moltenship/calendar-recurrence";
64
+
65
+ /** The starts of a meeting that repeats by `rrule`, a rule as iCalendar writes it. */
66
+ export function startsOf(first: Temporal.ZonedDateTime, rrule: string): string[] {
67
+ // Never throws: text without a usable rule gives no rule, and says why in `issues`.
68
+ const { rule } = parseRecurrenceRule(rrule);
69
+ if (rule === undefined) return [];
70
+
71
+ const { dates } = expandRecurrenceRule(rule, {
72
+ kind: "timed",
73
+ start: first.toInstant(),
74
+ end: first.add({ minutes: 30 }).toInstant(),
75
+ // The series repeats on this zone's wall clock.
76
+ sourceTimeZone: first.timeZoneId,
77
+ });
78
+ return dates.map((date) => date.toString());
79
+ }
80
+
81
+ export const mondays = startsOf(
82
+ Temporal.ZonedDateTime.from("2026-10-19T09:00[Europe/Berlin]"),
83
+ "FREQ=WEEKLY;BYDAY=MO;COUNT=3",
84
+ );
85
+ ```
86
+
87
+ `mondays` holds three instants:
88
+
89
+ ```text
90
+ 2026-10-19T07:00:00Z
91
+ 2026-10-26T08:00:00Z
92
+ 2026-11-02T08:00:00Z
93
+ ```
94
+
95
+ Each is 09:00 in Berlin. The clocks there go back on October 25, so the instant moves by an hour
96
+ and the meeting stays at 09:00. A timed series repeats on the wall clock of its own time zone.
97
+
98
+ The expansion covers RFC 5545: every `FREQ`, every `BY` part, `BYSETPOS`, `WKST`, `COUNT` and
99
+ `UNTIL`. A rule without an end is endless, so pass a window of dates as the third argument, as
100
+ [The engine](./recurrence/reference.md#the-engine) shows.
101
+
102
+ ## From events to occurrences
103
+
104
+ A rule alone has no exceptions and no moved occurrences. For those, the package reads your own
105
+ events through two adapters and expands them together:
106
+
107
+ - `createOccurrenceExpander(adapters)` returns an expander. `expander.expand(events, range)`
108
+ returns every occurrence that overlaps the range, with exception dates left out and overrides in
109
+ place. One-off events pass through.
110
+ - `recurringEventsFromIcs(calendar.events)` groups events parsed by
111
+ [`@moltenship/ics`](./ics.md) into masters, overrides and one-off events, ready for the
112
+ expander.
113
+ - `resolveRecurrenceEdit` and `applyRecurrenceEdit` turn a moved, resized or deleted occurrence
114
+ into the events to write.
115
+
116
+ [Series and occurrences](./recurrence/model.md) explains the model these share.
117
+
118
+ ## Next
119
+
120
+ - [Series and occurrences](./recurrence/model.md): Masters, exception dates and overrides, occurrence IDs, and what each edit scope changes.
121
+ - [Show and edit recurring events](./recurrence/calendar.md): Expand the dates on screen, ask which events a change applies to, and save the edit.
122
+ - [API reference](./recurrence/reference.md): Adapters, expansion, occurrence IDs, rules, the ICS bridge and edits.
package/docs/stylex.md ADDED
@@ -0,0 +1,290 @@
1
+ # StyleX
2
+
3
+ The calendar's views styled with StyleX, for apps without Tailwind.
4
+
5
+ Source: https://time.molten.sh/docs/react/stylex
6
+
7
+ The registry's baseline is Tailwind. The `stylex-*` items look the same as the Tailwind ones and
8
+ exist for apps that style with [StyleX](https://stylexjs.com): the same sizes, colours, type, hover
9
+ and focus states and motion, control by control and view by view, in light and dark. They hold the
10
+ same components with the same behaviour, every view included: same file names, exports,
11
+ `data-slot` attributes, roles and labels. Only the styles differ, `stylex.create` rather than
12
+ Tailwind classes. Buttons, tooltips, the view select, popovers, dialogs and toasts come from
13
+ `stylex-calendar-ui`, the StyleX twin of the calendar's kit: the same parts on
14
+ [ui-sdk](https://ui-sdk.dev). As with the baseline, you own the source you add.
15
+
16
+ One detail differs: in dark, a hovered event dims a little where the Tailwind one brightens.
17
+ StyleX's dark colours follow the page's `color-scheme` through `light-dark()`, which takes only
18
+ colours, so a filter can't change with it.
19
+
20
+ See it running on the demo's [StyleX page](https://moltenship-time-demo.vercel.app/stylex/).
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install @stylexjs/stylex
26
+ npm install --save-dev @stylexjs/unplugin
27
+ ```
28
+
29
+ `@moltenship/calendar`, `@ui-sdk/react` and `lucide-react` come with the items, as [UI source](./installation.md#ui-source-optional)
30
+ describes, and [Temporal](./installation.md#temporal) needs the same setup as in any app.
31
+
32
+ ## Configure Vite
33
+
34
+ ```ts title="vite.config.ts"
35
+ import { fileURLToPath } from "node:url";
36
+
37
+ import stylex from "@stylexjs/unplugin";
38
+ import react from "@vitejs/plugin-react";
39
+ import { defineConfig } from "vite";
40
+
41
+ const fromHere = (path: string) => fileURLToPath(new URL(path, import.meta.url));
42
+
43
+ export default defineConfig(({ command }) => ({
44
+ plugins: [
45
+ // Before React.
46
+ stylex.vite({
47
+ aliases: { "@/*": [fromHere("src/*")] },
48
+ dev: command === "serve",
49
+ lightningcssOptions: {
50
+ targets: { chrome: 123 << 16, firefox: 120 << 16, safari: (17 << 16) | (5 << 8) },
51
+ },
52
+ runtimeInjection: false,
53
+ unstable_moduleResolution: { rootDir: fromHere("."), type: "commonJS" },
54
+ }),
55
+ react(),
56
+ ],
57
+ build: { cssTarget: ["chrome123", "firefox120", "safari17.5"] },
58
+ resolve: { alias: { "@": fromHere("src") } },
59
+ }));
60
+ ```
61
+
62
+ - `aliases` and `unstable_moduleResolution` let StyleX find the tokens file. The items import it as
63
+ `@/components/calendar-stylex/calendar-tokens.stylex`, and StyleX reads it at compile time. Vite's
64
+ own alias doesn't reach the StyleX compiler, so it needs both.
65
+ - `lightningcssOptions.targets` and `build.cssTarget` name browsers that have `light-dark()`. The
66
+ calendar's tokens rely on it for dark mode. With older targets it's lowered to a polyfill
67
+ that needs `color-scheme` in the same stylesheet, and dark colors break without an error.
68
+
69
+ ## Add the global CSS
70
+
71
+ Declare ui-sdk's layer first, then import the calendar's stylesheet. `calendar-global.css` holds the
72
+ few rules StyleX can't write, such as those for drag previews, and arrives with the items. The
73
+ tokens follow the page's `color-scheme` through `light-dark()`, so set it too, or let your app's
74
+ mode toggle set it on the root:
75
+
76
+ ```css title="styles.css"
77
+ @layer ui-sdk;
78
+ @import "@/components/calendar-stylex/calendar-global.css";
79
+
80
+ :root {
81
+ color-scheme: light dark;
82
+ }
83
+ ```
84
+
85
+ The calendar needs no other theme: its tokens hold their own colors, those of the Tailwind theme.
86
+ To use your design system's, [map them](#use-your-design-systems-colors).
87
+
88
+ ## Add the items
89
+
90
+ `shadcn add` needs a `components.json` to know your aliases, even in an app without Tailwind, and
91
+ your `tsconfig.json` needs the `@/*` path. The schema requires the `tailwind` block, but these items
92
+ don't read it or `style`, and adding them leaves your CSS as it is:
93
+
94
+ ```json title="components.json"
95
+ {
96
+ "$schema": "https://ui.shadcn.com/schema.json",
97
+ "style": "new-york",
98
+ "rsc": false,
99
+ "tsx": true,
100
+ "tailwind": { "css": "src/styles.css", "baseColor": "neutral", "cssVariables": true },
101
+ "aliases": {
102
+ "components": "@/components",
103
+ "utils": "@/lib/utils",
104
+ "ui": "@/components/ui",
105
+ "lib": "@/lib",
106
+ "hooks": "@/hooks"
107
+ }
108
+ }
109
+ ```
110
+
111
+ `stylex-calendar-full` installs every view, the tokens, the controls and the parts they share:
112
+
113
+ ```bash
114
+ npx shadcn@latest add https://time.molten.sh/r/stylex-calendar-full.json
115
+ ```
116
+
117
+ Or add one view, which brings what it builds on. Every item in the
118
+ [table on Installation](./installation.md#ui-source-optional) has a `stylex-` version:
119
+
120
+ ```bash
121
+ npx shadcn@latest add https://time.molten.sh/r/stylex-month-view.json
122
+ ```
123
+
124
+ The files land in `calendar-stylex/` under your `components` alias, and the controls in
125
+ `calendar-stylex/ui/`, so they never overwrite the Tailwind ones.
126
+
127
+ ## Use the views
128
+
129
+ The API is the [Quick start](./quick-start.md)'s, with imports from `calendar-stylex`:
130
+
131
+ ```tsx title="calendar.tsx"
132
+ import { createCalendar, defineEventAdapter } from "@moltenship/calendar";
133
+ import * as stylex from "@stylexjs/stylex";
134
+
135
+ import { CalendarToolbar } from "@/components/calendar-stylex/calendar-toolbar";
136
+ import { createMonthView } from "@/components/calendar-stylex/month-view/month-view";
137
+ import { createWeekView } from "@/components/calendar-stylex/time-grid-view/time-grid-view";
138
+
139
+ const eventAdapter = defineEventAdapter<Meeting>()({
140
+ getId: (meeting) => meeting.id,
141
+ getTitle: (meeting) => meeting.title,
142
+ getInterval: (meeting) => ({ kind: "timed", start: meeting.start, end: meeting.end }),
143
+ getResourceIds: () => [],
144
+ });
145
+
146
+ const Calendar = createCalendar<Meeting>()({
147
+ eventAdapter,
148
+ views: [createWeekView<Meeting>(), createMonthView<Meeting>()],
149
+ });
150
+
151
+ const styles = stylex.create({
152
+ frame: { display: "flex", flexDirection: "column", height: 640 },
153
+ viewport: { flexGrow: 1, minHeight: 0 },
154
+ });
155
+
156
+ export function TeamCalendar({ meetings }: { readonly meetings: readonly Meeting[] }) {
157
+ return (
158
+ <Calendar.Root
159
+ events={meetings}
160
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
161
+ defaultTimeZone="Europe/Berlin"
162
+ locale="en-US"
163
+ weekRules={{ firstDay: 1, minimalDays: 4, weekend: [6, 7] }}
164
+ >
165
+ <Calendar.Frame {...stylex.props(styles.frame)}>
166
+ <CalendarToolbar calendar={Calendar} />
167
+ <Calendar.Viewport {...stylex.props(styles.viewport)}>
168
+ <Calendar.ActiveView />
169
+ </Calendar.Viewport>
170
+ </Calendar.Frame>
171
+ </Calendar.Root>
172
+ );
173
+ }
174
+ ```
175
+
176
+ ## Change the tokens
177
+
178
+ The tokens have the names in [Theming](./theming.md#tokens), as keys of `calendarVars`:
179
+ `calendarVars["--calendar-today"]` is `var(--calendar-today)`. Override them on a part of the page
180
+ with `stylex.createTheme`, and apply the theme on a wrapper. One value covers both modes through
181
+ `light-dark()`, which takes only colors:
182
+
183
+ ```tsx
184
+ import * as stylex from "@stylexjs/stylex";
185
+
186
+ import { calendarVars } from "@/components/calendar-stylex/calendar-tokens.stylex";
187
+
188
+ const calendarTheme = stylex.createTheme(calendarVars, {
189
+ "--calendar-today": "light-dark(oklch(0.55 0.17 150), oklch(0.72 0.15 150))",
190
+ "--calendar-hour-height": "4rem",
191
+ });
192
+
193
+ <div {...stylex.props(calendarTheme)}>
194
+ <TeamCalendar meetings={meetings} />
195
+ </div>;
196
+ ```
197
+
198
+ Tokens are resolved where they're declared, on `:root`. So a wrapper that overrides `--primary`
199
+ doesn't change `--calendar-event-border`, which reads `var(--primary)`: restate it in the same
200
+ theme. The [Theme builder](./theme-builder.md#use-the-stylex-theme) does this for you, and lets you
201
+ try a theme and copy it.
202
+
203
+ Popovers, tooltips, dialogs and toasts render inside the calendar, in the browser's top layer, so a
204
+ theme on a wrapper reaches them too.
205
+
206
+ `--calendar-surface` is no token. It's unset, and the views read it through a constant, for a
207
+ container with its own background to set in an inline `style`, as on
208
+ [Theming](./theming.md#changing-tokens).
209
+
210
+ ## Use your design system's colors
211
+
212
+ The base colors, such as `--background`, `--primary` and `--border`, hold the values of the
213
+ Tailwind theme. To have the calendar follow your design system, point them at its variables. For
214
+ a design system whose root theme puts its variables on `<html>`, that's:
215
+
216
+ ```tsx
217
+ const appCalendarTheme = stylex.createTheme(calendarVars, {
218
+ "--radius": "var(--app-radius)",
219
+ "--background": "var(--app-surface)",
220
+ "--foreground": "var(--app-text)",
221
+ "--popover": "var(--app-surface-raised)",
222
+ "--primary": "var(--app-accent)",
223
+ "--muted-foreground": "var(--app-text-muted)",
224
+ "--border": "var(--app-border)",
225
+ "--ring": "var(--app-focus)",
226
+ // …and the rest of the base colors in the list on Theming, in the same way.
227
+ });
228
+
229
+ // On `<html>` too, so the tokens that read a base color, such as `--calendar-event-border`, follow.
230
+ document.documentElement.classList.add(
231
+ ...(stylex.props(appCalendarTheme).className ?? "").split(" "),
232
+ );
233
+ ```
234
+
235
+ [Tokens](./theming.md#tokens) lists the base colors.
236
+
237
+ ## Override a component's styles
238
+
239
+ The components take `xstyle` beside `className` and `style`, for styles of your own. They win over
240
+ the component's:
241
+
242
+ ```tsx
243
+ const styles = stylex.create({
244
+ toolbar: { paddingBlock: "1rem" },
245
+ });
246
+
247
+ <CalendarToolbar calendar={Calendar} xstyle={styles.toolbar} />;
248
+ ```
249
+
250
+ The controls in `calendar-stylex/ui/` take `xstyle` too. To change a control everywhere, edit its
251
+ styles in its `.styles.ts` file, or replace the control, as
252
+ [Use your own controls](./theming.md#use-your-own-controls) describes.
253
+
254
+ ## Event colors
255
+
256
+ Views take `getEventColor`, and the names are the same nine, as in
257
+ [Choosing a color per event](./theming.md#choosing-a-color-per-event). Each color has three tokens
258
+ of its own, in place of the baseline's hue and chroma: `--calendar-event-blue`,
259
+ `--calendar-event-blue-foreground` and `--calendar-event-blue-border`. Override them with
260
+ `createTheme` like any other:
261
+
262
+ ```tsx
263
+ const calendarTheme = stylex.createTheme(calendarVars, {
264
+ "--calendar-event-blue": "light-dark(oklch(0.92 0.06 240), oklch(0.35 0.08 240))",
265
+ });
266
+ ```
267
+
268
+ `eventColorStyles` in `event-color-styles.ts` points an element's `--calendar-event` tokens at one
269
+ color, and `data-color` stays on the element as a hook for your own CSS. To add a color, add its
270
+ name to `event-colors.ts`, its tokens to `calendar-tokens.stylex.ts`, and an entry to
271
+ `eventColorStyles`.
272
+
273
+ ## Next.js
274
+
275
+ The demo and CI exercise this flavour under Vite, and not under Next.js. With Next.js, StyleX
276
+ compiles through `@stylexjs/babel-plugin` in `babel.config.js`, with the `@/*` alias, and
277
+ `@stylexjs/postcss-plugin`, with `@stylex;` in the global CSS; see StyleX's
278
+ [installation guide](https://stylexjs.com/docs/learn/installation/).
279
+
280
+ ## What's different from the baseline
281
+
282
+ - The controls come from `stylex-calendar-ui`, in `calendar-stylex/ui/`, not `calendar-ui`. They
283
+ have the same parts, props and `data-slot` attributes, built on ui-sdk as well. Their look is
284
+ `stylex.create` in the `.styles.ts` file beside each.
285
+ - StyleX's classes have the same specificity as a global `[data-slot]` rule, and come after your
286
+ CSS. So a rule of yours that sets a property a view's styles also set, such as an
287
+ [Availability](./availability.md) recipe's background color, needs a stronger selector:
288
+ `[data-slot="time-grid-unavailable"][data-slot]`. Or use `xstyle` or the tokens.
289
+ - A fix to a view goes to both flavours. You get it the way you do for the baseline, by running
290
+ `shadcn add` for the item again, which asks before it replaces a file you changed.
@@ -0,0 +1,172 @@
1
+ # Handle daylight saving time
2
+
3
+ Days of 23 and 25 hours, wall-clock times the clocks skip or repeat, and the rows of a day view, with @moltenship/calendar-temporal.
4
+
5
+ Source: https://time.molten.sh/docs/react/temporal/daylight-saving-time
6
+
7
+ Twice a year, in a zone with daylight saving time, a date isn't 24 hours long. In Berlin the
8
+ clocks go from 02:00 to 03:00 on March 29, 2026, so that date lasts 23 hours and 02:15 never
9
+ happens. On October 25 they go from 03:00 back to 02:00, so the date lasts 25 hours and 02:15
10
+ happens twice. Code that adds 24 hours to midnight, or that turns "02:15" into an instant without
11
+ looking, is wrong on those two dates.
12
+
13
+ The functions on this page take the time zone as an argument and never read the host's.
14
+
15
+ ## How long a date is
16
+
17
+ `zonedDayRange(date, timeZone)` returns the real start and end of a date in a zone, and its length:
18
+
19
+ ```ts title="daylight-saving-time.ts"
20
+ import {
21
+ resolveZonedWallTime,
22
+ slotsInZonedDay,
23
+ snapZonedWallTime,
24
+ zonedDayRange,
25
+ } from "@moltenship/calendar-temporal";
26
+
27
+ /** How many hours a date lasts in a time zone: 23, 24 or 25 in most of them. */
28
+ export function hoursInDay(date: Temporal.PlainDate, timeZone: string): number {
29
+ return zonedDayRange(date, timeZone).duration.total("hours");
30
+ }
31
+ ```
32
+
33
+ In `Europe/Berlin`, `hoursInDay` returns 23 for March 29, 2026, 25 for October 25 and 24 for
34
+ October 8.
35
+
36
+ ## Which events are on a date
37
+
38
+ `interval` on the result is the range of instants to compare events with. Compare with it, and not
39
+ with midnight plus 24 hours:
40
+
41
+ ```ts title="daylight-saving-time.ts"
42
+ /** Whether an event's instants overlap a date in a time zone. */
43
+ export function isOnDate(
44
+ event: { readonly start: Temporal.Instant; readonly end: Temporal.Instant },
45
+ date: Temporal.PlainDate,
46
+ timeZone: string,
47
+ ): boolean {
48
+ const day = zonedDayRange(date, timeZone);
49
+ // A few zones have skipped a whole date. Such a date has no instants to compare with.
50
+ if (day.kind === "skipped") return false;
51
+ return (
52
+ Temporal.Instant.compare(event.start, day.interval.end) < 0 &&
53
+ Temporal.Instant.compare(event.end, day.interval.start) > 0
54
+ );
55
+ }
56
+ ```
57
+
58
+ An event from 22:30 to 23:00 UTC on October 8 is on October 9 in Berlin, where it starts at 00:30,
59
+ and on October 8 in New York.
60
+
61
+ `kind` is `"skipped"` in the rare case where a zone skips a whole date, as Samoa did on December
62
+ 30, 2011. Such a date has no instants, and `interval` is `null`.
63
+
64
+ For an event that crosses midnight, `splitInstantRangeByZonedDay(range, timeZone)` cuts its range
65
+ into one piece per date, and each piece says whether the event continues before or after that
66
+ date.
67
+
68
+ ## The rows of a day view
69
+
70
+ A day view shows the wall clock: 24 rows labelled 00:00 to 23:00, on every date. `slotsInZonedDay`
71
+ returns those rows with the instants behind each:
72
+
73
+ ```ts title="daylight-saving-time.ts"
74
+ export interface HourRow {
75
+ /** The time on the wall clock, such as "02:00". */
76
+ readonly label: string;
77
+ /** "gap" for an hour the clocks skip, "fold" for one they repeat, else "unique". */
78
+ readonly kind: string;
79
+ /** When the row starts: no instant in a gap, two in a fold. */
80
+ readonly starts: readonly Temporal.Instant[];
81
+ }
82
+
83
+ /** The hour rows of a day view. Every day has the same 24 labels, whatever its length. */
84
+ export function hourRows(date: Temporal.PlainDate, timeZone: string): HourRow[] {
85
+ const { slots } = slotsInZonedDay(date, {
86
+ timeZone,
87
+ disambiguation: "compatible",
88
+ slotDuration: { hours: 1 },
89
+ });
90
+ return slots.map((slot) => ({
91
+ label: slot.wallRange.start.toPlainTime().toString({ smallestUnit: "minute" }),
92
+ kind: slot.kind,
93
+ starts: slot.segments.flatMap((segment) =>
94
+ segment.occurrences.map((occurrence) => occurrence.interval.start),
95
+ ),
96
+ }));
97
+ }
98
+ ```
99
+
100
+ On March 29 in Berlin the 02:00 row is a gap and has no instant. On October 25 it is a fold and
101
+ has two:
102
+
103
+ ```text
104
+ March 29, 2026 October 25, 2026
105
+ 01:00 unique 2026-03-29T00:00:00Z 01:00 unique 2026-10-24T23:00:00Z
106
+ 02:00 gap 02:00 fold 2026-10-25T00:00:00Z 2026-10-25T01:00:00Z
107
+ 03:00 unique 2026-03-29T01:00:00Z 03:00 unique 2026-10-25T02:00:00Z
108
+ ```
109
+
110
+ A slot that a clock change cuts through is split at the change: its `kind` is `"transition"` and it
111
+ has one segment for each part. The function throws a `RangeError` when a day would have more than
112
+ 10,000 slots, and `limit` raises that.
113
+
114
+ ## A time a person typed
115
+
116
+ A form gives a date and a time with no zone. `resolveZonedWallTime` turns them into an instant and
117
+ says what it found: `kind` is `"unique"`, `"gap"` or `"fold"`.
118
+
119
+ ```ts title="daylight-saving-time.ts"
120
+ export type PickedTime =
121
+ | { readonly ok: true; readonly instant: Temporal.Instant }
122
+ | { readonly ok: false; readonly reason: string };
123
+
124
+ /** The instant of a date and time a person typed into a form. */
125
+ export function pickTime(wallTime: Temporal.PlainDateTime, timeZone: string): PickedTime {
126
+ const result = resolveZonedWallTime(wallTime, { timeZone, disambiguation: "compatible" });
127
+
128
+ if (result.status === "rejected") return { ok: false, reason: "That time can't be used." };
129
+ if (result.kind === "gap") {
130
+ // The clocks skipped this time. `adjustment` has the time "compatible" moved it to.
131
+ const moved = result.adjustment?.resolvedWallTime.toPlainTime().toString({
132
+ smallestUnit: "minute",
133
+ });
134
+ return { ok: false, reason: `The clocks skip that time. Did you mean ${moved}?` };
135
+ }
136
+ // In a fold the time happens twice, and `selected` is the first of `occurrences`.
137
+ return { ok: true, instant: result.selected.instant };
138
+ }
139
+ ```
140
+
141
+ With Berlin as the zone:
142
+
143
+ | The person typed | `pickTime` returns |
144
+ | ----------------- | --------------------------------------------------- |
145
+ | October 8, 02:15 | The instant `2026-10-08T00:15:00Z` |
146
+ | March 29, 02:15 | "The clocks skip that time. Did you mean 03:15?" |
147
+ | October 25, 02:15 | The instant `2026-10-25T00:15:00Z`, the first 02:15 |
148
+
149
+ `disambiguation` takes Temporal's four values. `"compatible"` moves a skipped time later by the
150
+ length of the gap and picks the earlier of two repeated times. `"reject"` gives a result whose
151
+ `status` is `"rejected"` for both. In a fold, `occurrences` holds both instants, so a form can ask
152
+ which one the person meant.
153
+
154
+ ## A pointer on a time grid
155
+
156
+ A drag gives a wall-clock time that needs rounding to the grid. `snapZonedWallTime` rounds it and
157
+ resolves it in one step:
158
+
159
+ ```ts title="daylight-saving-time.ts"
160
+ /** A pointer's position on a day view, rounded to the 15-minute grid. */
161
+ export function snapToGrid(wallTime: Temporal.PlainDateTime, timeZone: string) {
162
+ return snapZonedWallTime(wallTime, { timeZone, increment: 15, smallestUnit: "minute" });
163
+ }
164
+ ```
165
+
166
+ 09:07 on October 8 snaps to 09:00. 02:10 on March 29 has no 02:00 or 02:15 to snap to, so it lands
167
+ on 03:00, the moment the clocks change. `mode` is `"nearest"` by default, or `"floor"` or `"ceil"`,
168
+ and `fold` picks the earlier or the later of two repeated times.
169
+
170
+ The calendar's week and day views are built on these functions, so they draw a 23-hour day and a
171
+ repeated hour without code of yours. [Time and time zones](../concepts/time.md) describes what a
172
+ reader sees.