UNPKG

@taskgenius/calendar

Version:

A lightweight, configurable TypeScript calendar component with drag-and-drop support

80 lines (74 loc) 2.85 kB
/** * 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; } declare type DateFns = any; /** * date-fns adapter implementation * Requires date-fns to be installed as a peer dependency */ export declare class DateFnsAdapter implements DateAdapter<DateFnsDate> { private fns; constructor(dateFns: DateFns); create(date?: string | Date): Date; parse(dateStr: string, formatStr?: string): Date; format(date: Date, formatStr: 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; } declare type DateFnsDate = Date; /** * Time unit for date operations */ declare type TimeUnit = "year" | "month" | "week" | "day" | "hour" | "minute"; export { }