@uplink-protocol/calendar-controller
Version:
Flexible calendar and time picker API supporting both calendar, date-picker, and time-picker integrations for any JavaScript framework or library
93 lines (92 loc) • 3.04 kB
TypeScript
/**
* Time utility functions
* Provides common time manipulation and formatting utilities
*/
/**
* Check if two times are the same (ignoring date part)
* @param time1 First time
* @param time2 Second time
* @returns Whether times are the same
*/
export declare function isSameTime(time1: Date, time2: Date): boolean;
/**
* Check if a time is within a range
* @param time Time to check
* @param startTime Range start time
* @param endTime Range end time
* @returns Whether time is in range
*/
export declare function isTimeInRange(time: Date, startTime: Date, endTime: Date): boolean;
/**
* Get time-only milliseconds (ignoring date part)
* @param time Date object
* @returns Milliseconds since midnight
*/
export declare function getTimeOnlyMs(time: Date): number;
/**
* Format time to string
* @param time Time to format
* @param format Format string
* @returns Formatted time string
*/
export declare function formatTime(time: Date, format?: string): string;
/**
* Parse time string to Date object
* @param timeString Time string to parse
* @returns Parsed Date object or null if invalid
*/
export declare function parseTime(timeString: string): Date | null;
/**
* Convert 24-hour to 12-hour format
* @param hour24 Hour in 24-hour format (0-23)
* @returns Object with hour12 (1-12) and period ('AM'|'PM')
*/
export declare function convertTo12Hour(hour24: number): {
hour12: number;
period: 'AM' | 'PM';
};
/**
* Convert 12-hour to 24-hour format
* @param hour12 Hour in 12-hour format (1-12)
* @param period AM or PM
* @returns Hour in 24-hour format (0-23)
*/
export declare function convertTo24Hour(hour12: number, period: 'AM' | 'PM'): number;
/**
* Get current time with only time components (no date)
* @returns Date object with today's date but current time
*/
export declare function getCurrentTimeOnly(): Date;
/**
* Round time to nearest step interval
* @param time Input time
* @param minuteStep Step interval for minutes
* @param secondStep Step interval for seconds
* @returns Rounded time
*/
export declare function roundTimeToStep(time: Date, minuteStep?: number, secondStep?: number): Date;
/**
* Create time from components
* @param hours Hours (0-23)
* @param minutes Minutes (0-59)
* @param seconds Seconds (0-59)
* @param milliseconds Milliseconds (0-999)
* @returns Date object with specified time
*/
export declare function createTime(hours: number, minutes: number, seconds?: number, milliseconds?: number): Date;
/**
* Add time duration to a time
* @param time Base time
* @param hours Hours to add
* @param minutes Minutes to add
* @param seconds Seconds to add
* @returns New time with added duration
*/
export declare function addTime(time: Date, hours?: number, minutes?: number, seconds?: number): Date;
/**
* Get time difference in milliseconds
* @param time1 First time
* @param time2 Second time
* @returns Difference in milliseconds (time1 - time2)
*/
export declare function getTimeDifference(time1: Date, time2: Date): number;