/** * @fileoverview Scheduling and booking utilities * Provides slot generation, availability checking, and conflict detection */ import type { DateRange, DateInput, WorkingHoursConfig, RecurrenceRule } from './types.js'; /** Configuration for scheduling operations */ export interface SchedulingConfig { /** Working hours configuration */ workingHours?: WorkingHoursConfig; /** Buffer time between appointments in minutes */ bufferMinutes?: number; /** Default slot duration in minutes */ slotDuration?: number; /** Holidays to exclude */ holidays?: Date[]; } /** A time slot with availability status */ export interface Slot { start: Date; end: Date; available: boolean; } /** A booking with optional metadata */ export interface Booking extends DateRange { id?: string; metadata?: Record; } /** Default scheduling configuration */ export declare const DEFAULT_SCHEDULING_CONFIG: SchedulingConfig; /** * Generates time slots for a single day * @param date - The date to generate slots for * @param config - Scheduling configuration * @returns Array of slots for the day * * @example * ```ts * const slots = generateSlots(new Date('2024-01-15'), { slotDuration: 30 }); * // Returns 30-minute slots during working hours * ``` */ export declare function generateSlots(date: DateInput, config?: SchedulingConfig): Slot[]; /** * Generates time slots for a date range * @param range - The date range to generate slots for * @param config - Scheduling configuration * @returns Array of slots for all days in range * * @example * ```ts * const range = { start: new Date('2024-01-15'), end: new Date('2024-01-17') }; * const slots = generateSlotsForRange(range, { slotDuration: 60 }); * ``` */ export declare function generateSlotsForRange(range: DateRange, config?: SchedulingConfig): Slot[]; /** * Gets available slots for a day, excluding existing bookings * @param date - The date to check * @param bookings - Existing bookings * @param config - Scheduling configuration * @returns Array of available slots * * @example * ```ts * const bookings = [{ start: new Date('2024-01-15T10:00'), end: new Date('2024-01-15T11:00') }]; * const available = getAvailableSlots(new Date('2024-01-15'), bookings); * ``` */ export declare function getAvailableSlots(date: DateInput, bookings: Booking[], config?: SchedulingConfig): Slot[]; /** * Finds the next available slot of specified duration * @param after - Start searching after this date * @param bookings - Existing bookings * @param duration - Required slot duration in minutes * @param config - Scheduling configuration * @returns Next available slot or null if none found within 30 days * * @example * ```ts * const nextSlot = findNextAvailable(new Date(), bookings, 60); * if (nextSlot) console.log(`Next 1-hour slot at ${nextSlot.start}`); * ``` */ export declare function findNextAvailable(after: DateInput, bookings: Booking[], duration: number, config?: SchedulingConfig): Slot | null; /** * Checks if a slot is available (no conflicts with existing bookings) * @param slot - The slot to check * @param bookings - Existing bookings * @returns True if slot is available * * @example * ```ts * const slot = { start: new Date('2024-01-15T14:00'), end: new Date('2024-01-15T15:00') }; * if (isSlotAvailable(slot, existingBookings)) { * // Book the slot * } * ``` */ export declare function isSlotAvailable(slot: DateRange, bookings: Booking[]): boolean; /** * Finds bookings that conflict with a proposed time range * @param bookings - Existing bookings * @param proposed - Proposed time range * @returns Array of conflicting bookings * * @example * ```ts * const conflicts = findConflicts(existingBookings, { start: propStart, end: propEnd }); * if (conflicts.length > 0) { * console.log('Conflicts with:', conflicts); * } * ``` */ export declare function findConflicts(bookings: Booking[], proposed: DateRange): Booking[]; /** * Checks if a proposed time range has any conflicts * @param bookings - Existing bookings * @param proposed - Proposed time range * @returns True if there are conflicts * * @example * ```ts * if (hasConflict(existingBookings, proposedMeeting)) { * console.log('Time slot not available'); * } * ``` */ export declare function hasConflict(bookings: Booking[], proposed: DateRange): boolean; /** * Adds buffer time around a slot * @param slot - The original slot * @param bufferMinutes - Buffer time in minutes * @returns New slot with buffer added * * @example * ```ts * const slot = { start: new Date('2024-01-15T10:00'), end: new Date('2024-01-15T11:00') }; * const buffered = addBuffer(slot, 15); * // buffered.start = 09:45, buffered.end = 11:15 * ``` */ export declare function addBuffer(slot: DateRange, bufferMinutes: number): DateRange; /** * Removes buffer time from a slot * @param slot - The buffered slot * @param bufferMinutes - Buffer time in minutes to remove * @returns New slot with buffer removed * * @example * ```ts * const bufferedSlot = { start: new Date('2024-01-15T09:45'), end: new Date('2024-01-15T11:15') }; * const original = removeBuffer(bufferedSlot, 15); * // original.start = 10:00, original.end = 11:00 * ``` */ export declare function removeBuffer(slot: DateRange, bufferMinutes: number): DateRange; /** * Expands recurring availability pattern into concrete slots * @param pattern - Recurrence pattern * @param range - Date range to expand within * @param config - Scheduling configuration * @returns Array of slots from the recurring pattern * * @example * ```ts * const pattern = { * frequency: 'weekly', * startDate: new Date('2024-01-01'), * byWeekday: [1, 3, 5], // Mon, Wed, Fri * until: new Date('2024-12-31') * }; * const slots = expandRecurringAvailability(pattern, range); * ``` */ export declare function expandRecurringAvailability(pattern: RecurrenceRule, range: DateRange, config?: SchedulingConfig): Slot[]; /** * Merges adjacent or overlapping bookings * @param bookings - Array of bookings to merge * @returns Array of merged bookings * * @example * ```ts * const bookings = [ * { start: new Date('2024-01-15T09:00'), end: new Date('2024-01-15T10:00') }, * { start: new Date('2024-01-15T10:00'), end: new Date('2024-01-15T11:00') } * ]; * const merged = mergeBookings(bookings); * // [{ start: 09:00, end: 11:00 }] * ``` */ export declare function mergeBookings(bookings: Booking[]): Booking[]; /** * Splits a slot at a specific time * @param slot - The slot to split * @param at - The time to split at * @returns Tuple of two slots, or null if split point is outside slot * * @example * ```ts * const slot = { start: new Date('2024-01-15T09:00'), end: new Date('2024-01-15T11:00'), available: true }; * const [before, after] = splitSlot(slot, new Date('2024-01-15T10:00')); * // before: 09:00-10:00, after: 10:00-11:00 * ``` */ export declare function splitSlot(slot: Slot, at: DateInput): [Slot, Slot] | null; //# sourceMappingURL=scheduling.d.ts.map