Skip to Content
GuideScheduling

Scheduling

timeslottr has two generators: generateTimeslots for a single window, and generateDailyTimeslots to apply a schedule across many days.

Single day

Give it a range, a slotDurationMinutes, and whatever options you need:

import { generateTimeslots } from 'timeslottr' const slots = generateTimeslots({ day: '2024-03-15', timezone: 'America/New_York', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, slotIntervalMinutes: 15, // start a new slot every 15 min, so slots overlap bufferBeforeMinutes: 10, // trim 10 min off the start of the window bufferAfterMinutes: 10, // trim 10 min off the end excludedWindows: [{ start: '12:00', end: '13:00' }], // lunch alignment: 'start', })

See Configuration for every option and its default.

Overlapping vs. back-to-back slots

slotIntervalMinutes is the step between slot starts. slotDurationMinutes is how long each slot lasts. Set them equal (the default) for back-to-back slots, or make the interval smaller to overlap them:

// 30-min slots starting every 15 min: 9:00 to 9:30, 9:15 to 9:45, and so on generateTimeslots({ day: '2024-03-15', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, slotIntervalMinutes: 15, })

Multiple days

generateDailyTimeslots takes a period (start/end dates) plus the same config, and applies it to each day in range:

import { generateDailyTimeslots } from 'timeslottr' const slots = generateDailyTimeslots( { start: '2024-03-01', end: '2024-03-07' }, { range: { start: '09:00', end: '17:00' }, // same hours every day slotDurationMinutes: 60, timezone: 'America/New_York', }, )

Per-weekday schedules

Pass a Map<Weekday, TimeslotRangeInput | null> as the range to give each day of the week its own hours. Weekdays absent from the map (or mapped to null) generate no slots:

import { generateDailyTimeslots, Weekday } from 'timeslottr' const slots = generateDailyTimeslots( { start: '2024-03-01', end: '2024-03-14' }, { 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, so no slots on weekends ]), slotDurationMinutes: 60, timezone: 'America/New_York', excludedWindows: [{ start: '12:00', end: '13:00' }], }, )

Weekday is an enum that matches Date.getDay(), from SUN (0) to SAT (6).

Next, factor in who is actually free. See Multi-party availability.

Last updated on