Skip to Content
GuideScheduling

Scheduling

Start with one day of working hours, then add rules as you need them. Use generateTimeslots for one day or time window, and generateDailyTimeslots to repeat working hours across a date range. To also remove bookings, see Multi-party availability.

Single day

For a first schedule, choose a date, timezone, working window, and meeting length. This example offers 30-minute meetings from 09:00 to 10:00 in New York:

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

The result contains two slots: 09:00–09:30 and 09:30–10:00, in the configured timezone. Their start and end values are Date objects.

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:

import { generateTimeslots } from 'timeslottr' // 30-minute meetings, with a new option starting every 15 minutes const slots = generateTimeslots({ day: '2024-03-15', timezone: 'America/New_York', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, slotIntervalMinutes: 15, })

A shorter interval offers more choices: a visitor can pick 09:00 or 09:15. Those options overlap, so your application still needs to record a booking and remove conflicting options when someone reserves one.

DurationIntervalFirst two options
30 minutes30 minutes (default)09:00–09:30, 09:30–10:00
30 minutes15 minutes09:00–09:30, 09:15–09:45
30 minutes45 minutes09:00–09:30, 09:45–10:15

Buffers and breaks

Buffers trim the outer working window. For a 09:00–17:00 range, a 10-minute before buffer and a 10-minute after buffer leave 09:10–16:50. They do not add prep or cleanup time around each meeting or busy event.

Use excludedWindows to remove breaks inside the range. Each remaining free segment is slotted separately, so no slot crosses a break. If a segment is shorter than slotDurationMinutes, it produces no slots by default. To allow shorter slots, set minimumSlotDurationMinutes and keep includeEdge: true.

import { generateTimeslots } from 'timeslottr' const slots = generateTimeslots({ day: '2024-03-15', timezone: 'America/New_York', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, excludedWindows: [{ start: '12:00', end: '13:00' }], }) slots.length // 14: six before lunch, eight after

Multiple days

generateDailyTimeslots takes a period (start/end dates) plus the same config, and applies it to each day in range. Date-only period boundaries mean midnight in timezone: the end date does not include that day’s working hours. To include March 1 through March 7, set the end to March 8:

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

This returns 56 one-hour slots: eight per day for seven days, including the weekend. Use a weekday map below if your schedule only runs on selected days.

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).

Booking windows

Want two hours to prepare for a meeting, and bookings no more than 60 days ahead? Use minimumNoticeMinutes for lead time and maximumAdvanceDays for the latest allowed start. Both work with every generator:

import { generateDailyTimeslots } from 'timeslottr' const slots = generateDailyTimeslots( { start: '2024-03-01', end: '2024-06-01' }, { range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, timezone: 'America/New_York', now: '2024-03-01T08:00:00-05:00', // fixed clock for this example minimumNoticeMinutes: 120, // no bookings within the next 2 hours maximumAdvanceDays: 60, // and nothing more than 60 days out }, )

maximumAdvanceDays counts calendar days rather than 24-hour blocks, so the cutoff stays at the same local time across a daylight-saving change. It must be a positive whole number.

Filtering looks at each slot’s start time, never its end. Set minimumNoticeMinutes: 0 to exclude slots that have already started; maximumAdvanceDays alone only sets an upper cutoff. The bookable span is half-open: a slot starting exactly at the notice boundary is kept, one starting exactly at the advance cutoff is not.

Unbookable slots are dropped before maxSlots is applied, so maxSlots: 5 returns up to five bookable slots per day, provided enough slots fit. For generateDailyTimeslots, maxSlots and metadata indexes apply separately to each day. Use slots.slice(0, 5) if you need five results across the entire period.

Controlling “now”

Both options are measured from now, which defaults to new Date(). Set it explicitly to make output deterministic in tests, or to gate against a server clock instead of the caller’s:

import { generateTimeslots } from 'timeslottr' const slots = generateTimeslots({ day: '2024-03-15', timezone: 'UTC', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, now: '2024-03-15T10:15:00Z', minimumNoticeMinutes: 60, }) // earliest bookable start is 11:15, so the first slot returned is 11:30

The fixed now values above keep the examples repeatable. Omit now in a live booking flow to use the current clock.

When neither option is set, now is never read and generation does not filter out past dates.

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

Last updated on