/** * Calendar Utilities * * Pure TypeScript utilities for calendar month generation and localization. * Ported from ClojureScript ty/date/core.cljs * * Key Features: * - 42-day calendar grid generation (6 weeks × 7 days) * - Monday-first week ordering * - Rich day context with metadata * - Localized weekday names * - No external dependencies (native Date API only) * * Note on Timestamps: * - `value`: UTC timestamp at midnight UTC (timezone-independent, use for storage/server) * - `localValue`: Local timestamp at midnight local time (use for display/local calculations) * - `year/month/dayInMonth`: Calendar date components (user's mental model) * * Example for October 13, 2025: * - value = Date.UTC(2025, 9, 13) = consistent worldwide * - localValue = new Date(2025, 9, 13).getTime() = varies by timezone * - Both represent the same calendar date, different moments in time */ /** * Rich context for a single calendar day * Contains all metadata needed for rendering and event handling */ export interface DayContext { /** Timestamp in milliseconds (UTC midnight) - use for server communication and storage */ value: number; /** Timestamp in milliseconds (local midnight) - use for local calculations and display */ localValue: number; /** Year (e.g., 2025) */ year: number; /** Month (1-12, 1 = January) */ month: number; /** Day of month (1-31) */ dayInMonth: number; /** Is this a weekend day? (Saturday or Sunday) */ weekend: boolean; /** Is this day from a different month? */ otherMonth: boolean; /** Is this from the previous month? */ prevMonth?: boolean; /** Is this from the next month? */ nextMonth?: boolean; /** Is this today? */ today?: boolean; /** Is this a holiday? (extensible for future use) */ holiday?: boolean; /** Is this day selected? (from calendar's internal state) */ isSelected?: boolean; /** Calendar's selected year (if any) */ selectedYear?: number; /** Calendar's selected month (if any) */ selectedMonth?: number; /** Calendar's selected day (if any) */ selectedDay?: number; } /** * Generate a 42-day calendar grid for a given month * * Returns 6 weeks (42 days) starting from the Monday at or before * the first day of the month. This ensures a complete calendar view * with days from the previous and next months as needed. * * @param year - Year (e.g., 2025) * @param month - Month (1-12, 1 = January) * @param selection - Optional selection state to include in day contexts * @returns Array of 42 day contexts with rich metadata * * @throws {RangeError} If year or month are invalid * * @example * const days = getCalendarMonthDays(2025, 10); // October 2025 * console.log(days.length); // 42 * console.log(days[0].dayInMonth); // First day shown (might be from September) */ export declare function getCalendarMonthDays(year: number, month: number, selection?: { year?: number; month?: number; day?: number; }): DayContext[]; /** * Get localized weekday names in Monday-first order * * Note: Intl.DateTimeFormat returns Sunday-first by default, * so we reorder to Monday-first: [Mon, Tue, Wed, Thu, Fri, Sat, Sun] * * @param locale - Locale string (e.g., "en-US", "de-DE", "ja-JP") * @param style - Display style: "long" (Monday), "short" (Mon), "narrow" (M) * @returns Array of 7 weekday names starting with Monday * * @example * getLocalizedWeekdays("en-US", "short") * // Returns: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] * * getLocalizedWeekdays("de-DE", "long") * // Returns: ["Montag", "Dienstag", "Mittwoch", ...] */ export declare function getLocalizedWeekdays(locale: string, style?: 'long' | 'short' | 'narrow'): string[]; /** * Get month name in specified locale * * @param month - Month (1-12) * @param locale - Locale string * @param style - Display style * @returns Localized month name * * @throws {RangeError} If month is invalid */ export declare function getMonthName(month: number, locale?: string, style?: 'long' | 'short' | 'narrow'): string; /** * Format a day context as an ISO date string * * @param dayContext - Day context to format * @returns ISO date string (YYYY-MM-DD) * * @example * formatDayContext({ year: 2025, month: 10, dayInMonth: 13, ... }) * // Returns: "2025-10-13" */ export declare function formatDayContext(dayContext: DayContext): string; /** * Check if a day context matches a specific date * * @param dayContext - Day context to check * @param year - Target year * @param month - Target month (1-12) * @param day - Target day * @returns True if the day context matches * * @example * isDayContext(dayCtx, 2025, 10, 13) // true if context is Oct 13, 2025 */ export declare function isDayContext(dayContext: DayContext, year: number, month: number, day: number): boolean; /** * Parse an ISO date string (YYYY-MM-DD) into year, month, day components * * @param isoString - ISO date string (YYYY-MM-DD) * @returns Object with year, month (1-12), and day, or null if invalid * * @example * parseISODate("2025-10-13") * // Returns: { year: 2025, month: 10, day: 13 } */ export declare function parseISODate(isoString: string): { year: number; month: number; day: number; } | null; /** * Convert a UTC timestamp to an ISO date string * Interprets the timestamp as UTC midnight and returns the date * * @param utcTimestamp - UTC timestamp in milliseconds * @returns ISO date string (YYYY-MM-DD) * * @example * const ctx = getCalendarMonthDays(2025, 10)[0]; * utcTimestampToISO(ctx.value) // "2025-10-13" */ export declare function utcTimestampToISO(utcTimestamp: number): string; /** * Convert a local timestamp to an ISO date string * Interprets the timestamp in local timezone and returns the date * * @param localTimestamp - Local timestamp in milliseconds * @returns ISO date string (YYYY-MM-DD) * * @example * const ctx = getCalendarMonthDays(2025, 10)[0]; * localTimestampToISO(ctx.localValue) // "2025-10-13" */ export declare function localTimestampToISO(localTimestamp: number): string; //# sourceMappingURL=calendar-utils.d.ts.map