scheduling-sdk
Version:
Brought to you by Recal - A TypeScript SDK for scheduling functionality
51 lines • 2.21 kB
TypeScript
import type { WeeklyAvailability } from '../../types/availability.types';
import type { BusyTime } from '../../types/scheduling.types';
/**
* Converts a weekly availability pattern into busy times for a specific week.
*
* This function inverts the availability concept: it takes available time periods
* and generates busy times for all the unavailable periods. For example, if you're
* available Monday 9-17, it creates busy times for Monday 0-9 and 17-24, plus
* all day Tuesday through Sunday.
*
* Automatically chooses between legacy per-day processing and timezone-aware
* week-wide processing based on whether cross-day boundary issues are possible.
*
* @param availability - The weekly availability pattern to convert
* @param weekStart - The Monday date for the week to process (MUST be a Monday)
* @param timezone - IANA timezone identifier for processing availability times
*
* @returns Array of busy times representing unavailable periods for that week
*
* @throws {Error} If weekStart is not a Monday (getDay() !== 1)
* @throws {Error} If availability contains invalid time formats or ranges
* @throws {Error} If timezone is invalid
*
* @example
* ```typescript
* const availability = {
* schedules: [
* { days: ['monday', 'wednesday', 'friday'], start: '09:00', end: '17:00' },
* { days: ['tuesday', 'thursday'], start: '10:00', end: '16:00' }
* ],
* timezone: 'America/New_York'
* }
*
* const mondayDate = new Date('2024-01-01T00:00:00Z') // Must be Monday
* const busyTimes = weeklyAvailabilityToBusyTimes(availability, mondayDate)
*
* // Returns busy times for:
* // - Monday: 00:00-14:00, 22:00-23:59 (9 AM - 5 PM NY time converted to UTC)
* // - Tuesday: 00:00-15:00, 21:00-23:59 (10 AM - 4 PM NY time converted to UTC)
* // etc.
* ```
*
* @example
* ```typescript
* // Override timezone at call time
* const busyTimes = weeklyAvailabilityToBusyTimes(availability, mondayDate, 'Europe/London')
* // Uses London time regardless of availability.timezone
* ```
*/
export declare function weeklyAvailabilityToBusyTimes(availability: WeeklyAvailability, weekStart: Date, timezone?: string): BusyTime[];
//# sourceMappingURL=converter.d.ts.map