Core concepts
Start with a simple question: “When can someone book a 30-minute meeting?” You give timeslottr your working hours and the meeting length, and it returns the possible start and end times. These are the ideas you’ll use along the way.
From working hours to slots
A range is the window you want to offer. A slot is one possible meeting inside that window. For example, an hour of working time can hold two 30-minute slots:
Working hours: 09:00 ─────────────────── 10:00
Slots: [09:00 → 09:30) [09:30 → 10:00)Here’s that schedule in code:
import { generateTimeslots } from 'timeslottr'
const slots = generateTimeslots({
day: '2024-01-01',
timezone: 'America/New_York',
range: { start: '09:00', end: '10:00' },
slotDurationMinutes: 30,
})
slots.length // 2day answers “which date?”, timezone answers “whose 9am?”, and range
sets the working hours. slotDurationMinutes sets the length of each meeting.
Breaks and bookings can remove time from that range before slots are generated.
These examples use fixed dates so you can reproduce the results. Past dates still produce slots unless you enable booking windows.
The Timeslot shape
Each result has a start and an end, both JavaScript Date objects.
The generators also attach metadata describing the slot:
// The first slot from the example above looks like this:
const firstSlot = {
start: new Date('2024-01-01T14:00:00.000Z'),
end: new Date('2024-01-01T14:30:00.000Z'),
metadata: {
index: 0,
durationMinutes: 30,
},
}The output shows 14:00 UTC because that’s the same moment as 09:00 in New York on January 1. The timezone section below shows how to display it as local time.
indexstarts at0. For multi-day generation, it restarts each day.durationMinutesis the slot’s actual length in elapsed minutes.labelis included if yourlabelFormatterreturns one.
The public Timeslot type makes metadata optional, so you can also work with
slots that only have start and end. See Types for the full definition.
Sending slots to an API or saving them as JSON? Use
timeslotToJSON and timeslotFromJSON to convert between
dates and strings. JSON.parse alone does not restore Date objects.
Half-open intervals [start, end)
A meeting can end at 09:30 and the next one can start at 09:30. They touch, but they don’t overlap.
That’s what half-open means: the start belongs to the slot, and the end
marks where it stops. The notation [start, end) is just a short way to write
that rule. You don’t need to adjust times by a second or a millisecond to keep
adjacent meetings separate.
import { contains, createTimeslot } from 'timeslottr'
const slot = createTimeslot(
new Date('2024-01-01T09:00:00Z'),
new Date('2024-01-01T09:30:00Z'),
)
contains(slot, new Date('2024-01-01T09:00:00Z')) // true: the slot starts here
contains(slot, new Date('2024-01-01T09:15:00Z')) // true: during the slot
contains(slot, new Date('2024-01-01T09:30:00Z')) // false: the slot has endedThis rule applies to ranges, slots, exclusions, and availability windows.
overlaps, subtract, and intersect follow it too: a booking that ends
exactly when a slot starts does not block that slot.
Timezones and DST
Give local times a date and timezone
“09:00” alone doesn’t identify a moment. It needs a date and a place.
For everyday working hours, use day with time-only boundaries and an explicit
IANA timezone such as America/New_York, Europe/London, or UTC.
You can also supply dates directly in your boundaries:
| Input | When to use it | Example boundary |
|---|---|---|
| Time-only string | Working hours, with day supplied separately | '09:00' |
| Date and time object | A local time on a specific date in timezone | { date: '2024-01-01', time: '09:00' } |
ISO timestamp with Z or an offset | An exact moment, such as a calendar event | '2024-01-01T14:00:00Z' |
JavaScript Date | An exact moment you already have in code | new Date('2024-01-01T14:00:00Z') |
A boundary is a start or end value. These formats work for ranges,
exclusions, and busy windows passed to the generators. The lower-level
subtract and intersect functions take Date objects.
Set timezone explicitly to get consistent calendar times on browsers and
servers. Without it, calendar inputs use the runtime’s local timezone.
For exact timestamps, include Z or an offset such as -05:00.
Use YYYY-MM-DD for date-only inputs, such as '2024-01-01'. They mean midnight
in the configured timezone. Forms like '2025-3-5', '2025/03/05', and impossible
dates such as '2025-02-30' are rejected. For a multi-day period, midnight on the
end date means that day’s working hours are outside the period; see
Multiple days.
Display a slot in the timezone you want
A Date holds a moment in time; it doesn’t keep the timezone used to create it.
toISOString() always shows UTC, marked with Z. To show local time, format
the result with Intl.DateTimeFormat:
// Using slots from the first example:
const formatTime = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
hour: '2-digit',
minute: '2-digit',
hour12: false,
})
formatTime.format(slots[0].start) // '09:00'
slots[0].start.toISOString() // '2024-01-01T14:00:00.000Z'
// Both represent the same moment.Notice the spelling: timeslottr’s option is timezone; the Intl option is
timeZone.
When the clocks change
Meeting lengths are measured in elapsed time. A 30-minute slot lasts 30 real minutes, even if a daylight-saving change makes the clock jump during it.
For example, New York skips from 02:00 to 03:00 on March 10, 2024. The window from midnight to 06:00 contains five elapsed hours, so it produces ten 30-minute slots:
import { generateTimeslots } from 'timeslottr'
const slots = generateTimeslots({
day: '2024-03-10',
timezone: 'America/New_York',
range: { start: '00:00', end: '06:00' },
slotDurationMinutes: 30,
})
slots.length // 10On the fall-back day, an hour repeats, so the same midnight-to-06:00 window
contains seven elapsed hours and produces fourteen slots. timeslottr uses the
platform’s Intl API for timezone calculations, with no extra date library.
Put it into practice
- Scheduling: repeat hours across days, add breaks, and set booking limits.
- Multi-party availability: remove bookings and find times everyone can attend.
- Playground: change a schedule and explore the generated slots.