@moltenship/calendar 1.0.0-rc.2 → 2.0.0-beta.1

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 (70) hide show
  1. package/README.md +24 -4
  2. package/dist/index.d.mts +2 -2
  3. package/docs/accessibility.md +304 -0
  4. package/docs/agents/changes.md +449 -0
  5. package/docs/agents/coding-agents.md +117 -0
  6. package/docs/agents/connect.md +435 -0
  7. package/docs/agents/deleting.md +296 -0
  8. package/docs/agents/reference.md +512 -0
  9. package/docs/agents/server.md +317 -0
  10. package/docs/agents/webmcp.md +153 -0
  11. package/docs/agents.md +353 -0
  12. package/docs/annotations.md +196 -0
  13. package/docs/api/changes.md +248 -0
  14. package/docs/api/dnd-kit.md +267 -0
  15. package/docs/api/events.md +152 -0
  16. package/docs/api/ics.md +524 -0
  17. package/docs/api/primitives.md +168 -0
  18. package/docs/api/react.md +236 -0
  19. package/docs/api/recurrence.md +586 -0
  20. package/docs/api/solid.md +460 -0
  21. package/docs/api/store.md +92 -0
  22. package/docs/api/temporal.md +172 -0
  23. package/docs/api.md +57 -0
  24. package/docs/availability.md +573 -0
  25. package/docs/comparison.md +279 -0
  26. package/docs/concepts/anatomy.md +73 -0
  27. package/docs/concepts/events.md +164 -0
  28. package/docs/concepts/how-it-works.md +95 -0
  29. package/docs/concepts/recurrence.md +127 -0
  30. package/docs/concepts/state.md +244 -0
  31. package/docs/concepts/time.md +170 -0
  32. package/docs/guides/dnd-kit.md +333 -0
  33. package/docs/guides/google-calendar-sync.md +1246 -0
  34. package/docs/guides/google-calendar.md +367 -0
  35. package/docs/guides/ics.md +486 -0
  36. package/docs/guides/motion.md +414 -0
  37. package/docs/guides/nextjs-app-router.md +630 -0
  38. package/docs/guides/nextjs.md +149 -0
  39. package/docs/guides/performance.md +103 -0
  40. package/docs/guides/recurring-events.md +583 -0
  41. package/docs/guides/tanstack-query.md +485 -0
  42. package/docs/index.md +118 -0
  43. package/docs/installation.md +194 -0
  44. package/docs/interactions.md +408 -0
  45. package/docs/llms.txt +86 -0
  46. package/docs/migrating-to-2.md +322 -0
  47. package/docs/quick-start.md +159 -0
  48. package/docs/stylex.md +265 -0
  49. package/docs/testing.md +581 -0
  50. package/docs/theme-builder.md +81 -0
  51. package/docs/theming.md +169 -0
  52. package/docs/undo-redo.md +339 -0
  53. package/docs/views/agenda.md +221 -0
  54. package/docs/views/custom-views.md +192 -0
  55. package/docs/views/month.md +109 -0
  56. package/docs/views/resource-columns.md +261 -0
  57. package/docs/views/resource-timeline.md +225 -0
  58. package/docs/views/scrolling.md +192 -0
  59. package/docs/views/week-and-day.md +257 -0
  60. package/docs/views/year.md +138 -0
  61. package/docs/views.md +69 -0
  62. package/package.json +41 -14
  63. package/skills/moltenship-time/SKILL.md +75 -0
  64. package/skills/moltenship-time/references/agent-ready.md +272 -0
  65. package/skills/moltenship-time/references/changes.md +188 -0
  66. package/skills/moltenship-time/references/compose.md +168 -0
  67. package/skills/moltenship-time/references/mistakes.md +98 -0
  68. package/skills/moltenship-time/references/solid.md +202 -0
  69. package/skills/moltenship-time/references/state.md +129 -0
  70. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,95 @@
1
+ # How it works
2
+
3
+ The packages, and how your events become a rendered view.
4
+
5
+ Source: https://time.molten.sh/docs/concepts/how-it-works
6
+
7
+ ## Packages
8
+
9
+ ```text
10
+ @moltenship/calendar what you import: everything below
11
+ ├── @moltenship/calendar-react Root, components, hooks
12
+ │ └── @moltenship/calendar-primitives the calendar without a framework: state, actions, agents
13
+ ├── @moltenship/calendar-dnd drag, resize, and create inside views
14
+ ├── @moltenship/calendar-core adapters, validation, snapshots, queries, changes
15
+ └── @moltenship/calendar-temporal ranges, day boundaries, DST helpers
16
+ ```
17
+
18
+ `calendar-react` and `calendar-dnd` build on `calendar-core`, which builds on `calendar-temporal`.
19
+ `calendar-core` and `calendar-temporal` don't use React or the DOM, so they also run on a server
20
+ or in a worker.
21
+
22
+ Since 2.0 the calendar itself is written once, without a framework, in
23
+ `@moltenship/calendar-primitives`: the state, the actions, the pipeline from your events to a
24
+ view's projection, and what the calendar tells an [AI agent](../agents.md). It's a
25
+ [ui-sdk](https://ui-sdk.dev) primitive, and `calendar-react` renders it with `@ui-sdk/react`. That
26
+ is why `@ui-sdk/core` and `@ui-sdk/react` are peer dependencies, and how
27
+ `@moltenship/calendar-solid` renders the same calendar in SolidJS 2. Dates, time zones,
28
+ recurrence, layouts and policies stay in the calendar's own engine; ui-sdk's date components
29
+ aren't used.
30
+
31
+ Two more packages stand apart from `@moltenship/calendar`: `@moltenship/calendar-recurrence` expands
32
+ recurring events into ordinary events (it builds on core, Temporal and `ics`), and `@moltenship/ics`
33
+ parses iCalendar text with no dependencies.
34
+
35
+ | Package | Use it when |
36
+ | --------------------------------- | ----------------------------------------------------------------------------------------------------- |
37
+ | `@moltenship/calendar` | Almost always. It includes `calendar-core`, `calendar-temporal`, `calendar-react` and `calendar-dnd`. |
38
+ | `@moltenship/calendar-core` | You want to validate or query events in code that never loads React. |
39
+ | `@moltenship/calendar-temporal` | You only need the date and time zone helpers. |
40
+ | `@moltenship/calendar-react` | Rarely. `@moltenship/calendar` already includes everything in it. |
41
+ | `@moltenship/calendar-primitives` | You write a framework integration, or want the agent types. See [Primitives](../api/primitives.md). |
42
+ | `@moltenship/calendar-solid` | Your app is on SolidJS 2. A preview, without the styled views. See [Solid](../api/solid.md). |
43
+ | `@moltenship/calendar-recurrence` | Your events repeat. See [Recurring events](./recurrence.md). |
44
+ | `@moltenship/ics` | You read iCalendar feeds or files. See [ICS](../api/ics.md). |
45
+
46
+ `@moltenship/calendar` has no `"use client"` directive of its own, so a Server Component can import
47
+ its core and Temporal helpers. The React parts and the pointer layer keep their client boundary.
48
+
49
+ Import from the package name only. The packages export nothing else besides `./package.json`, so a
50
+ path such as
51
+ `@moltenship/calendar-core/src/events` doesn't resolve.
52
+
53
+ ## From events to the screen
54
+
55
+ 1. You pass `events` to `Root`.
56
+ 2. `Root` runs each record through your adapter, validates it, and builds a **snapshot**: a frozen,
57
+ indexed copy of your events.
58
+ 3. `Root` asks the active view's strategy for the visible dates, then calls its `project` function
59
+ with the snapshot. The result is the view's **projection**: the events it needs, in the shape it
60
+ needs.
61
+ 4. `ActiveView` renders the view's `Renderer` with that projection.
62
+ 5. Buttons and your own controls call actions such as `navigateNext` or `setView`. The calendar
63
+ updates uncontrolled state itself and sends controlled changes to your handlers. A new date or
64
+ view means a new range and a new projection.
65
+ 6. An [agent](../agents.md) calls the same actions through ui-sdk's agent bridge, if your app
66
+ creates one. Its changes reach the same handlers and policies, marked as an agent's.
67
+
68
+ Steps 2 and 3 only run again when their inputs change. A new array with the same records in the same
69
+ order reuses the snapshot. A changed array is read again through the adapter, except records with an
70
+ unchanged `getRevision` value; if every record comes out the same, in the same order, the interval indexes are kept.
71
+
72
+ ## Using the engine without React
73
+
74
+ Snapshots work anywhere. This finds the meetings in a time range using `calendar-core` and
75
+ `calendar-temporal` directly:
76
+
77
+ ```ts
78
+ import { createEventSnapshotCache } from "@moltenship/calendar-core";
79
+ import { instantInterval } from "@moltenship/calendar-temporal";
80
+
81
+ const snapshots = createEventSnapshotCache(eventAdapter);
82
+ const snapshot = snapshots.getSnapshot(meetings);
83
+
84
+ const morning = snapshot.queryTimed(
85
+ instantInterval(
86
+ Temporal.Instant.from("2026-10-08T06:00:00Z"),
87
+ Temporal.Instant.from("2026-10-08T10:00:00Z"),
88
+ ),
89
+ );
90
+
91
+ morning.map((meeting) => meeting.title); // ["Standup"]
92
+ ```
93
+
94
+ `eventAdapter` and `meetings` are the ones from the [Quick start](../quick-start.md). The
95
+ [snapshot reference](../api/events.md#snapshots) lists every query.
@@ -0,0 +1,127 @@
1
+ # Recurring events
2
+
3
+ Series, exceptions and overrides, how each series keeps its own time, occurrence IDs, and what "this", "following" and "all" change.
4
+
5
+ Source: https://time.molten.sh/docs/concepts/recurrence
6
+
7
+ The calendar shows events, and knows nothing about series. `@moltenship/calendar-recurrence` sits
8
+ beside it: it expands each series into its occurrences for the dates on screen, and the calendar
9
+ shows those as ordinary events. Views, drag and drop, and the event engine work the same with or
10
+ without it, and apps that don't import it pay nothing for it.
11
+
12
+ This page explains the model. [Show and edit recurring events](../guides/recurring-events.md) wires
13
+ it into a calendar, and the [API reference](../api/recurrence.md) lists every export.
14
+
15
+ ## Series
16
+
17
+ Apps store repeating events the way iCalendar, Google Calendar and Outlook do:
18
+
19
+ - **A master event**, placed at the series' first occurrence, with its recurrence: a **rule**, such
20
+ as "every weekday" (RRULE), **exception dates**, occurrences that don't happen (EXDATE), and
21
+ **extra dates**, occurrences the rule doesn't give (RDATE).
22
+ - **Overrides**: separate events that each replace one occurrence, such as a meeting moved to
23
+ another time. An override names its series and the occurrence's original start
24
+ (RECURRENCE-ID). A **cancelled** override removes the occurrence, as Google's API and ICS feeds
25
+ record a deleted one.
26
+ - **One-off events**: everything else.
27
+
28
+ ```text
29
+ Stand-up (master) Mon 19 Oct, 09:00–09:15 every weekday
30
+ exception date Wed 21 Oct, 09:00 no stand-up that day
31
+ Stand-up (override) replaces Thu 22 Oct, 09:00 at 10:00–10:15
32
+
33
+ Occurrences, 19–23 Oct: Mon 09:00, Tue 09:00, Thu 10:00, Fri 09:00
34
+ ```
35
+
36
+ Your events keep their own shape. A recurrence adapter, beside your event adapter, reads the
37
+ recurrence of a master and what an override replaces, as an
38
+ [event adapter](./events.md) reads titles and times. Series can be endless, so occurrences
39
+ exist only for the dates you expand, usually the dates the calendar shows.
40
+
41
+ ## Each series keeps its own time
42
+
43
+ Every date of a series has the kind of its first occurrence: an instant for a timed series, a date
44
+ for an all-day one, and a wall time for a floating one. That includes exception dates, extra dates,
45
+ the rule's end, and the original starts overrides name. A date of another kind converts, as real
46
+ feeds need: a date-only exception on a timed series excludes every occurrence that day, and a
47
+ date-only end lasts through that day.
48
+
49
+ A timed series repeats on the wall clock of its own time zone, the `sourceTimeZone` of its first
50
+ occurrence. So a 09:00 meeting stays at 09:00 across daylight saving time, and its instant moves by
51
+ an hour instead. A stand-up at 09:00 in Berlin is at 03:00 in New York most weeks, and at 04:00 in
52
+ the weeks between the two cities' clock changes. A floating series repeats at the same wall time in
53
+ every zone, and an all-day series on the same dates.
54
+
55
+ Some times and dates don't exist on a series' calendar:
56
+
57
+ - A start in a daylight saving gap, such as 02:30 on the night clocks go forward, moves forward by
58
+ the gap and still counts. A start the clock repeats takes its first instant.
59
+ - Dates no month has, such as 30 February or the fifth Friday of a month with four, are skipped and
60
+ don't count.
61
+ - The first occurrence is always one and counts toward the rule's COUNT, even when the rule
62
+ wouldn't give it. Occurrences an exception date removes still count.
63
+
64
+ ## Occurrence IDs
65
+
66
+ An occurrence's ID is its series' ID and its original start: `standup::2026-10-22T07:00:00Z`.
67
+ Instants are written in UTC, and dates and wall times as they are. The ID stays the same across
68
+ views, time zones and reloads, so you can store it, select it, and link to it.
69
+
70
+ An override keeps the original start of the occurrence it replaces, so an occurrence moved on its
71
+ own keeps its ID, and with it its selection and focus. An override shows under the same ID before
72
+ its master loads. One-off events keep their own IDs.
73
+
74
+ Changing the following occurrences, or all of them, changes their original starts, and so their
75
+ IDs. The edit maps old IDs to new ones, so your selection can follow; see
76
+ [Keep the selection](../guides/recurring-events.md#keep-the-selection).
77
+
78
+ ## Editing a series
79
+
80
+ When someone moves, resizes or deletes an occurrence, the app asks which events the change applies
81
+ to, then saves what that means for the series:
82
+
83
+ | Scope | A move or resize | A delete |
84
+ | ------------------------- | ------------------------------------------------------------------------ | ------------------------------- |
85
+ | This event | An override for that occurrence, or a change to its override | An exception date on the master |
86
+ | This and following events | The series ends before it, and a new series starts where it was dropped | The series ends before it |
87
+ | All events | The whole series moves or stretches by the same change, on its own clock | The master and its overrides go |
88
+
89
+ - **All events** moves the rule with the change, such as Monday to Tuesday in a weekly rule, and
90
+ moves exception dates, extra dates and the original starts overrides name, so deleted occurrences
91
+ stay deleted and moved ones don't appear twice. Overrides keep their own times.
92
+ - **This and following events** splits the series, as Google Calendar and Outlook on the web do:
93
+ later exception dates, extra dates and overrides move to the new series.
94
+ - Only scopes that can apply are offered. The first occurrence has no "This and following events",
95
+ since that's all of them, and a rule that can't follow the change, such as "the 28th of each
96
+ month" dragged to a 29th, offers only "This event".
97
+
98
+ ## While the change saves
99
+
100
+ The change stays pending, and visible, while the app asks for the scope and saves it. Cancelling
101
+ the question rolls it back.
102
+
103
+ Only the occurrence that was dragged shows the change while it's pending. The calendar keeps
104
+ pending changes per event and knows nothing about series, so the rest of a series moves once your
105
+ events change and the series is expanded again.
106
+
107
+ ## Limits
108
+
109
+ - **RANGE=THISANDFUTURE** isn't part of the model. Google Calendar and Outlook split series
110
+ instead, and the ICS bridge splits a series at such an override the same way, so Apple's "this and
111
+ future" changes show on every later occurrence. When the rule can't follow the change, as a
112
+ BYSETPOS rule moved to another day can't, the bridge reports it and the override replaces only its
113
+ own occurrence.
114
+ - **Drags use the calendar's clock.** In a time zone whose daylight saving time changes on other
115
+ dates than the series' zone, a drag, resize or editor change with "All events" or "This and
116
+ following events" moves the series by an hour more or less than the user did, unless the edit
117
+ gets the calendar's `timeZone`, which
118
+ [the guide](../guides/recurring-events.md#ask-which-events-a-change-applies-to) passes. With it,
119
+ the change is replayed on the series' clock.
120
+ - **A repeated hour.** A rule can't say "the later 02:30" of the night clocks go back, so with "All
121
+ events" a start dropped on the later of two equal wall times gets an override there, and the rest
122
+ of the series repeats at the earlier one.
123
+ - **Cancelled first occurrences.** Edits read one occurrence and its series. When cancelled overrides
124
+ hide the first occurrences, "This and following events" from the next still splits the series,
125
+ unless the edit gets the series' overrides as `overrides`.
126
+ - **The ISO calendar.** Rules repeat in the ISO calendar, iCalendar's Gregorian one: a monthly series
127
+ steps by Gregorian months even when its dates use another calendar.
@@ -0,0 +1,244 @@
1
+ # State
2
+
3
+ Let the calendar own its state, or control it from your app, one value at a time.
4
+
5
+ Source: https://time.molten.sh/docs/concepts/state
6
+
7
+ `Root` keeps six values:
8
+
9
+ | Value | Type | Meaning |
10
+ | --------------------- | ---------------------- | ------------------------------------------- |
11
+ | `view` | one of your view names | The active view |
12
+ | `anchorDate` | `Temporal.PlainDate` | The date the visible range is built around |
13
+ | `timeZone` | `string` (IANA name) | The zone timed events are shown in |
14
+ | `selection` | your type, or `null` | What the user selected |
15
+ | `focus` | your type, or `null` | What has keyboard focus inside the calendar |
16
+ | `expandedResourceIds` | array of resource IDs | Which resource groups are expanded |
17
+
18
+ Each value can be **uncontrolled** (the calendar owns it) or **controlled** (your app owns it),
19
+ independently of the others.
20
+
21
+ ## Uncontrolled
22
+
23
+ Pass a `default` prop and the calendar manages the value from then on. Defaults are read once, when
24
+ `Root` mounts.
25
+
26
+ ```tsx
27
+ <Calendar.Root
28
+ events={meetings}
29
+ defaultView="day"
30
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
31
+ defaultTimeZone="Europe/Berlin"
32
+ locale="en-US"
33
+ weekRules={weekRules}
34
+ >
35
+ <Calendar.ActiveView />
36
+ </Calendar.Root>
37
+ ```
38
+
39
+ ## Controlled
40
+
41
+ Pass the value and a change handler. The calendar never changes a controlled value itself. When the
42
+ user clicks Next, it calls your handler with the new value, and you decide whether to store it.
43
+
44
+ This example controls the date so a date input outside the calendar stays in sync. It uses the
45
+ `Calendar` from the [Quick start](../quick-start.md).
46
+
47
+ ```tsx title="controlled-state.tsx"
48
+ export function ControlledCalendar() {
49
+ const [anchorDate, setAnchorDate] = useState(() => Temporal.PlainDate.from("2026-10-08"));
50
+
51
+ return (
52
+ <>
53
+ <input
54
+ type="date"
55
+ value={anchorDate.toString()}
56
+ onChange={(event) => {
57
+ if (event.currentTarget.value) {
58
+ setAnchorDate(Temporal.PlainDate.from(event.currentTarget.value));
59
+ }
60
+ }}
61
+ />
62
+ <Calendar.Root
63
+ events={meetings}
64
+ anchorDate={anchorDate}
65
+ onAnchorDateChange={setAnchorDate}
66
+ defaultTimeZone="Europe/Berlin"
67
+ locale="en-US"
68
+ weekRules={weekRules}
69
+ >
70
+ <Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
71
+ <Calendar.NextTrigger>Next</Calendar.NextTrigger>
72
+ <NextWeekButton />
73
+ <Calendar.ActiveView />
74
+ </Calendar.Root>
75
+ </>
76
+ );
77
+ }
78
+ ```
79
+
80
+ The props follow one pattern:
81
+
82
+ | Uncontrolled | Controlled | Handler |
83
+ | ---------------------------- | --------------------- | ----------------------------- |
84
+ | `defaultView` | `view` | `onViewChange` |
85
+ | `defaultAnchorDate` | `anchorDate` | `onAnchorDateChange` |
86
+ | `defaultTimeZone` | `timeZone` | `onTimeZoneChange` |
87
+ | `defaultSelection` | `selection` | `onSelectionChange` |
88
+ | `defaultFocus` | `focus` | `onFocusChange` |
89
+ | `defaultExpandedResourceIds` | `expandedResourceIds` | `onExpandedResourceIdsChange` |
90
+
91
+ A few rules:
92
+
93
+ - `undefined` means uncontrolled. To control `selection` or `focus` with nothing selected, pass
94
+ `null`.
95
+ - Handlers also run for uncontrolled values, after the calendar updates them. The second argument
96
+ says what changed, why, and who asked. See [what a handler hears](#what-a-handler-hears).
97
+ - If you haven't applied a change the calendar asked for, the handler also hears a later request
98
+ for the value you have. For example, Today after a scroll you deferred. Apply the latest value
99
+ you were given, and you'll drop the earlier change.
100
+ - `Root` needs a date, a time zone, and a view on its first render. The view can come from
101
+ `defaultView`, `view`, or the first registered view. If one is missing, `Root` throws
102
+ `calendar-root-requires-anchor-date`, `calendar-root-requires-time-zone`, or
103
+ `calendar-root-requires-view`.
104
+
105
+ ## What a handler hears
106
+
107
+ Every change handler gets the new value and a detail:
108
+
109
+ | Field | Type | Meaning |
110
+ | ------------ | ------------------ | ----------------------------------------------------------------------------- |
111
+ | `slice` | `string` | Which value changed, such as `"view"` or `"anchorDate"` |
112
+ | `previous` | the value's type | The value before the change |
113
+ | `controlled` | `boolean` | Whether a prop controls the value |
114
+ | `reason` | `string` | Why it changed. See below |
115
+ | `source` | `string` | Who caused it. See below |
116
+ | `event` | `Event`, or absent | The DOM event behind it, such as a button's click. Absent for code and agents |
117
+ | `cancel()` | function | Stops the change. An uncontrolled value goes back to `previous` |
118
+ | `canceled` | `boolean` | Whether `cancel()` was called |
119
+
120
+ `reason` is one of:
121
+
122
+ - `"next-press"`, `"previous-press"` or `"today-press"`: a press of `Calendar.NextTrigger`,
123
+ `Calendar.PreviousTrigger` or `Calendar.TodayTrigger`.
124
+ - `"input-change"`: a choice in `Calendar.ViewSwitcher`.
125
+ - `"keyboard-navigation"`: a key in a view that moves focus or the visible range, such as an
126
+ arrow key or Page Down.
127
+ - `"focus-change"`: focus a person moved onto a cell or an event, by clicking it or tabbing to it.
128
+ - `"resource-toggle"`: a resource expanded or collapsed.
129
+ - `"imperative"`: an action called from code, such as `actions.setView("month")`. It's also the
130
+ reason for anything an [agent](../agents.md) does.
131
+
132
+ `source` is one of `"mouse"`, `"touch"`, `"pen"`, `"keyboard"`, `"virtual"`, `"agent"` or
133
+ `"programmatic"`. `"keyboard"` is a person's keys, on a toolbar button and in a view: arrow-key
134
+ navigation, moving focus and expanding a resource report it. `"virtual"` is a click with no
135
+ pointer or key behind it, which may come from assistive technology. `"agent"` is an AI agent
136
+ acting through the [agent bridge](../agents/connect.md), and anything its step causes.
137
+ `"programmatic"` is your own code.
138
+
139
+ This calendar records how people navigate and keeps agents out of the month view. It uses the
140
+ `Calendar`, `meetings` and `weekRules` from the [Quick start](../quick-start.md):
141
+
142
+ ```tsx title="tracked-calendar.tsx"
143
+ "use client";
144
+
145
+ import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
146
+
147
+ import { Calendar, meetings, weekRules } from "./calendar";
148
+
149
+ /** Records how the calendar is navigated, and keeps the month view for people. */
150
+ export function TrackedCalendar({ track }: { readonly track: (entry: string) => void }) {
151
+ return (
152
+ <Calendar.Root
153
+ label="Team calendar"
154
+ events={meetings}
155
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
156
+ defaultTimeZone="Europe/Berlin"
157
+ locale="en-US"
158
+ weekRules={weekRules}
159
+ onAnchorDateChange={(date, detail) => {
160
+ // "next-press by mouse to 2026-10-15", "imperative by agent to 2026-11-02"
161
+ track(`${detail.reason} by ${detail.source} to ${date.toString()}`);
162
+ }}
163
+ onViewChange={(view, detail) => {
164
+ if (view === "month" && detail.source === "agent") detail.cancel();
165
+ }}
166
+ >
167
+ <Calendar.Frame className="flex h-[640px] flex-col rounded-xl border">
168
+ <CalendarToolbar calendar={Calendar} />
169
+ <Calendar.Viewport className="min-h-0 flex-1">
170
+ <Calendar.ActiveView />
171
+ </Calendar.Viewport>
172
+ </Calendar.Frame>
173
+ </Calendar.Root>
174
+ );
175
+ }
176
+ ```
177
+
178
+ `cancel()` puts an uncontrolled value back as it was. For a controlled value it does nothing you
179
+ couldn't do yourself: the value changes only when you store it.
180
+
181
+ An action you call can say why and who. Pass the DOM event that led to it, and the calendar works
182
+ out the `source`:
183
+
184
+ ```tsx
185
+ <button onClick={(event) => actions.navigateNext({ event: event.nativeEvent })}>Next</button>
186
+ ```
187
+
188
+ Every action takes the same options as its last argument: `{ event?, reason?, source? }`.
189
+ Without them, a call from your code reads `reason: "imperative"` and `source: "programmatic"`.
190
+
191
+ ## Reading and changing state
192
+
193
+ Any component inside `Root` can use the hooks on your calendar:
194
+
195
+ - `useCalendarState()` returns all six values.
196
+ - `useCalendarSelector(selector)` returns one derived value and re-renders only when it changes.
197
+ - `useCalendarActions()` returns `setView`, `setAnchorDate`, `setTimeZone`, `setSelection`,
198
+ `setFocus`, `setExpandedResourceIds`, `navigateNext`, `navigatePrevious`, `navigateToday`,
199
+ `proposeEventChange`, and `checkEventChange`.
200
+ - `useCalendarMeta()` returns everything else: the event snapshot, resources, the environment, the
201
+ active view and the registered views, diagnostics, the instance ID, and element IDs and refs.
202
+ - `useCalendar()` returns `state`, `actions`, and `meta` together.
203
+ - `useVisibleRange()` and `useViewProjection()` return what the active view shows. See
204
+ [Custom views](../views/custom-views.md#reading-the-view-from-other-components).
205
+
206
+ ```tsx title="controlled-state.tsx"
207
+ const selectAnchorDate = (state: CalendarPublicState) => state.anchorDate;
208
+
209
+ function NextWeekButton() {
210
+ const anchorDate = Calendar.useCalendarSelector(selectAnchorDate);
211
+ const actions = Calendar.useCalendarActions();
212
+
213
+ return (
214
+ <button type="button" onClick={() => actions.setAnchorDate(anchorDate.add({ weeks: 1 }))}>
215
+ Skip a week
216
+ </button>
217
+ );
218
+ }
219
+ ```
220
+
221
+ A selector can live outside the component, as above, or inline. Actions called one after another
222
+ build on each other, so `navigateNext()` twice in one click moves two steps, controlled or not.
223
+
224
+ ## Selection and focus types
225
+
226
+ You choose the shape of `selection` and `focus`. Pass their types as the third and fourth type
227
+ arguments of `createCalendar`, after the event and resource types. Time stores the values as they
228
+ are.
229
+
230
+ ```tsx title="selection.tsx"
231
+ type Selection = { readonly eventId: string } | { readonly date: Temporal.PlainDate };
232
+
233
+ const Calendar = createCalendar<Meeting, never, Selection>()({ eventAdapter });
234
+
235
+ export function SelectStandup() {
236
+ const actions = Calendar.useCalendarActions();
237
+
238
+ return (
239
+ <button type="button" onClick={() => actions.setSelection({ eventId: "standup" })}>
240
+ Select standup
241
+ </button>
242
+ );
243
+ }
244
+ ```
@@ -0,0 +1,170 @@
1
+ # Time and time zones
2
+
3
+ Timed, all-day, and floating events, exclusive end times, and daylight saving time.
4
+
5
+ Source: https://time.molten.sh/docs/concepts/time
6
+
7
+ Time uses the
8
+ [Temporal API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal)
9
+ for every date and time. There are no `Date` objects or millisecond timestamps in the API, so a
10
+ date never shifts by a day because of a hidden time zone conversion.
11
+
12
+ ## Three kinds of events
13
+
14
+ ```ts
15
+ // A call at 15:00 UTC. Shown at 17:00 in Berlin and 11:00 in New York.
16
+ const call = {
17
+ kind: "timed",
18
+ start: Temporal.Instant.from("2026-10-08T15:00:00Z"),
19
+ end: Temporal.Instant.from("2026-10-08T16:00:00Z"),
20
+ };
21
+
22
+ // A public holiday. October 3 in every time zone.
23
+ const holiday = {
24
+ kind: "all-day",
25
+ start: Temporal.PlainDate.from("2026-10-03"),
26
+ end: Temporal.PlainDate.from("2026-10-04"),
27
+ };
28
+
29
+ // Gym at 07:00, in whatever time zone you're in that day.
30
+ const gym = {
31
+ kind: "floating",
32
+ start: Temporal.PlainDateTime.from("2026-10-08T07:00"),
33
+ end: Temporal.PlainDateTime.from("2026-10-08T08:00"),
34
+ };
35
+ ```
36
+
37
+ - **Timed** events happen at an exact moment. Time converts them to the calendar's time zone for
38
+ display.
39
+ - **All-day** events cover whole dates and ignore time zones.
40
+ - **Floating** events have a wall-clock time but no time zone. They show at the same clock time
41
+ whichever zone the calendar uses.
42
+
43
+ A timed range can also carry `sourceTimeZone`, the zone the event was created in. Time keeps it on
44
+ the event for your views to use; display still uses the calendar's zone.
45
+
46
+ ## End times are exclusive
47
+
48
+ Every range includes its start and excludes its end. This is often written `[start, end)`.
49
+
50
+ - A 9:00–10:00 meeting and a 10:00–11:00 meeting don't overlap.
51
+ - A one-day all-day event on October 3 ends on October 4.
52
+ - An all-day event covering October 3 and 4 ends on October 5.
53
+
54
+ The start must be strictly before the end. Zero-length and reversed ranges are
55
+ [reported as invalid](./events.md#invalid-records).
56
+
57
+ ## The calendar's time zone
58
+
59
+ `Root` takes an IANA time zone name, either as `defaultTimeZone` or as a controlled `timeZone`. Time
60
+ doesn't read the browser's or the server's zone. You choose it, typically from user settings.
61
+
62
+ ```tsx
63
+ const actions = Calendar.useCalendarActions();
64
+
65
+ actions.setTimeZone("America/New_York");
66
+ ```
67
+
68
+ Changing the zone moves timed events to their new local times. All-day and floating events stay
69
+ where they are.
70
+
71
+ To use the visitor's own zone, read `Temporal.Now.timeZoneId()` in the browser. If you render on the
72
+ server, store the zone with the user or pass it from the client after hydration, so the server and
73
+ the browser render the same thing. See [Next.js and server rendering](../guides/nextjs.md).
74
+
75
+ ## Secondary time zones
76
+
77
+ `secondaryTimeZones` on `Root` adds other zones that time grids label their hours in. Events still
78
+ show in the calendar's own zone. Pass IANA names, or `{ timeZone, label }` to name a zone yourself:
79
+
80
+ ```tsx
81
+ <Calendar.Root timeZone="Europe/Berlin" secondaryTimeZones={["Asia/Tokyo"]} />
82
+ ```
83
+
84
+ Time reads each hour line on its own date: it resolves the wall time in the calendar's zone, then
85
+ converts that moment to the other zone. It never adds a fixed offset, so the labels are right on
86
+ the days either zone changes its clocks, and for zones such as Australia/Lord_Howe, whose clocks
87
+ move by 30 minutes. Like `timeZone`, the list is an explicit input, so the server and the browser
88
+ render the same labels. Invalid zones are left out and reported as
89
+ [diagnostics](../api/react.md#diagnostics).
90
+
91
+ A grid has one hour gutter for all its days, so the gutter follows one of them: the first day shown
92
+ on which neither zone changes its clocks. The days whose lines read differently, because a zone
93
+ changed its offset, are listed as shifts: runs of lines, each with how many minutes it differs by.
94
+
95
+ Views get the list as `environment.secondaryTimeZones`. In your own view,
96
+ `timeGridZoneAxis(columns, timeZone)` returns each line's time in another zone and the shifts.
97
+ Pass `{ visible }` when the view renders days beside the ones on screen, so the gutter follows a
98
+ day you can see. `timeGridZoneTimes(column, wallTime, timeZone)` reads one wall time. The
99
+ [week and day views](../views/week-and-day.md#secondary-time-zones) show the zones as extra hour
100
+ columns.
101
+
102
+ ## Daylight saving time
103
+
104
+ Not every day has 24 hours. In Berlin, March 29, 2026 has 23 hours and October 25, 2026 has 25:
105
+
106
+ ```ts
107
+ Temporal.PlainDate.from("2026-03-29").toZonedDateTime("Europe/Berlin").hoursInDay; // 23
108
+ Temporal.PlainDate.from("2026-10-25").toZonedDateTime("Europe/Berlin").hoursInDay; // 25
109
+ ```
110
+
111
+ So some wall-clock times never happen (02:30 on March 29) and some happen twice (02:30 on
112
+ October 25). Temporal's `disambiguation` option decides which moment such a time means:
113
+
114
+ | Value | Skipped time (gap) | Repeated time (fold) |
115
+ | ------------------------ | ------------------------ | --------------------- |
116
+ | `"compatible"` (default) | Moves later by the gap | The earlier one |
117
+ | `"earlier"` | Moves earlier by the gap | The earlier one |
118
+ | `"later"` | Moves later by the gap | The later one |
119
+ | `"reject"` | Throws a `RangeError` | Throws a `RangeError` |
120
+
121
+ ```ts
122
+ Temporal.PlainDateTime.from("2026-03-29T02:30")
123
+ .toZonedDateTime("Europe/Berlin", { disambiguation: "compatible" })
124
+ .toString(); // "2026-03-29T03:30:00+02:00[Europe/Berlin]"
125
+ ```
126
+
127
+ `Root`'s `disambiguation` prop takes the same values (default `"compatible"`) and gives the setting
128
+ to views as `environment.disambiguation`. The built-in views and interactions don't read it; use it
129
+ in your own view when you turn a wall-clock time into an instant. When you build a view, these
130
+ helpers from
131
+ `@moltenship/calendar` already account for these days:
132
+
133
+ - `zonedDayRange(date, timeZone)` returns the real start and end of a day, 23 or 25 hours long when
134
+ needed.
135
+ - `slotsInZonedDay(date, options)` splits a day into time slots and marks skipped and repeated hours.
136
+ - `resolveZonedWallTime(wallTime, { timeZone, disambiguation })` tells you how a wall-clock time
137
+ resolved, including how far it moved.
138
+
139
+ See the [Temporal helpers reference](../api/temporal.md).
140
+
141
+ ## The current time
142
+
143
+ Time reads the current time from one of three places, in this order:
144
+
145
+ - `now` on `Root`: a fixed `Temporal.Instant`. Use it when you render on the server, so the server
146
+ and the browser agree on "today".
147
+ - `clock` on `Root`: an object with an `instant()` method, for a value you control, such as a fake
148
+ clock in tests. Define it once at module scope.
149
+ - The system clock, when you pass neither.
150
+
151
+ Without `now`, nothing that depends on the current time renders on the server: a view's `today` is
152
+ `null` and `useNow()` returns `null` until the page has hydrated. The Today button always works; it
153
+ reads the clock when it's clicked.
154
+
155
+ `useNow()` gives a component the current instant, for example to draw a line at the current time.
156
+ It re-renders every `intervalMs` (one minute by default). This one uses the `Calendar` from the
157
+ [Quick start](../quick-start.md):
158
+
159
+ ```tsx
160
+ import { useNow } from "@moltenship/calendar";
161
+
162
+ function CurrentTime() {
163
+ const now = useNow({ intervalMs: 30_000 });
164
+ const { timeZone } = Calendar.useCalendarState();
165
+ if (now === null) return null;
166
+
167
+ const time = now.toZonedDateTimeISO(timeZone).toPlainTime();
168
+ return <time dateTime={now.toString()}>{time.toString({ smallestUnit: "minute" })}</time>;
169
+ }
170
+ ```