/** * Time Utilities * Helper functions for time operations, formatting, and date manipulation * Combines interval-based time operations with convenient date utilities */ import type { TimeComponents, TimeConfig, TimeInterval } from '@plyaz/types/api'; /** * Get quarter of the year * * @param date - Date to get quarter for * @returns Quarter number (1-4) */ export declare function getQuarter(date: Date): number; /** * Get ISO week number for a date * * @param date - Date to get week number for * @returns ISO week number (1-53) */ export declare function getISOWeek(date: Date): number; /** * Get time components from a date * * @param config - Time configuration * @returns Time components for formatting */ export declare function getTimeComponents(config?: TimeConfig): TimeComponents; /** * Format time for a specific interval * * @param interval - Time interval to format for * @param config - Configuration options * @param separator - Separator for formatted parts * @returns Formatted time string * * @example * ```typescript * formatTimeForInterval('hour'); // "2024-0-15-14" * formatTimeForInterval('week'); // "2024-W3" * formatTimeForInterval('quarter'); // "2024-Q1" * ``` */ export declare function formatTimeForInterval(interval: TimeInterval, config?: TimeConfig, separator?: string): string; /** * Get start of a time interval * * @param interval - Time interval * @param date - Date to get start for * @returns Date at the start of the interval * * @example * ```typescript * const startOfDay = getIntervalStart('day', new Date()); * const startOfWeek = getIntervalStart('week', new Date()); * ``` */ export declare function getIntervalStart(interval: TimeInterval, date?: Date): Date; /** * Get end of a time interval * * @param interval - Time interval * @param date - Date to get end for * @returns Date at the end of the interval * * @example * ```typescript * const endOfDay = getIntervalEnd('day', new Date()); * const endOfMonth = getIntervalEnd('month', new Date()); * ``` */ export declare function getIntervalEnd(interval: TimeInterval, date?: Date): Date; /** * Add intervals to a date * * @param date - Starting date * @param interval - Time interval to add * @param count - Number of intervals to add * @returns New date with intervals added * * @example * ```typescript * const tomorrow = addInterval(new Date(), 'day', 1); * const nextWeek = addInterval(new Date(), 'week', 1); * const nextQuarter = addInterval(new Date(), 'quarter', 1); * ``` */ export declare function addInterval(date: Date, interval: TimeInterval, count: number): Date; /** * Get all interval boundaries within a range * * @param interval - Time interval * @param startDate - Start of range * @param endDate - End of range * @returns Array of dates at interval boundaries * * @example * ```typescript * // Get all hour boundaries for today * const hours = getIntervalBoundaries('hour', startOfDay, endOfDay); * ``` */ export declare function getIntervalBoundaries(interval: TimeInterval, startDate: Date, endDate: Date): Date[]; /** * Check if two dates are in the same interval * * @param date1 - First date * @param date2 - Second date * @param interval - Time interval to check * @returns True if dates are in the same interval * * @example * ```typescript * const sameDay = isSameInterval(date1, date2, 'day'); * const sameWeek = isSameInterval(date1, date2, 'week'); * ``` */ export declare function isSameInterval(date1: Date, date2: Date, interval: TimeInterval): boolean; /** * Get the difference between two dates in a specific interval * * @param date1 - First date * @param date2 - Second date * @param interval - Time interval for the difference * @returns Number of intervals between dates * * @example * ```typescript * const days = getIntervalDifference(startDate, endDate, 'day'); * const weeks = getIntervalDifference(startDate, endDate, 'week'); * ``` */ export declare function getIntervalDifference(date1: Date, date2: Date, interval: TimeInterval): number; /** * Get a human-readable relative time string * * @param date - Date to format * @param baseDate - Base date to compare against (defaults to now) * @returns Relative time string * * @example * ```typescript * getRelativeTime(yesterday); // "1 day ago" * getRelativeTime(nextWeek); // "in 1 week" * ``` */ export declare function getRelativeTime(date: Date, baseDate?: Date): string; export declare function formatDuration(ms: number, options?: { compact?: boolean; units?: number; }): string; /** * Get current timestamp in milliseconds * Uses globalThis.Date to work with fake timers in tests */ export declare function now(): number; /** * Get current timestamp in seconds */ export declare function nowInSeconds(): number; /** * Create a new Date object (safer than new Date()) */ export declare function createDate(value?: string | number | Date): Date; /** * Check if date is valid */ export declare function isValidDate(date: Date): boolean; /** * Format timestamp as relative time (e.g., "2 minutes ago") * Alternative implementation to getRelativeTime with different format */ export declare function timeAgo(timestamp: number | Date): string; /** * Convert milliseconds to seconds */ export declare function msToSeconds(ms: number): number; /** * Convert seconds to milliseconds */ export declare function secondsToMs(seconds: number): number; /** * Add time to date */ export declare function addTime(date: Date, amount: number, unit: 'ms' | 's' | 'm' | 'h' | 'd'): Date; /** * Check if date is in the past */ export declare function isPast(date: Date): boolean; /** * Check if date is in the future */ export declare function isFuture(date: Date): boolean; /** * Check if date is today */ export declare function isToday(date: Date): boolean; /** * Get start of day for a date * Alias for getIntervalStart('day', date) */ export declare function startOfDay(date: Date): Date; /** * Get end of day for a date * Alias for getIntervalEnd('day', date) */ export declare function endOfDay(date: Date): Date; /** * Format date as ISO string */ export declare function toISOString(date: Date): string; /** * Parse ISO string to Date */ export declare function fromISOString(iso: string): Date; /** * Get unix timestamp (seconds) */ export declare function getUnixTimestamp(date?: Date): number; /** * Create Date from unix timestamp (seconds) */ export declare function fromUnixTimestamp(timestamp: number): Date; /** * Get difference between two dates in specified unit * Alternative to getIntervalDifference with different unit types */ export declare function dateDiff(date1: Date, date2: Date, unit?: 'ms' | 's' | 'm' | 'h' | 'd'): number; /** * Check if two dates are on the same day * Alias for isSameInterval(date1, date2, 'day') */ export declare function isSameDay(date1: Date, date2: Date): boolean; //# sourceMappingURL=time.d.ts.map