Skip to Content
GuideMulti-party availability

Multi-party availability

Suppose you work 09:00–17:00, have lunch at noon, and need a meeting with Alice and Bob. You need a slot that fits your hours and avoids all three calendars. generateAvailableTimeslots does that in one call.

Use the interval functions subtract and intersect, plus generateAvailableTimeslots, which combines them with slot generation.

Everything here uses half-open [start, end) intervals (see Core concepts), so a slot that ends when a meeting starts is not treated as a conflict.

Pick your starting point

What you haveWhat to use
Working hours and existing bookingsgenerateAvailableTimeslots to get bookable slots
Free windows and bookings as Date objectssubtract to get the remaining free windows
A list of free windows for each personintersect to find shared free windows

The pipeline

base availability -> subtract(busy) -> intersect(participants) -> slots
  1. Start from base availability: your range minus buffers and excludedWindows.
  2. Subtract busy to remove events that are already booked for everyone.
  3. Intersect the participants to keep only windows where every person is free.
  4. Run the normal generator over what is left.

All in one call

generateAvailableTimeslots takes the same config as generateTimeslots, plus two optional fields:

import { generateAvailableTimeslots } from 'timeslottr' const slots = generateAvailableTimeslots({ day: '2024-01-01', timezone: 'America/New_York', range: { start: '09:00', end: '17:00' }, slotDurationMinutes: 30, // booked events on the host's calendar, blocked for everyone 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

Read the example as “start with my working hours, remove lunch, then avoid Alice’s morning meeting and Bob’s late-afternoon meeting.” That leaves two free windows, which are split into 30-minute slots.

busy is one shared list of bookings. participantsBusy is a list of lists: each inner list belongs to one person. You provide these events from your calendar integration; timeslottr does not fetch calendars or save reservations.

busy and participantsBusy accept the same formats as range and excludedWindows: a Date, an ISO string, a time-only string like '09:00', or a { date, time } object.

A fully booked day returns []. An empty inner array in participantsBusy means that person is free for the whole window. Time-only busy strings need a day or dated boundaries, the same as excludedWindows.

The primitives on their own

Sometimes you already have free and busy intervals and just want the math. Both functions work on resolved Interval objects ({ start: Date; end: Date }). Use these functions when you want free windows of any length, rather than fixed-length meetings. The API reference covers their inputs and edge cases. The times in the next two examples are UTC (Z).

subtract: availability minus bookings

import { subtract } from 'timeslottr' const free = subtract( [{ start: new Date('2024-01-01T09:00:00Z'), end: new Date('2024-01-01T17:00:00Z') }], [{ start: new Date('2024-01-01T12:00:00Z'), end: new Date('2024-01-01T13:00:00Z') }], ) // result: [09:00 to 12:00, 13:00 to 17:00]

Busy intervals can be unsorted, overlap each other, or touch boundaries. A busy window in the middle of a source splits it in two.

intersect: a time for the whole team

import { intersect } from 'timeslottr' const team = intersect([ [{ start: new Date('2024-01-01T09:00:00Z'), end: new Date('2024-01-01T15:00:00Z') }], [{ start: new Date('2024-01-01T11:00:00Z'), end: new Date('2024-01-01T17:00:00Z') }], ]) // result: [11:00 to 15:00]

Given one set of free intervals per person, intersect returns the windows where all of them overlap. With no sets it returns []. With one set it returns a merged copy. If any set is empty, the result is [], since a person with no availability blocks everyone.

Why am I getting no slots?

  • Check that every free segment is long enough for slotDurationMinutes. Free minutes on opposite sides of a booking cannot be combined into one slot.
  • Check the date and timezone used for time-only boundaries.
  • If you set minimumNoticeMinutes, check now: past dates may be filtered out.
  • For intersect, an empty person’s free list blocks all shared availability. For participantsBusy, an empty person’s busy list blocks nothing.

Try it

Use the Playground to explore working hours, slot lengths, and exclusions. To try participant bookings, start with the example above and replace each person’s busy list with your own calendar events.

Last updated on