Event management: fields, sorting, and availability.
Events come in two types:
- Standard — fixed capacity with optional date
- Daily — date-based booking with holiday exclusions
Add days to a YYYY-MM-DD date string
Add N months to an ISO timestamp, clamping to the last day of the target month. e.g. 2026-01-31 + 1mo → 2026-02-28 Preserves the time component (hour/minute/second/ms). Zero months returns the input with canonical ISO string formatting.
Compute how many days ago an event started, relative to today in the configured timezone. Returns null if the event date is today or in the future, or if the date is empty/invalid. For past events, returns a positive integer (1 = yesterday).
Convert a UTC ISO datetime to a YYYY-MM-DD calendar date in the given timezone. Returns null if the input is empty or invalid. Used by the calendar view to map standard event dates to calendar days.
Format a YYYY-MM-DD date for display. Returns "Monday 15 March 2026"
Format a booking's stored [start_at, end_at) ISO range as a human label.
1-day bookings collapse to formatDateLabel; multi-day bookings use the
compact English range formatter (inclusive — subtracts 1 day from end_at,
which is the first midnight after the booked window).
Compact English date-range formatter. Uses an en dash (–) for ranges.
Format an ISO datetime string for display in the given timezone. Returns e.g. "Monday 15 June 2026 at 14:00 BST"
Compact ISO datetime formatter for table cells. Returns e.g. "07/04/2026 14:00" in the configured timezone.
Compute available booking dates for a daily event.
Filters by bookable days of the week and excludes holidays.
For events with duration_days > 1, excludes start dates whose full range
would hit a non-bookable day or extend past the booking window.
Returns sorted array of YYYY-MM-DD strings.
Get the next available booking date for a daily event. More efficient than getAvailableDates()[0] — stops at first match. Returns null if no bookable dates are available.
Load all events with holidays and return them sorted, filtered by predicate.
Determine which contact fields to collect for multiple events. Returns the union of all field settings, sorted by canonical CONTACT_FIELDS order.
Normalize datetime-local "YYYY-MM-DDTHH:MM" to full UTC ISO string. The input is interpreted as local time in the given timezone and converted to UTC.
Parse a comma-separated fields string into individual ContactField names
Sort events in unified 3-tier order. Works with any Event subtype (Event, EventWithCount, etc.).
Round a date down to the start of the current hour for cache-stable signatures
Ensure "email" is included in an event fields setting
| "Monday"
| "Tuesday"
| "Wednesday"
| "Thursday"
| "Friday"
| "Saturday"
Day name lookup from Date.getUTCDay() index (Sunday=0)
Usage
import * as mod from "docs/events.ts";