Overview

What @moltenship/calendar-temporal is, how to install it, and a first example of its date ranges.

@moltenship/calendar-temporal is the date math under the calendar: ranges, week and month grids, rounding and snapping, the real length of a day in a time zone, and what happens to a time when the clocks change. Dates and times go in and out as native Temporal values.

Apart from createSystemClock, nothing in it reads the clock, and nothing reads the host's time zone. Every function takes the date, the time zone and the first day of the week as arguments, so the same call gives the same answer on a server, in a browser and in a test.

Use it without the calendar

The package has no dependencies and imports no UI framework. Install it alone for a date picker of your own, a booking form, a report grouped by week, or any code that needs a correct month grid or a day that is 23 hours long.

@moltenship/calendar-solid re-exports all of it. An app that has the calendar imports these functions from there, and needs nothing more installed.

Install

pnpm add @moltenship/calendar-temporal

The package is versioned with the calendar.

It needs a runtime with Temporal, or a polyfill loaded first, and TypeScript's ESNext library. Installation shows both.

A first example

A range has a start and an end. It includes the start and excludes the end, which is how nights, bookings and visible dates are counted:

stay.ts
import {
  intersectPlainDateIntervals,
  plainDateInterval,
  weekRange,
} from "@moltenship/calendar-temporal";

const date = (value: string) => Temporal.PlainDate.from(value);

// A stay that arrives on October 9 and leaves on the 14th. A range includes its start and
// excludes its end, so the 14th isn't one of its nights.
export const stay = plainDateInterval(date("2026-10-09"), date("2026-10-14"));

// The week of October 8 that starts on a Monday: October 5 up to the 12th.
export const week = weekRange(date("2026-10-08"), { weekStartsOn: 1 });

// The part of the stay inside that week, or null when they don't overlap.
export const nights = intersectPlainDateIntervals(stay, week);

nights runs from October 9 up to October 12: the three nights of the stay that fall in that week. plainDateInterval throws an InvalidHalfOpenIntervalError when the start isn't before the end, so a range that exists is valid.

What's in it

You needUse
A range of dates, instants or wall-clock timesplainDateInterval, instantInterval, plainDateTimeInterval
Whether two ranges overlap, and whereplainDateIntervalsIntersect, intersectPlainDateIntervals
The week or the month grid around a dateweekRange, monthGrid, iteratePlainDates
A time rounded to a grid of minutessnapPlainTime, snapZonedDateTime, snapZonedWallTime
When a date starts and ends in a time zonezonedDayRange, splitInstantRangeByZonedDay
The instant of a wall-clock time, with gaps and folds namedresolveZonedWallTime
The rows of a day viewslotsInZonedDay
A clock you can fix in a testcreateFixedClock, createSystemClock

Next

On this page