UNPKG

scheduling-sdk

Version:

Brought to you by Recal - A TypeScript SDK for scheduling functionality

55 lines 2.24 kB
/** * Timezone utility functions for handling timezone-aware date conversions. * Uses native JavaScript Date API and Intl.DateTimeFormat for zero-dependency timezone support. */ /** * Converts a time string (HH:mm) in a specific timezone to a UTC Date object for a given date. * * @param timeStr - Time string in HH:mm format (e.g., "09:00", "14:30") * @param date - The date to apply the time to (timezone will be ignored, only year/month/day used) * @param timezone - IANA timezone identifier (e.g., "America/New_York", "Europe/London") * @returns UTC Date object representing the specified time in the given timezone * * @throws {Error} If timezone is invalid or time format is invalid * * @example * ```typescript * // 9 AM New York time on Jan 15, 2024 * const date = new Date('2024-01-15') * const utcDate = convertTimeStringToUTC('09:00', date, 'America/New_York') * // Returns UTC date representing 9 AM EST (2 PM UTC) or 9 AM EDT (1 PM UTC) depending on DST * ``` */ export declare function convertTimeStringToUTC(timeStr: string, date: Date, timezone: string): Date; /** * Creates a Date object representing a specific time on a given date in a timezone. * * @param date - Base date (year/month/day will be used) * @param hours - Hours (0-23) * @param minutes - Minutes (0-59) * @param timezone - IANA timezone identifier * @returns UTC Date object representing the specified time in the given timezone * * @example * ```typescript * const date = new Date('2024-01-15') * const utcDate = createDateInTimezone(date, 9, 30, 'America/New_York') * // Returns UTC date representing 9:30 AM New York time * ``` */ export declare function createDateInTimezone(date: Date, hours: number, minutes: number, timezone: string): Date; /** * Validates that a timezone string is a valid IANA timezone identifier. * * @param timezone - Timezone string to validate * @returns true if valid, false otherwise * * @example * ```typescript * isValidTimezone('America/New_York') // true * isValidTimezone('EST') // false (not IANA format) * isValidTimezone('Invalid/Timezone') // false * ``` */ export declare function isValidTimezone(timezone: string): boolean; //# sourceMappingURL=timezone.d.ts.map