/** * Temporal Query Evaluator for TONL Query API * * Provides temporal query capabilities including: * - Date literal parsing (@2025-01-15, @now, @now-7d) * - Temporal comparison operators (before, after, between) * - Relative time expressions (daysAgo, weeksAgo, monthsAgo) * - ISO 8601 duration support * * @example * ```typescript * // Query filters with temporal expressions: * doc.query("events[?(@.date > @now-7d)]") // Last 7 days * doc.query("events[?(@.date between @2025-01-01 @2025-12-31)]") * doc.query("posts[?(@.publishedAt before @now)]") * ``` */ /** * Parsed temporal value */ export interface TemporalValue { /** * Unix timestamp in milliseconds */ timestamp: number; /** * JavaScript Date object */ date: Date; /** * ISO 8601 string representation */ iso: string; /** * Original input string */ original: string; /** * Whether this is a relative time expression */ isRelative: boolean; } /** * Duration value (ISO 8601 duration) */ export interface DurationValue { years: number; months: number; weeks: number; days: number; hours: number; minutes: number; seconds: number; milliseconds: number; } /** * Temporal query options */ export interface TemporalOptions { /** * Timezone for date parsing (default: local) */ timezone?: string; /** * Reference time for relative expressions (default: now) */ referenceTime?: Date | number; /** * Whether to use start of day for date-only values * @default true */ startOfDay?: boolean; /** * Whether to use end of day for date-only comparisons * @default false */ endOfDay?: boolean; } /** * Parse a temporal literal string * * Supports: * - ISO 8601 dates: @2025-01-15, @2025-01-15T10:30:00Z * - Relative expressions: @now, @now-7d, @now+1w, @now-3M * - Named dates: @today, @yesterday, @tomorrow * * @param input - Temporal literal string (with or without @ prefix) * @param options - Parsing options * @returns Parsed temporal value * * @example * ```typescript * parseTemporalLiteral("@2025-01-15") // Specific date * parseTemporalLiteral("@now") // Current time * parseTemporalLiteral("@now-7d") // 7 days ago * parseTemporalLiteral("@now+2w") // 2 weeks from now * parseTemporalLiteral("@today") // Start of today * ``` */ export declare function parseTemporalLiteral(input: string, options?: TemporalOptions): TemporalValue; /** * Parse ISO 8601 duration string * * @param input - Duration string (e.g., "P1Y2M3D", "PT1H30M") * @returns Parsed duration value * * @example * ```typescript * parseDuration("P1Y") // 1 year * parseDuration("P1M") // 1 month * parseDuration("P1D") // 1 day * parseDuration("PT1H") // 1 hour * parseDuration("PT1H30M") // 1 hour 30 minutes * parseDuration("P1Y2M3DT4H5M6S") // Full duration * ``` */ export declare function parseDuration(input: string): DurationValue; /** * Convert duration to milliseconds * * Note: Months and years are approximate (30 days, 365 days) */ export declare function durationToMilliseconds(duration: DurationValue): number; /** * Add duration to a date */ export declare function addDuration(date: Date, duration: DurationValue): Date; /** * Subtract duration from a date */ export declare function subtractDuration(date: Date, duration: DurationValue): Date; /** * Get start of day */ export declare function startOfDay(date: Date): Date; /** * Get end of day */ export declare function endOfDay(date: Date): Date; /** * Get start of week (Monday) */ export declare function startOfWeek(date: Date): Date; /** * Get end of week (Sunday) */ export declare function endOfWeek(date: Date): Date; /** * Get start of month */ export declare function startOfMonth(date: Date): Date; /** * Get end of month */ export declare function endOfMonth(date: Date): Date; /** * Get start of year */ export declare function startOfYear(date: Date): Date; /** * Get end of year */ export declare function endOfYear(date: Date): Date; /** * Parse a value as temporal (Date, number timestamp, or string) */ export declare function toTemporalValue(value: any, options?: TemporalOptions): TemporalValue | null; /** * Compare two temporal values * * @returns Negative if a < b, positive if a > b, 0 if equal */ export declare function compareTemporalValues(a: TemporalValue, b: TemporalValue): number; /** * Check if date A is before date B */ export declare function isBefore(a: any, b: any, options?: TemporalOptions): boolean; /** * Check if date A is after date B */ export declare function isAfter(a: any, b: any, options?: TemporalOptions): boolean; /** * Check if date is between two dates (inclusive) */ export declare function isBetween(date: any, start: any, end: any, options?: TemporalOptions): boolean; /** * Check if date is within N days ago */ export declare function isDaysAgo(date: any, days: number, options?: TemporalOptions): boolean; /** * Check if date is within N weeks ago */ export declare function isWeeksAgo(date: any, weeks: number, options?: TemporalOptions): boolean; /** * Check if date is within N months ago */ export declare function isMonthsAgo(date: any, months: number, options?: TemporalOptions): boolean; /** * Check if date is within N years ago */ export declare function isYearsAgo(date: any, years: number, options?: TemporalOptions): boolean; /** * Check if two dates are on the same day */ export declare function isSameDay(a: any, b: any, options?: TemporalOptions): boolean; /** * Check if two dates are in the same week */ export declare function isSameWeek(a: any, b: any, options?: TemporalOptions): boolean; /** * Check if two dates are in the same month */ export declare function isSameMonth(a: any, b: any, options?: TemporalOptions): boolean; /** * Check if two dates are in the same year */ export declare function isSameYear(a: any, b: any, options?: TemporalOptions): boolean; /** * Evaluate temporal operator in filter expression * * Used internally by filter-evaluator.ts * * @param operator - Temporal operator type * @param left - Left operand (date value from document) * @param right - Right operand (temporal literal or date) * @param extra - Extra argument (for between operator) * @returns Boolean result */ export declare function evaluateTemporalOperator(operator: string, left: any, right: any, extra?: any): boolean; /** * Check if an operator is a temporal operator */ export declare function isTemporalOperator(operator: string): boolean; /** * Check if a string looks like a temporal literal */ export declare function isTemporalLiteral(value: string): boolean; //# sourceMappingURL=temporal-evaluator.d.ts.map