UNPKG

@kitiumai/utils-ts

Version:

Comprehensive TypeScript utilities for KitiumAI projects

218 lines 5.25 kB
/** * Date utility functions */ /** * Format a date to a string * * @param date - The date to format * @param format - Format string (default: ISO string) * @returns Formatted date string * * @example * ```ts * formatDate(new Date(2024, 0, 1), 'YYYY-MM-DD') // '2024-01-01' * ``` */ export declare function formatDate(date: Date, format?: string): string; /** * Parse a date string * * @param dateString - The date string to parse * @returns Parsed Date object, or null if invalid * * @example * ```ts * parseDate('2024-01-01') // Date object * ``` */ export declare function parseDate(dateString: string): Date | null; /** * Add days to a date * * @param date - The date to add to * @param days - Number of days to add (can be negative) * @returns A new Date object * * @example * ```ts * addDays(new Date(2024, 0, 1), 5) // Date 5 days later * ``` */ export declare function addDays(date: Date, days: number): Date; /** * Add months to a date * * @param date - The date to add to * @param months - Number of months to add (can be negative) * @returns A new Date object * * @example * ```ts * addMonths(new Date(2024, 0, 1), 2) // Date 2 months later * ``` */ export declare function addMonths(date: Date, months: number): Date; /** * Add years to a date * * @param date - The date to add to * @param years - Number of years to add (can be negative) * @returns A new Date object * * @example * ```ts * addYears(new Date(2024, 0, 1), 1) // Date 1 year later * ``` */ export declare function addYears(date: Date, years: number): Date; /** * Get the start of day (00:00:00) * * @param date - The date * @returns A new Date object at start of day * * @example * ```ts * startOfDay(new Date(2024, 0, 1, 15, 30)) // Date at 00:00:00 * ``` */ export declare function startOfDay(date: Date): Date; /** * Get the end of day (23:59:59.999) * * @param date - The date * @returns A new Date object at end of day * * @example * ```ts * endOfDay(new Date(2024, 0, 1, 15, 30)) // Date at 23:59:59.999 * ``` */ export declare function endOfDay(date: Date): Date; /** * Check if date1 is before date2 * * @param date1 - First date * @param date2 - Second date * @returns True if date1 is before date2 * * @example * ```ts * isBefore(new Date(2024, 0, 1), new Date(2024, 0, 2)) // true * ``` */ export declare function isBefore(date1: Date, date2: Date): boolean; /** * Check if date1 is after date2 * * @param date1 - First date * @param date2 - Second date * @returns True if date1 is after date2 * * @example * ```ts * isAfter(new Date(2024, 0, 2), new Date(2024, 0, 1)) // true * ``` */ export declare function isAfter(date1: Date, date2: Date): boolean; /** * Check if two dates are the same (same day) * * @param date1 - First date * @param date2 - Second date * @returns True if dates are the same day * * @example * ```ts * isSameDay(new Date(2024, 0, 1), new Date(2024, 0, 1, 15, 30)) // true * ``` */ export declare function isSameDay(date1: Date, date2: Date): boolean; /** * Calculate difference in days between two dates * * @param date1 - First date * @param date2 - Second date * @returns Number of days difference (can be negative) * * @example * ```ts * differenceInDays(new Date(2024, 0, 5), new Date(2024, 0, 1)) // 4 * ``` */ export declare function differenceInDays(date1: Date, date2: Date): number; /** * Calculate difference in hours between two dates * * @param date1 - First date * @param date2 - Second date * @returns Number of hours difference (can be negative) * * @example * ```ts * differenceInHours(new Date(2024, 0, 1, 5), new Date(2024, 0, 1, 1)) // 4 * ``` */ export declare function differenceInHours(date1: Date, date2: Date): number; /** * Calculate difference in minutes between two dates * * @param date1 - First date * @param date2 - Second date * @returns Number of minutes difference (can be negative) * * @example * ```ts * differenceInMinutes(new Date(2024, 0, 1, 0, 5), new Date(2024, 0, 1, 0, 1)) // 4 * ``` */ export declare function differenceInMinutes(date1: Date, date2: Date): number; /** * Get the start of month * * @param date - The date * @returns A new Date object at start of month * * @example * ```ts * startOfMonth(new Date(2024, 0, 15)) // Date at 2024-01-01 00:00:00 * ``` */ export declare function startOfMonth(date: Date): Date; /** * Get the end of month * * @param date - The date * @returns A new Date object at end of month * * @example * ```ts * endOfMonth(new Date(2024, 0, 15)) // Date at 2024-01-31 23:59:59.999 * ``` */ export declare function endOfMonth(date: Date): Date; /** * Get the start of year * * @param date - The date * @returns A new Date object at start of year * * @example * ```ts * startOfYear(new Date(2024, 5, 15)) // Date at 2024-01-01 00:00:00 * ``` */ export declare function startOfYear(date: Date): Date; /** * Get the end of year * * @param date - The date * @returns A new Date object at end of year * * @example * ```ts * endOfYear(new Date(2024, 5, 15)) // Date at 2024-12-31 23:59:59.999 * ``` */ export declare function endOfYear(date: Date): Date; //# sourceMappingURL=date.d.ts.map