@taskgenius/calendar
Version:
A lightweight, configurable TypeScript calendar component with drag-and-drop support
74 lines (70 loc) • 2.72 kB
TypeScript
/**
* Abstract date adapter interface for pluggable date libraries
*/
declare interface DateAdapter<T> {
/** Create a date from various inputs */
create(date?: string | Date | T): T;
/** Parse a date string with optional format */
parse(dateStr: string, format?: string): T;
/** Format a date to string */
format(date: T, format: string): string;
/** Get year */
year(date: T): number;
/** Get month (0-11) */
month(date: T): number;
/** Get day of month (1-31) */
date(date: T): number;
/** Get day of week (0-6, Sunday = 0) */
day(date: T): number;
/** Get hour (0-23) */
hour(date: T): number;
/** Get minute (0-59) */
minute(date: T): number;
/** Set hour and return new date */
setHour(date: T, hour: number): T;
/** Set minute and return new date */
setMinute(date: T, minute: number): T;
/** Add time to date */
add(date: T, amount: number, unit: TimeUnit): T;
/** Calculate difference between dates */
diff(date1: T, date2: T, unit: TimeUnit): number;
/** Get start of time unit */
startOf(date: T, unit: TimeUnit): T;
/** Get end of time unit */
endOf(date: T, unit: TimeUnit): T;
/** Check if date1 is before date2 */
isBefore(date1: T, date2: T, unit?: TimeUnit): boolean;
/** Check if date1 is after date2 */
isAfter(date1: T, date2: T, unit?: TimeUnit): boolean;
/** Check if dates are the same */
isSame(date1: T, date2: T, unit?: TimeUnit): boolean;
}
/**
* Native JavaScript Date adapter implementation
* Zero dependencies, uses built-in Date API
*/
export declare class NativeDateAdapter implements DateAdapter<Date> {
create(date?: string | Date): Date;
parse(dateStr: string, _format?: string): Date;
format(date: Date, format: string): string;
year(date: Date): number;
month(date: Date): number;
date(date: Date): number;
day(date: Date): number;
hour(date: Date): number;
minute(date: Date): number;
setHour(date: Date, hour: number): Date;
setMinute(date: Date, minute: number): Date;
add(date: Date, amount: number, unit: TimeUnit): Date;
diff(date1: Date, date2: Date, unit: TimeUnit): number;
startOf(date: Date, unit: TimeUnit): Date;
endOf(date: Date, unit: TimeUnit): Date;
isBefore(date1: Date, date2: Date, unit?: TimeUnit): boolean;
isAfter(date1: Date, date2: Date, unit?: TimeUnit): boolean;
isSame(date1: Date, date2: Date, unit?: TimeUnit): boolean;
}
/**
* Time unit for date operations
*/
declare type TimeUnit = "year" | "month" | "week" | "day" | "hour" | "minute";
export { }