@moltenship/calendar 2.0.0-beta.1 → 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 (75) hide show
  1. package/README.md +11 -10
  2. package/dist/index.d.mts +2 -2
  3. package/dist/index.mjs +2 -2
  4. package/docs/accessibility.md +5 -4
  5. package/docs/agents/changes.md +3 -3
  6. package/docs/agents/coding-agents.md +19 -20
  7. package/docs/agents/connect.md +20 -11
  8. package/docs/agents/deleting.md +2 -2
  9. package/docs/agents/reference.md +5 -6
  10. package/docs/agents/server.md +4 -4
  11. package/docs/agents/webmcp.md +2 -2
  12. package/docs/agents.md +10 -8
  13. package/docs/annotations.md +10 -8
  14. package/docs/api/changes.md +37 -21
  15. package/docs/api/{react.md → components.md} +65 -56
  16. package/docs/api/dnd-kit.md +1 -3
  17. package/docs/api/events.md +14 -13
  18. package/docs/api/primitives.md +61 -11
  19. package/docs/api/store.md +3 -3
  20. package/docs/api.md +23 -23
  21. package/docs/availability.md +25 -22
  22. package/docs/comparison.md +23 -24
  23. package/docs/concepts/anatomy.md +3 -3
  24. package/docs/concepts/events.md +2 -3
  25. package/docs/concepts/how-it-works.md +33 -16
  26. package/docs/concepts/state.md +1 -1
  27. package/docs/concepts/time.md +5 -7
  28. package/docs/customization.md +271 -0
  29. package/docs/frameworks.md +116 -0
  30. package/docs/guides/dnd-kit.md +2 -2
  31. package/docs/guides/google-calendar-sync.md +3 -3
  32. package/docs/guides/google-calendar.md +4 -4
  33. package/docs/guides/motion.md +2 -2
  34. package/docs/guides/nextjs-app-router.md +1 -1
  35. package/docs/guides/nextjs.md +1 -1
  36. package/docs/guides/performance.md +6 -6
  37. package/docs/guides/tanstack-query.md +2 -2
  38. package/docs/{guides/ics.md → ics/feed.md} +7 -9
  39. package/docs/ics/import.md +183 -0
  40. package/docs/{api/ics.md → ics/reference.md} +11 -53
  41. package/docs/ics.md +142 -0
  42. package/docs/index.md +81 -50
  43. package/docs/installation.md +48 -33
  44. package/docs/interactions.md +36 -3
  45. package/docs/llms.txt +81 -68
  46. package/docs/migrating-to-2.md +200 -25
  47. package/docs/quick-start.md +27 -23
  48. package/docs/{guides/recurring-events.md → recurrence/calendar.md} +23 -8
  49. package/docs/{concepts/recurrence.md → recurrence/model.md} +13 -12
  50. package/docs/{api/recurrence.md → recurrence/reference.md} +22 -61
  51. package/docs/recurrence.md +122 -0
  52. package/docs/stylex.md +74 -49
  53. package/docs/temporal/daylight-saving-time.md +172 -0
  54. package/docs/temporal/month-grid.md +119 -0
  55. package/docs/{api/temporal.md → temporal/reference.md} +7 -12
  56. package/docs/temporal.md +105 -0
  57. package/docs/testing.md +20 -1
  58. package/docs/theme-builder.md +9 -8
  59. package/docs/theming.md +108 -2
  60. package/docs/undo-redo.md +24 -16
  61. package/docs/views/agenda.md +14 -13
  62. package/docs/views/custom-views.md +13 -10
  63. package/docs/views/month.md +10 -9
  64. package/docs/views/resource-columns.md +21 -17
  65. package/docs/views/resource-timeline.md +16 -15
  66. package/docs/views/scrolling.md +7 -6
  67. package/docs/views/week-and-day.md +15 -14
  68. package/docs/views/year.md +11 -11
  69. package/docs/views.md +1 -1
  70. package/package.json +7 -6
  71. package/skills/moltenship-time/SKILL.md +7 -5
  72. package/skills/moltenship-time/references/compose.md +13 -6
  73. package/skills/moltenship-time/references/mistakes.md +4 -2
  74. package/skills/moltenship-time/references/solid.md +36 -25
  75. package/docs/api/solid.md +0 -460
@@ -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 CHANGED
@@ -1,26 +1,32 @@
1
1
  # StyleX
2
2
 
3
- The calendar's views styled with StyleX and Astryx, for apps without Tailwind.
3
+ The calendar's views styled with StyleX, for apps without Tailwind.
4
4
 
5
- Source: https://time.molten.sh/docs/stylex
5
+ Source: https://time.molten.sh/docs/react/stylex
6
6
 
7
- The registry's baseline is Tailwind and shadcn/ui. If your app styles with
8
- [StyleX](https://stylexjs.com) and builds on [Astryx](https://astryx.atmeta.com), Meta's design
9
- system, use the `stylex-*` items instead. They hold the same components with the same behaviour,
10
- every view included: same file names, exports, `data-slot` attributes, roles and labels. Styles are
11
- `stylex.create` rather than Tailwind classes, and buttons, tooltips and the like come from Astryx
12
- rather than shadcn/ui. As with the baseline, you own the source you add.
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.
13
19
 
14
20
  See it running on the demo's [StyleX page](https://moltenship-time-demo.vercel.app/stylex/).
15
21
 
16
22
  ## Install
17
23
 
18
24
  ```bash
19
- npm install @stylexjs/stylex @astryxdesign/core @astryxdesign/theme-neutral
25
+ npm install @stylexjs/stylex
20
26
  npm install --save-dev @stylexjs/unplugin
21
27
  ```
22
28
 
23
- `@moltenship/calendar` comes with the items, as [UI source](./installation.md#ui-source-optional)
29
+ `@moltenship/calendar`, `@ui-sdk/react` and `lucide-react` come with the items, as [UI source](./installation.md#ui-source-optional)
24
30
  describes, and [Temporal](./installation.md#temporal) needs the same setup as in any app.
25
31
 
26
32
  ## Configure Vite
@@ -56,46 +62,39 @@ export default defineConfig(({ command }) => ({
56
62
  - `aliases` and `unstable_moduleResolution` let StyleX find the tokens file. The items import it as
57
63
  `@/components/calendar-stylex/calendar-tokens.stylex`, and StyleX reads it at compile time. Vite's
58
64
  own alias doesn't reach the StyleX compiler, so it needs both.
59
- - `lightningcssOptions.targets` and `build.cssTarget` name browsers that have `light-dark()`. Astryx
60
- and the calendar's tokens rely on it for dark mode. With older targets it's lowered to a polyfill
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
61
67
  that needs `color-scheme` in the same stylesheet, and dark colors break without an error.
62
68
 
63
69
  ## Add the global CSS
64
70
 
65
- Declare the layers first, then import the stylesheets. `calendar-global.css` holds the few rules
66
- StyleX can't write, such as those for drag previews, and arrives with the items.
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:
67
75
 
68
76
  ```css title="styles.css"
69
- @layer reset, astryx-base, astryx-theme;
70
- @import "@astryxdesign/core/reset.css";
71
- @import "@astryxdesign/core/astryx.css";
72
- @import "@astryxdesign/theme-neutral/theme.css";
77
+ @layer ui-sdk;
73
78
  @import "@/components/calendar-stylex/calendar-global.css";
74
- ```
75
-
76
- Wrap your app in Astryx's `Theme`. It sets the root's `color-scheme`, which `light-dark()` follows:
77
-
78
- ```tsx title="main.tsx"
79
- import { Theme } from "@astryxdesign/core/theme";
80
- import { neutralTheme } from "@astryxdesign/theme-neutral/built";
81
-
82
- import "./styles.css";
83
79
 
84
- <Theme theme={neutralTheme}>
85
- <App />
86
- </Theme>;
80
+ :root {
81
+ color-scheme: light dark;
82
+ }
87
83
  ```
88
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
+
89
88
  ## Add the items
90
89
 
91
90
  `shadcn add` needs a `components.json` to know your aliases, even in an app without Tailwind, and
92
91
  your `tsconfig.json` needs the `@/*` path. The schema requires the `tailwind` block, but these items
93
- don't read it, and adding them leaves your CSS as it is:
92
+ don't read it or `style`, and adding them leaves your CSS as it is:
94
93
 
95
94
  ```json title="components.json"
96
95
  {
97
96
  "$schema": "https://ui.shadcn.com/schema.json",
98
- "style": "base-nova",
97
+ "style": "new-york",
99
98
  "rsc": false,
100
99
  "tsx": true,
101
100
  "tailwind": { "css": "src/styles.css", "baseColor": "neutral", "cssVariables": true },
@@ -109,7 +108,7 @@ don't read it, and adding them leaves your CSS as it is:
109
108
  }
110
109
  ```
111
110
 
112
- `stylex-calendar-full` installs every view, the tokens and the parts they share:
111
+ `stylex-calendar-full` installs every view, the tokens, the controls and the parts they share:
113
112
 
114
113
  ```bash
115
114
  npx shadcn@latest add https://time.molten.sh/r/stylex-calendar-full.json
@@ -122,8 +121,8 @@ Or add one view, which brings what it builds on. Every item in the
122
121
  npx shadcn@latest add https://time.molten.sh/r/stylex-month-view.json
123
122
  ```
124
123
 
125
- The files land in `calendar-stylex/` under your `components` alias, so they never overwrite the
126
- Tailwind ones.
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.
127
126
 
128
127
  ## Use the views
129
128
 
@@ -196,22 +195,45 @@ const calendarTheme = stylex.createTheme(calendarVars, {
196
195
  </div>;
197
196
  ```
198
197
 
199
- The base colors, such as `--background` and `--primary`, read the tokens of the root Astryx theme, so
200
- a theme of yours flows in with no change here. They fall back to the values of `calendar-theme.css`
201
- without one.
202
-
203
198
  Tokens are resolved where they're declared, on `:root`. So a wrapper that overrides `--primary`
204
199
  doesn't change `--calendar-event-border`, which reads `var(--primary)`: restate it in the same
205
200
  theme. The [Theme builder](./theme-builder.md#use-the-stylex-theme) does this for you, and lets you
206
201
  try a theme and copy it.
207
202
 
208
- Popovers and tooltips open in a portal under `<body>`, outside a wrapper. To theme them too, put the
209
- theme's class on `<body>`, or pass your wrapper to the portal's `container` in the source you own.
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.
210
205
 
211
206
  `--calendar-surface` is no token. It's unset, and the views read it through a constant, for a
212
207
  container with its own background to set in an inline `style`, as on
213
208
  [Theming](./theming.md#changing-tokens).
214
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
+
215
237
  ## Override a component's styles
216
238
 
217
239
  The components take `xstyle` beside `className` and `style`, for styles of your own. They win over
@@ -225,6 +247,10 @@ const styles = stylex.create({
225
247
  <CalendarToolbar calendar={Calendar} xstyle={styles.toolbar} />;
226
248
  ```
227
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
+
228
254
  ## Event colors
229
255
 
230
256
  Views take `getEventColor`, and the names are the same nine, as in
@@ -246,17 +272,16 @@ name to `event-colors.ts`, its tokens to `calendar-tokens.stylex.ts`, and an ent
246
272
 
247
273
  ## Next.js
248
274
 
249
- The demo and CI exercise this flavour under Vite, and not under Next.js. Astryx's
250
- [`example-nextjs-stylex`](https://github.com/meta/astryx/tree/main/apps/example-nextjs-stylex) shows
251
- the setup for Next.js: `@stylexjs/babel-plugin` in `babel.config.js` with the `@/*` alias, and
252
- `@stylexjs/postcss-plugin` with `useCSSLayers.before` naming Astryx's layers, with `@stylex;` at the
253
- end of the global CSS.
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/).
254
279
 
255
280
  ## What's different from the baseline
256
281
 
257
- - Base UI stays, unstyled, under the parts that need its focus handling or anchoring where Astryx has
258
- no equal: the recurrence scope dialog, the undo toast, the year view's day popover, and some
259
- tooltips and popovers in the views. An item lists `@base-ui/react` when it uses it.
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.
260
285
  - StyleX's classes have the same specificity as a global `[data-slot]` rule, and come after your
261
286
  CSS. So a rule of yours that sets a property a view's styles also set, such as an
262
287
  [Availability](./availability.md) recipe's background color, needs a stronger selector:
@@ -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.
@@ -0,0 +1,119 @@
1
+ # Build a month grid
2
+
3
+ Lay out the weeks of a month with monthGrid, weekRange and iteratePlainDates, for a date picker or a view of your own.
4
+
5
+ Source: https://time.molten.sh/docs/react/temporal/month-grid
6
+
7
+ A month grid needs three answers: which date the first row starts on, how many rows there are,
8
+ and which days belong to the months before and after. `monthGrid` gives all three for any date and
9
+ any first day of the week. This page builds the grid as data. It imports no UI framework, so the
10
+ same rows feed a date picker, a view or a printed report.
11
+
12
+ ## The rows
13
+
14
+ `monthGrid(date, { weekStartsOn })` returns the month's first day as `month`, the whole visible
15
+ range as `range`, and one seven-day range per row as `weeks`. `iteratePlainDates` steps through a
16
+ range one date at a time and leaves the range's end out:
17
+
18
+ ```ts title="month-grid.ts"
19
+ import {
20
+ iteratePlainDates,
21
+ monthGrid,
22
+ weekRange,
23
+ type WeekStartsOn,
24
+ } from "@moltenship/calendar-temporal";
25
+
26
+ export interface GridDay {
27
+ readonly date: Temporal.PlainDate;
28
+ /** False for the days of the months before and after, which fill the first and last rows. */
29
+ readonly inMonth: boolean;
30
+ }
31
+
32
+ /** The rows of a month grid: one array of seven days for each week. */
33
+ export function monthRows(date: Temporal.PlainDate, weekStartsOn: WeekStartsOn): GridDay[][] {
34
+ const grid = monthGrid(date, { weekStartsOn });
35
+ return grid.weeks.map((week) =>
36
+ Array.from(iteratePlainDates(week), (day) => ({
37
+ date: day,
38
+ inMonth: day.year === grid.month.year && day.month === grid.month.month,
39
+ })),
40
+ );
41
+ }
42
+ ```
43
+
44
+ `weekStartsOn` is an ISO day number: 1 is Monday and 7 is Sunday. The function takes it as an
45
+ argument and reads no locale, so pass the first day your app uses.
46
+
47
+ A grid has four to six rows. February 2027 starts on a Monday and has 28 days, so with weeks that
48
+ start on Monday it has four. August 2026 has six.
49
+
50
+ ## The weekday names
51
+
52
+ The names above the columns come from any week that starts on the same day. `weekRange` returns
53
+ the seven-day range around a date:
54
+
55
+ ```ts title="month-grid.ts"
56
+ /** The names above the columns, starting on the grid's first weekday. */
57
+ export function weekdayNames(weekStartsOn: WeekStartsOn, locale: string): string[] {
58
+ // Any week has the seven weekdays in the grid's order.
59
+ const week = weekRange(Temporal.PlainDate.from("2026-01-01"), { weekStartsOn });
60
+ return Array.from(iteratePlainDates(week), (day) =>
61
+ day.toLocaleString(locale, { weekday: "short" }),
62
+ );
63
+ }
64
+ ```
65
+
66
+ ## Draw it
67
+
68
+ A component maps over the rows. This function writes them as text, which shows the layout without
69
+ a framework:
70
+
71
+ ```ts title="month-grid.ts"
72
+ /** The grid as text, with the days of other months left blank. */
73
+ export function monthText(date: Temporal.PlainDate, weekStartsOn: WeekStartsOn): string {
74
+ const cell = (text: string) => text.slice(0, 2).padStart(2);
75
+ const rows = monthRows(date, weekStartsOn).map((row) =>
76
+ row.map((day) => cell(day.inMonth ? `${day.date.day}` : "")).join(" "),
77
+ );
78
+ return [weekdayNames(weekStartsOn, "en-US").map(cell).join(" "), ...rows].join("\n");
79
+ }
80
+ ```
81
+
82
+ `monthText(Temporal.PlainDate.from("2026-10-08"), 1)` returns:
83
+
84
+ ```text
85
+ Mo Tu We Th Fr Sa Su
86
+ 1 2 3 4
87
+ 5 6 7 8 9 10 11
88
+ 12 13 14 15 16 17 18
89
+ 19 20 21 22 23 24 25
90
+ 26 27 28 29 30 31
91
+ ```
92
+
93
+ The first row starts on September 28. Those three days are in the grid with `inMonth` false, so a
94
+ component can draw them dimmed, and this function leaves them blank.
95
+
96
+ ## Six rows every month
97
+
98
+ A grid that changes height as the reader moves through the year makes the page jump. Pass
99
+ `fixedWeeks: true` for six rows in every month:
100
+
101
+ ```ts title="month-grid.ts"
102
+ /** Six rows for every month, so a grid keeps its height as the reader moves through the year. */
103
+ export function sixWeeks(date: Temporal.PlainDate, weekStartsOn: WeekStartsOn) {
104
+ return monthGrid(date, { weekStartsOn, fixedWeeks: true });
105
+ }
106
+ ```
107
+
108
+ For February 2027 the fixed grid runs to March 15, two rows into March.
109
+
110
+ ## Find the events in the grid
111
+
112
+ `grid.range` is the range of dates to load events for. It includes the days of the months around
113
+ the month, since the grid shows them. For events stored as instants, turn the range's dates into
114
+ instants in the viewer's time zone with `zonedDayRange`, as
115
+ [Handle daylight saving time](./daylight-saving-time.md#which-events-are-on-a-date) shows.
116
+
117
+ The calendar's own month view does this for you. Its strategy calls `projectMonth`, which lays out
118
+ events on these rows with their lanes and overflow: see [Month view](../views/month.md) and
119
+ [Custom views](../views/custom-views.md).
@@ -1,18 +1,13 @@
1
- # Temporal helpers
1
+ # API reference
2
2
 
3
- Ranges, date and time grids, rounding, day boundaries, and DST from @moltenship/calendar-temporal.
3
+ Everything @moltenship/calendar-temporal exports. Ranges, date and time grids, rounding, day boundaries, daylight saving time, keys and clocks.
4
4
 
5
- Source: https://time.molten.sh/docs/api/temporal
5
+ Source: https://time.molten.sh/docs/react/temporal/reference
6
6
 
7
- `@moltenship/calendar-temporal` has the date math that views need. `@moltenship/calendar` re-exports
8
- all of it, so you can import these functions from either package:
7
+ Everything on this page is exported from `@moltenship/calendar-temporal`. The
8
+ [Overview](../temporal.md) has the install command and a first example.
9
9
 
10
- ```ts
11
- import { plainDateInterval, zonedDayRange } from "@moltenship/calendar";
12
- ```
13
-
14
- The package on its own has no dependencies and no React, so it also works where React isn't
15
- loaded.
10
+ `@moltenship/calendar` re-exports all of it, so a React app imports from either.
16
11
 
17
12
  Dates and times go in and out as native Temporal values. Apart from `createSystemClock`, nothing
18
13
  reads the clock, and nothing reads the host time zone.
@@ -162,7 +157,7 @@ repeated hour have two. A slot that a DST change cuts through is split at the ch
162
157
  ## Keys
163
158
 
164
159
  `instantKey`, `plainDateKey`, `plainDateTimeKey`, `zonedDayKey`, and `zonedWallTimeKey` return
165
- strings for use as React keys or cache keys. Two moments in a repeated hour share a wall-clock key,
160
+ strings for use as list keys or cache keys. Two moments in a repeated hour share a wall-clock key,
166
161
  so key those by `instantKey`. Time zone names are compared case-insensitively, but aliases such as
167
162
  `Asia/Calcutta` and `Asia/Kolkata` produce different keys.
168
163