Skip to Content
ReferenceGeneration functions

Generation functions

Each generator turns a schedule into Timeslot[]: an array of possible meetings with Date start and end values. Start with the function that matches your task, then add options from Configuration.

Your taskFunction
Offer meetings in one time windowgenerateTimeslots
Repeat a schedule over several daysgenerateDailyTimeslots
Avoid existing bookings or coordinate a teamgenerateAvailableTimeslots

All examples below use an explicit timezone. See Core concepts if UTC output or date input formats are new to you.

generateTimeslots

generateTimeslots(config: TimeslotGenerationConfig): Timeslot[]

Use this for one day of working hours. For example, a two-hour window contains four 30-minute meetings:

import { generateTimeslots } from 'timeslottr' const slots = generateTimeslots({ day: '2024-03-15', timezone: 'America/New_York', range: { start: '09:00', end: '11:00' }, slotDurationMinutes: 30, })

slots.length is 4; the first meeting is 09:00–09:30 in New York. For breaks, buffers, and different start intervals, follow the Scheduling guide.

The booking-window options (minimumNoticeMinutes, maximumAdvanceDays, and the now they are measured from) apply to all three generators. See Booking windows.

generateDailyTimeslots

generateDailyTimeslots(period: TimeslotRangeInput, config: DailyTimeslotConfig): Timeslot[]

Generates slots across multiple days. Supports per-weekday schedules via a Map<Weekday, TimeslotRangeInput | null>, or a single range applied to every day. Only slots fully contained in period are returned. A date-only end resolves to midnight, so use end: '2024-03-15' to include working hours on March 14. Weekdays not present in the map (or mapped to null) are skipped. maxSlots limits each day’s results, and metadata indexes restart each day.

import { generateDailyTimeslots, Weekday } from 'timeslottr' const slots = generateDailyTimeslots( { start: '2024-03-01', end: '2024-03-15' }, { range: new Map([ [Weekday.MON, { start: '09:00', end: '17:00' }], [Weekday.TUE, { start: '09:00', end: '17:00' }], [Weekday.WED, { start: '09:00', end: '12:00' }], [Weekday.THU, { start: '09:00', end: '17:00' }], [Weekday.FRI, { start: '10:00', end: '16:00' }], // SAT and SUN omitted = no slots generated ]), slotDurationMinutes: 60, timezone: 'America/New_York', excludedWindows: [{ start: '12:00', end: '13:00' }], }, )

DailyTimeslotConfig accepts all single-day options plus maxDays. See Configuration.

generateAvailableTimeslots

generateAvailableTimeslots(config: AvailableTimeslotConfig): Timeslot[]

Use this when existing events should block otherwise open hours. It takes the same config as generateTimeslots, plus busy (events to subtract) and participantsBusy (per-person busy sets). It subtracts bookings, intersects across participants when provided, then runs the standard slot generator over the remaining free time. Slotting behavior is identical to generateTimeslots.

import { generateAvailableTimeslots } from 'timeslottr' const slots = generateAvailableTimeslots({ day: '2024-01-01', timezone: 'America/New_York', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, // already-booked events on the host's calendar busy: [{ start: '12:00', end: '13:00' }], // each invitee's busy times; only times where all are free survive participantsBusy: [ [{ start: '09:00', end: '10:00' }], // Alice [{ start: '16:00', end: '17:00' }], // Bob ], }) // 10 slots: 10:00–12:00 and 13:00–16:00, in New York

Busy times accept the same formats as range and excludedWindows (string | Date | { date, time }). A fully booked day returns []. An empty participantsBusy entry means that person is free for the whole window. See Multi-party availability for the longer walkthrough.

Last updated on