/** * Fluent chain API for ts-time-utils * * Provides a chainable interface for date operations: * ```ts * chain(new Date()) * .add(1, 'day') * .startOf('month') * .format('YYYY-MM-DD') * ``` */ import type { TimeUnit, DateInput, FormatOptions } from './types.js'; /** Units accepted by startOf/endOf */ type StartOfUnit = 'day' | 'week' | 'month' | 'year' | 'hour' | 'minute'; /** * Immutable chainable date wrapper * All transformation methods return a new ChainedDate instance */ export declare class ChainedDate { private readonly _date; constructor(date?: DateInput); /** * Add time to the date * @example chain(date).add(1, 'day').add(2, 'hours') */ add(amount: number, unit: TimeUnit): ChainedDate; /** * Subtract time from the date * @example chain(date).subtract(1, 'week') */ subtract(amount: number, unit: TimeUnit): ChainedDate; /** * Get the start of a time period * @example chain(date).startOf('month') */ startOf(unit: StartOfUnit): ChainedDate; /** * Get the end of a time period * @example chain(date).endOf('day') */ endOf(unit: StartOfUnit): ChainedDate; /** * Set specific date/time components * @example chain(date).set({ year: 2025, month: 1 }) */ set(values: { year?: number; month?: number; day?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }): ChainedDate; /** * Clone the ChainedDate */ clone(): ChainedDate; /** * Format date using pattern string * @example chain(date).format('YYYY-MM-DD') // "2025-01-15" */ format(pattern: string): string; /** * Format time in 12h, 24h, or ISO format * @example chain(date).formatTime('12h') // "2:30 PM" */ formatTime(fmt?: '12h' | '24h' | 'iso'): string; /** * Format as calendar date (Today, Yesterday, Monday, etc.) * @example chain(date).calendar() // "Tomorrow" */ calendar(): string; /** * Get relative time string * @example chain(pastDate).ago() // "3 hours ago" */ ago(options?: FormatOptions): string; /** * Get ISO string */ toISOString(): string; /** * Get locale string */ toLocaleString(locale?: string, options?: Intl.DateTimeFormatOptions): string; /** * Format day as ordinal * @example chain(date).dayOrdinal() // "15th" */ dayOrdinal(): string; /** * Check if date is valid */ isValid(): boolean; /** * Check if date is today */ isToday(): boolean; /** * Check if date is yesterday */ isYesterday(): boolean; /** * Check if date is tomorrow */ isTomorrow(): boolean; /** * Check if date is in the past */ isPast(): boolean; /** * Check if date is in the future */ isFuture(): boolean; /** * Check if date is a weekend */ isWeekend(): boolean; /** * Check if date is a weekday */ isWeekday(): boolean; /** * Check if date is in this week */ isThisWeek(): boolean; /** * Check if date is in this month */ isThisMonth(): boolean; /** * Check if date is in this year */ isThisYear(): boolean; /** * Check if year is a leap year */ isLeapYear(): boolean; /** * Check if date is a business day */ isBusinessDay(holidays?: Date[]): boolean; /** * Check if date is same day as another */ isSameDay(other: DateInput): boolean; /** * Check if date is same week as another */ isSameWeek(other: DateInput): boolean; /** * Check if date is same month as another */ isSameMonth(other: DateInput): boolean; /** * Check if date is same year as another */ isSameYear(other: DateInput): boolean; /** * Check if date is before another */ isBefore(other: DateInput): boolean; /** * Check if date is after another */ isAfter(other: DateInput): boolean; /** * Check if date is between two dates */ isBetween(start: DateInput, end: DateInput, inclusive?: boolean): boolean; /** * Get difference from another date * @example chain(date).diff(other, 'days') // 5 */ diff(other: DateInput, unit?: TimeUnit, precise?: boolean): number; /** * Get the timestamp (milliseconds since epoch) */ valueOf(): number; /** * Get year */ year(): number; /** * Get month (1-12) */ month(): number; /** * Get day of month (1-31) */ day(): number; /** * Get day of week (0-6, 0=Sunday) */ weekday(): number; /** * Get hours (0-23) */ hours(): number; /** * Get minutes (0-59) */ minutes(): number; /** * Get seconds (0-59) */ seconds(): number; /** * Get milliseconds (0-999) */ milliseconds(): number; /** * Get day of year (1-366) */ dayOfYear(): number; /** * Get ISO week number (1-53) */ week(): number; /** * Get quarter (1-4) */ quarter(): number; /** * Get days in month */ daysInMonth(): number; /** * Get the underlying Date object */ toDate(): Date; /** * Get Unix timestamp (seconds) */ unix(): number; /** * Convert to array [year, month, day, hours, minutes, seconds, ms] */ toArray(): [number, number, number, number, number, number, number]; /** * Convert to object */ toObject(): { year: number; month: number; day: number; hours: number; minutes: number; seconds: number; milliseconds: number; }; } /** * Create a chainable date wrapper * @example * chain(new Date()).add(1, 'day').format('YYYY-MM-DD') * chain('2025-01-15').startOf('month').toDate() * chain().add(1, 'week').isWeekend() */ export declare function chain(date?: DateInput): ChainedDate; /** * Format a duration in milliseconds * Convenience export for use with chain().diff() * @example formatMs(chain(a).diff(b)) // "2 days, 3 hours" */ export declare function formatMs(ms: number, options?: FormatOptions): string; export {}; //# sourceMappingURL=chain.d.ts.map