Next: Core Concepts
npm install scheduling-sdk
# or
yarn add scheduling-sdk
# or
bun add scheduling-sdkBefore diving in, let's clarify the main concepts:
- Busy Time: A period when you're NOT available (existing meetings, appointments, breaks)
- Available Slot: A time period when you CAN be scheduled (no conflicts with busy times)
- Time Range: The window (start and end dates) where you want to find available slots
- Padding: Extra buffer time added around busy times to prevent back-to-back scheduling
The Scheduling SDK provides a simple interface for finding available time slots while considering busy periods and various scheduling constraints.
import { Scheduler } from 'scheduling-sdk'
// Create a scheduler with busy times (periods when NOT available)
const scheduler = new Scheduler([
{
start: new Date('2024-01-15T09:00:00Z'), // 9:00 AM meeting
end: new Date('2024-01-15T10:00:00Z'), // ends at 10:00 AM
},
{
start: new Date('2024-01-15T14:00:00Z'), // 2:00 PM appointment
end: new Date('2024-01-15T15:30:00Z'), // ends at 3:30 PM
},
])
// Find available 30-minute slots
const availableSlots = scheduler.findAvailableSlots(
new Date('2024-01-15T08:00:00Z'), // Start time
new Date('2024-01-15T17:00:00Z'), // End time
{
slotDuration: 30, // 30-minute slots
padding: 0, // No padding around busy times
slotSplit: 30, // Non-overlapping slots
offset: 0, // No offset from hour boundaries
}
)
console.log(availableSlots)
// Output: Array of available time slots that avoid the busy periods:
// - 8:00-8:30, 8:30-9:00 (before first meeting)
// - 10:00-10:30, 10:30-11:00... up to 14:00 (between meetings)
// - 15:30-16:00, 16:00-16:30, 16:30-17:00 (after last appointment)- Import the SDK: Import the
Schedulerclass - Create Scheduler: Initialize with existing busy times (optional)
- Define Options: Configure slot duration, padding, splitting, and offset
- Find Slots: Call
findAvailableSlotswith time range and options - Use Results: Process the returned array of available time slots
A time slot represents a potential booking period with a start and end time:
interface TimeSlot {
start: Date
end: Date
}Busy times represent periods when you are NOT available for scheduling - think of them as blocked time on your calendar:
interface BusyTime {
start: Date
end: Date
}Configure how slots are generated:
interface SchedulingOptions {
// Required
slotDuration: number // Duration of each slot in minutes
// Optional
slotSplit?: number // Interval between slot starts (default: same as duration)
padding?: number // Buffer time around busy periods in minutes
offset?: number // Offset from hour boundaries in minutes
maxOverlaps?: number // Allow up to K overlapping busy intervals (K-overlaps)
// Daily window filtering (timezone-aware)
timezone?: string
earliestTime?: string | number // 'HH:mm' or minutes since midnight
latestTime?: string | number // 'HH:mm' or minutes since midnight; supports '24:00' or 1440
}Quick links:
import { Scheduler } from 'scheduling-sdk'
const scheduler = new Scheduler()
// Add existing appointments
scheduler.addBusyTimes([
{ start: new Date('2024-01-15T10:00:00Z'), end: new Date('2024-01-15T11:00:00Z') },
{ start: new Date('2024-01-15T14:30:00Z'), end: new Date('2024-01-15T15:30:00Z') },
])
// Find 60-minute slots
const slots = scheduler.findAvailableSlots(new Date('2024-01-15T09:00:00Z'), new Date('2024-01-15T17:00:00Z'), {
slotDuration: 60,
})// Add 15-minute padding for room setup/cleanup
const slots = scheduler.findAvailableSlots(new Date('2024-01-15T09:00:00Z'), new Date('2024-01-15T17:00:00Z'), {
slotDuration: 60,
padding: 15, // 15 minutes buffer around busy times
})// Generate 60-minute slots every 30 minutes (overlapping)
const slots = scheduler.findAvailableSlots(new Date('2024-01-15T09:00:00Z'), new Date('2024-01-15T17:00:00Z'), {
slotDuration: 60,
slotSplit: 30, // New slot every 30 minutes
})// Allow up to 1 overlapping busy time (K = 1)
const kOverlapSlots = scheduler.findAvailableSlots(new Date('2024-01-15T09:00:00Z'), new Date('2024-01-15T17:00:00Z'), {
slotDuration: 30,
slotSplit: 15,
maxOverlaps: 1,
})// Align slots to quarter-hours (15-minute boundaries)
const slots = scheduler.findAvailableSlots(new Date('2024-01-15T09:00:00Z'), new Date('2024-01-15T17:00:00Z'), {
slotDuration: 30,
slotSplit: 15, // Align to 15-minute intervals
offset: 0, // Start on the hour
})// Separate schedulers for different resources
const roomScheduler = new Scheduler()
const equipmentScheduler = new Scheduler()
// Add resource-specific busy times
roomScheduler.addBusyTimes([...roomBookings])
equipmentScheduler.addBusyTimes([...equipmentBookings])
// Find slots available for both
const roomSlots = roomScheduler.findAvailableSlots(start, end, options)
const equipmentSlots = equipmentScheduler.findAvailableSlots(start, end, options)
// Find intersection of available slots
const bothAvailable = findIntersection(roomSlots, equipmentSlots)try {
const slots = scheduler.findAvailableSlots(
new Date('2024-01-15T17:00:00Z'), // End time
new Date('2024-01-15T09:00:00Z'), // Start time (invalid!)
{ slotDuration: 30 }
)
} catch (error) {
console.error('Invalid time range:', error.message)
}- API Reference — Complete method documentation
- Core Concepts — Daily Windows and K-overlaps
- Availability Scheduler — Weekly schedules and scheduler-level timezone
- Recipes — Real-world usage scenarios
- Performance Guide — Optimization tips