@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,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).
@@ -0,0 +1,167 @@
1
+ # API reference
2
+
3
+ Everything @moltenship/calendar-temporal exports. Ranges, date and time grids, rounding, day boundaries, daylight saving time, keys and clocks.
4
+
5
+ Source: https://time.molten.sh/docs/react/temporal/reference
6
+
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
+
10
+ `@moltenship/calendar` re-exports all of it, so a React app imports from either.
11
+
12
+ Dates and times go in and out as native Temporal values. Apart from `createSystemClock`, nothing
13
+ reads the clock, and nothing reads the host time zone.
14
+
15
+ ## Ranges
16
+
17
+ A range has a `start` and an `end`. The start is included and the end is excluded, and the start
18
+ must come before the end.
19
+
20
+ ```ts
21
+ import { plainDateInterval, plainDateIntervalContains } from "@moltenship/calendar-temporal";
22
+
23
+ const october = plainDateInterval(
24
+ Temporal.PlainDate.from("2026-10-01"),
25
+ Temporal.PlainDate.from("2026-11-01"),
26
+ );
27
+
28
+ plainDateIntervalContains(october, Temporal.PlainDate.from("2026-10-31")); // true
29
+ plainDateIntervalContains(october, Temporal.PlainDate.from("2026-11-01")); // false
30
+ ```
31
+
32
+ `instantInterval`, `plainDateInterval`, and `plainDateTimeInterval` create frozen ranges and throw
33
+ `InvalidHalfOpenIntervalError` when the start isn't before the end. To get a result object instead
34
+ of an error, use `validateHalfOpenInterval`.
35
+
36
+ There's one function per operation and type:
37
+
38
+ | Operation | `Temporal.Instant` | `Temporal.PlainDate` | `Temporal.PlainDateTime` |
39
+ | ---------------- | --------------------------------- | ----------------------------------- | --------------------------------------- |
40
+ | Contains a point | `instantIntervalContains` | `plainDateIntervalContains` | `plainDateTimeIntervalContains` |
41
+ | Contains a range | `instantIntervalContainsInterval` | `plainDateIntervalContainsInterval` | `plainDateTimeIntervalContainsInterval` |
42
+ | Overlaps | `instantIntervalsIntersect` | `plainDateIntervalsIntersect` | `plainDateTimeIntervalsIntersect` |
43
+ | Overlapping part | `intersectInstantIntervals` | `intersectPlainDateIntervals` | `intersectPlainDateTimeIntervals` |
44
+ | Split at a point | `splitInstantInterval` | `splitPlainDateInterval` | `splitPlainDateTimeInterval` |
45
+
46
+ Ranges that only touch don't overlap. The overlapping part is `null` when there's no overlap.
47
+ Splitting returns two ranges when the point is strictly inside, and the original range otherwise.
48
+
49
+ `compareInstants`, `comparePlainDates`, `comparePlainDateTimes`, and `comparePlainTimes` are the
50
+ matching sort functions.
51
+
52
+ ## Days, weeks, and months
53
+
54
+ ```ts
55
+ import { iteratePlainDates, monthGrid, weekRange } from "@moltenship/calendar-temporal";
56
+
57
+ const date = Temporal.PlainDate.from("2026-10-08");
58
+
59
+ weekRange(date, { weekStartsOn: 1 }); // 2026-10-05 to 2026-10-12, Monday start
60
+
61
+ const grid = monthGrid(date, { weekStartsOn: 1 });
62
+ grid.weeks.length; // 5 weeks shown for October 2026
63
+
64
+ for (const day of iteratePlainDates(grid.range)) {
65
+ // every date in the visible grid, end excluded
66
+ }
67
+ ```
68
+
69
+ - `weekRange(date, { weekStartsOn })` returns the seven-day range containing `date`. `weekStartsOn`
70
+ is 1 (Monday) to 7 (Sunday).
71
+ - `monthGrid(date, options)` returns the month's first day (`month`), the full visible `range`, and
72
+ one range per week (`weeks`). It has four to six weeks; pass `fixedWeeks: true` for always six.
73
+ - `iteratePlainDates(range, { stepDays })` and `iterateInstants(range, { step })` step through a
74
+ range lazily. They throw a `RangeError` rather than yield more than 10,000 values; raise `limit` for
75
+ longer ranges.
76
+
77
+ ## Rounding and snapping
78
+
79
+ ```ts
80
+ import { snapPlainTime, snapZonedDateTime } from "@moltenship/calendar-temporal";
81
+
82
+ snapPlainTime(Temporal.PlainTime.from("23:50"), {
83
+ increment: 30,
84
+ mode: "ceil",
85
+ smallestUnit: "minute",
86
+ }); // { time: 00:00, days: 1 }
87
+
88
+ snapZonedDateTime(Temporal.ZonedDateTime.from("2026-03-29T01:50+01:00[Europe/Berlin]"), {
89
+ increment: 15,
90
+ mode: "ceil",
91
+ smallestUnit: "minute",
92
+ }); // 2026-03-29T03:00:00+02:00[Europe/Berlin]: 02:00 doesn't exist that night
93
+ ```
94
+
95
+ The snap functions round to a wall-clock grid that starts at midnight, with `mode` set to
96
+ `"nearest"` (the default), `"floor"`, or `"ceil"`:
97
+
98
+ - `snapPlainTime(time, options)` returns `{ time, days }`. `days` is `1` when rounding up passed
99
+ midnight, so a late end time isn't mistaken for an early one.
100
+ - `snapZonedDateTime(value, options)` rounds in the value's own time zone. In a repeated hour it
101
+ keeps the same occurrence. If the result lands in a skipped hour, it moves to the moment the clocks
102
+ change, so `floor` never moves later and `ceil` never moves earlier.
103
+ - `snapZonedWallTime(wallTime, { timeZone, fold, ...options })` does the same for a wall-clock time
104
+ with no zone yet, such as a pointer position. `fold` picks `"earlier"` (the default) or `"later"`
105
+ for a repeated time.
106
+
107
+ `roundPlainTime` and `roundInstant` take Temporal's full set of rounding modes. Instant rounding
108
+ starts at the Unix epoch.
109
+
110
+ ## Days in a time zone
111
+
112
+ ```ts
113
+ import { zonedDayRange } from "@moltenship/calendar-temporal";
114
+
115
+ const day = zonedDayRange(Temporal.PlainDate.from("2026-03-29"), "Europe/Berlin");
116
+
117
+ day.kind; // "available"
118
+ day.duration.toString(); // "PT23H": the clocks go forward that night
119
+ ```
120
+
121
+ - `zonedDayRange(date, timeZone)` returns the real start and end of a date in a zone. Its
122
+ `interval` is the instant range to query with. In the rare case where a time zone skips a whole
123
+ date, `kind` is `"skipped"` and `interval` is `null`.
124
+ - `splitInstantRangeByZonedDay(range, timeZone)` cuts an instant range into one piece per day, for
125
+ events that cross midnight. Each piece says whether the event continues before or after that day.
126
+ - `zonedDayTransitions(date, timeZone)` lists the offset changes on a date, with whether each is a
127
+ gap or a fold and which wall-clock times it affects.
128
+
129
+ ## Wall-clock times
130
+
131
+ ```ts
132
+ import { resolveZonedWallTime } from "@moltenship/calendar-temporal";
133
+
134
+ const result = resolveZonedWallTime(Temporal.PlainDateTime.from("2026-03-29T02:15"), {
135
+ timeZone: "Europe/Berlin",
136
+ disambiguation: "compatible",
137
+ });
138
+
139
+ result.status; // "resolved"
140
+ result.kind; // "gap": 02:15 doesn't exist that day
141
+ result.adjustment?.resolvedWallTime.toString(); // "2026-03-29T03:15:00"
142
+ ```
143
+
144
+ `resolveZonedWallTime(wallTime, { timeZone, disambiguation })` turns a wall-clock time into an
145
+ instant and tells you what happened: `kind` is `"unique"`, `"gap"`, or `"fold"`. For a gap,
146
+ `adjustment` says how far the time moved; with `disambiguation: "reject"`, `status` is `"rejected"`
147
+ instead. For a fold, `occurrences` has both instants. `projectInstantToZonedTime(instant, timeZone)`
148
+ goes the other way.
149
+
150
+ ## Time slots
151
+
152
+ `slotsInZonedDay(date, { timeZone, disambiguation, slotDuration })` splits a day into wall-clock
153
+ slots, such as 30-minute rows for a day view. Slots in a skipped hour have no instant. Slots in a
154
+ repeated hour have two. A slot that a DST change cuts through is split at the change. It throws a
155
+ `RangeError` when the day would have more than 10,000 slots; raise `limit` for finer grids.
156
+
157
+ ## Keys
158
+
159
+ `instantKey`, `plainDateKey`, `plainDateTimeKey`, `zonedDayKey`, and `zonedWallTimeKey` return
160
+ strings for use as list keys or cache keys. Two moments in a repeated hour share a wall-clock key,
161
+ so key those by `instantKey`. Time zone names are compared case-insensitively, but aliases such as
162
+ `Asia/Calcutta` and `Asia/Kolkata` produce different keys.
163
+
164
+ ## Clocks
165
+
166
+ `createFixedClock(instant)` and `createSystemClock()` return objects for `Root`'s `clock` prop. A fixed
167
+ clock always returns the same instant, which helps in tests.
@@ -0,0 +1,105 @@
1
+ # Overview
2
+
3
+ What @moltenship/calendar-temporal is, how to install it, and a first example of its date ranges.
4
+
5
+ Source: https://time.molten.sh/docs/react/temporal
6
+
7
+ `@moltenship/calendar-temporal` is the date math under the calendar: ranges, week and month grids,
8
+ rounding and snapping, the real length of a day in a time zone, and what happens to a time when
9
+ the clocks change. Dates and times go in and out as native `Temporal` values.
10
+
11
+ Apart from `createSystemClock`, nothing in it reads the clock, and nothing reads the host's time
12
+ zone. Every function takes the date, the time zone and the first day of the week as arguments, so
13
+ the same call gives the same answer on a server, in a browser and in a test.
14
+
15
+ ## Use it without the calendar
16
+
17
+ The package has no dependencies and imports no UI framework. Install it alone for a date picker of
18
+ your own, a booking form, a report grouped by week, or any code that needs a correct month grid or
19
+ a day that is 23 hours long.
20
+
21
+ `@moltenship/calendar` re-exports all of it. An app that has the calendar imports these functions
22
+ from there, and needs nothing more installed:
23
+
24
+ ```ts
25
+ import { plainDateInterval, zonedDayRange } from "@moltenship/calendar";
26
+ ```
27
+
28
+ ## Install
29
+
30
+ **pnpm**
31
+
32
+ ```bash
33
+ pnpm add @moltenship/calendar-temporal
34
+ ```
35
+
36
+ **npm**
37
+
38
+ ```bash
39
+ npm install @moltenship/calendar-temporal
40
+ ```
41
+
42
+ **yarn**
43
+
44
+ ```bash
45
+ yarn add @moltenship/calendar-temporal
46
+ ```
47
+
48
+ **bun**
49
+
50
+ ```bash
51
+ bun add @moltenship/calendar-temporal
52
+ ```
53
+
54
+ The package is versioned with the calendar.
55
+
56
+ It needs a runtime with `Temporal`, or a polyfill loaded first, and TypeScript's `ESNext` library.
57
+ [Installation](./installation.md#temporal) shows both.
58
+
59
+ ## A first example
60
+
61
+ A range has a `start` and an `end`. It includes the start and excludes the end, which is how
62
+ nights, bookings and visible dates are counted:
63
+
64
+ ```ts title="stay.ts"
65
+ import {
66
+ intersectPlainDateIntervals,
67
+ plainDateInterval,
68
+ weekRange,
69
+ } from "@moltenship/calendar-temporal";
70
+
71
+ const date = (value: string) => Temporal.PlainDate.from(value);
72
+
73
+ // A stay that arrives on October 9 and leaves on the 14th. A range includes its start and
74
+ // excludes its end, so the 14th isn't one of its nights.
75
+ export const stay = plainDateInterval(date("2026-10-09"), date("2026-10-14"));
76
+
77
+ // The week of October 8 that starts on a Monday: October 5 up to the 12th.
78
+ export const week = weekRange(date("2026-10-08"), { weekStartsOn: 1 });
79
+
80
+ // The part of the stay inside that week, or null when they don't overlap.
81
+ export const nights = intersectPlainDateIntervals(stay, week);
82
+ ```
83
+
84
+ `nights` runs from October 9 up to October 12: the three nights of the stay that fall in that
85
+ week. `plainDateInterval` throws an `InvalidHalfOpenIntervalError` when the start isn't before the
86
+ end, so a range that exists is valid.
87
+
88
+ ## What's in it
89
+
90
+ | You need | Use |
91
+ | ----------------------------------------------------------- | --------------------------------------------------------------- |
92
+ | A range of dates, instants or wall-clock times | `plainDateInterval`, `instantInterval`, `plainDateTimeInterval` |
93
+ | Whether two ranges overlap, and where | `plainDateIntervalsIntersect`, `intersectPlainDateIntervals` |
94
+ | The week or the month grid around a date | `weekRange`, `monthGrid`, `iteratePlainDates` |
95
+ | A time rounded to a grid of minutes | `snapPlainTime`, `snapZonedDateTime`, `snapZonedWallTime` |
96
+ | When a date starts and ends in a time zone | `zonedDayRange`, `splitInstantRangeByZonedDay` |
97
+ | The instant of a wall-clock time, with gaps and folds named | `resolveZonedWallTime` |
98
+ | The rows of a day view | `slotsInZonedDay` |
99
+ | A clock you can fix in a test | `createFixedClock`, `createSystemClock` |
100
+
101
+ ## Next
102
+
103
+ - [Build a month grid](./temporal/month-grid.md): The weeks of a month, the weekday names above them, and the days of the months around it.
104
+ - [Handle daylight saving time](./temporal/daylight-saving-time.md): Days of 23 and 25 hours, times the clocks skip or repeat, and the rows of a day view.
105
+ - [API reference](./temporal/reference.md): Every function, by what it works on.