Skip to Content

Types

You can import types directly from timeslottr with import type. Start with the type that matches the data you’re working with:

DataType
Generated meeting optionsTimeslot[]
Free or busy windows with resolved datesInterval[]
Working hours supplied to a generatorTimeslotRangeInput
Generator optionsTimeslotGenerationConfig, DailyTimeslotConfig, or AvailableTimeslotConfig
Slots sent as JSONTimeslotJSON
import { generateTimeslots, type TimeslotGenerationConfig } from 'timeslottr' const config: TimeslotGenerationConfig = { day: '2024-03-15', timezone: 'UTC', range: { start: '09:00', end: '10:00' }, slotDurationMinutes: 30, } const slots = generateTimeslots(config)

Timeslot

The result of slot generation. start belongs to the slot, and end marks where it stops. The generators attach metadata, but the type allows it to be absent for slots you create yourself. See Core concepts.

interface Timeslot { start: Date // inclusive end: Date // exclusive metadata?: { index: number // 0-based slot index durationMinutes: number label?: string // from labelFormatter } }

Interval

A resolved half-open time interval. This is the shape that subtract and intersect work on.

interface Interval { start: Date // inclusive end: Date // exclusive }

AvailableTimeslotConfig

Extends TimeslotGenerationConfig with booked time for generateAvailableTimeslots.

interface AvailableTimeslotConfig extends TimeslotGenerationConfig { busy?: TimeslotRangeInput[] // events to subtract participantsBusy?: TimeslotRangeInput[][] // per-person busy sets }

TimeslotJSON

JSON-safe version with ISO string dates. Used with timeslotToJSON / timeslotFromJSON.

interface TimeslotJSON { start: string // ISO 8601 end: string // ISO 8601 metadata?: { index: number durationMinutes: number label?: string } }

TimeslotBoundaryInput

A start or end value before the generator converts it to a Date. Time-only values need a date anchor, usually config.day. Use YYYY-MM-DD for date-only strings and include Z or an offset for exact timestamps.

type TimeslotBoundaryInput = | Date // JavaScript Date object | string // ISO string or time-only ("09:00", "17:30") | { date?: Date | string // optional date anchor time: | string | { hour: number; minute?: number; second?: number } }

TimeslotRangeInput

A pair of boundaries describing working hours, a break, or a busy event. Unlike Interval, this accepts strings and date/time objects as well as Dates.

interface TimeslotRangeInput { start: TimeslotBoundaryInput end: TimeslotBoundaryInput }

AlignmentStrategy

Chooses where leftover time goes when a window doesn’t fit the slot pattern. Use 'start' to begin at the opening time, 'end' to finish at the closing time, or 'center' to balance the leftover time on both sides.

type AlignmentStrategy = 'start' | 'end' | 'center'

Weekday

Use this enum as the keys of a weekly schedule map. The values match JavaScript’s Date.getDay() (Sunday = 0). The generator chooses weekdays in the configured timezone; you do not need to calculate them yourself.

import { Weekday } from 'timeslottr' Weekday.SUN // 0 Weekday.MON // 1 Weekday.TUE // 2 Weekday.WED // 3 Weekday.THU // 4 Weekday.FRI // 5 Weekday.SAT // 6

Generator configuration types

TimeslotGenerationConfig describes a single window. range and slotDurationMinutes are required; the other options control dates, breaks, slot spacing, labels, and booking limits. See Configuration for the complete option tables and defaults.

DailyTimeslotConfig uses the same options, except that it supplies day automatically and lets range be a weekday map. It also accepts maxDays. The map has its own exported alias:

type WeekdayTimeslotRangeInput = Map<Weekday, TimeslotRangeInput | null>

An omitted weekday or a null entry generates no slots. See Per-weekday schedules for an example.

Supporting types

These smaller types are useful when building your own configuration form or label function:

type DateValue = Date | string type TimeOfDayInput = | string // for example, '09:30' | { hour: number; minute?: number; second?: number } interface TimeslotMetadata { index: number durationMinutes: number label?: string } type LabelFormatter = ( slot: { start: Date; end: Date }, index: number, durationMinutes: number, ) => string | undefined

Return a string from LabelFormatter to attach metadata.label, or undefined to leave it out. index is zero-based and restarts each day in multi-day results.

Last updated on