149 lines
4.9 KiB
TypeScript
149 lines
4.9 KiB
TypeScript
/**
|
|
* DateCalculator - Centralized date calculation logic for calendar
|
|
* Handles all date computations with proper week start handling
|
|
*/
|
|
import { CalendarConfig } from '../core/CalendarConfig';
|
|
export declare class DateCalculator {
|
|
private static config;
|
|
/**
|
|
* Initialize DateCalculator with configuration
|
|
* @param config - Calendar configuration
|
|
*/
|
|
static initialize(config: CalendarConfig): void;
|
|
/**
|
|
* Validate that a date is valid
|
|
* @param date - Date to validate
|
|
* @param methodName - Name of calling method for error messages
|
|
* @throws Error if date is invalid
|
|
*/
|
|
private static validateDate;
|
|
/**
|
|
* Get dates for work week using ISO 8601 day numbering (Monday=1, Sunday=7)
|
|
* @param weekStart - Any date in the week
|
|
* @returns Array of dates for the configured work days
|
|
*/
|
|
static getWorkWeekDates(weekStart: Date): Date[];
|
|
/**
|
|
* Get the start of the ISO week (Monday) for a given date
|
|
* @param date - Any date in the week
|
|
* @returns The Monday of the ISO week
|
|
*/
|
|
static getISOWeekStart(date: Date): Date;
|
|
/**
|
|
* Get the end of the ISO week for a given date
|
|
* @param date - Any date in the week
|
|
* @returns The end date of the ISO week (Sunday)
|
|
*/
|
|
static getWeekEnd(date: Date): Date;
|
|
/**
|
|
* Get week number for a date (ISO 8601)
|
|
* @param date - The date to get week number for
|
|
* @returns Week number (1-53)
|
|
*/
|
|
static getWeekNumber(date: Date): number;
|
|
/**
|
|
* Format a date range with customizable options
|
|
* @param start - Start date
|
|
* @param end - End date
|
|
* @param options - Formatting options
|
|
* @returns Formatted date range string
|
|
*/
|
|
static formatDateRange(start: Date, end: Date, options?: {
|
|
locale?: string;
|
|
month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
|
|
day?: 'numeric' | '2-digit';
|
|
year?: 'numeric' | '2-digit';
|
|
}): string;
|
|
/**
|
|
* Format a date to ISO date string (YYYY-MM-DD)
|
|
* @param date - Date to format
|
|
* @returns ISO date string
|
|
*/
|
|
static formatISODate(date: Date): string;
|
|
/**
|
|
* Check if a date is today
|
|
* @param date - Date to check
|
|
* @returns True if the date is today
|
|
*/
|
|
static isToday(date: Date): boolean;
|
|
/**
|
|
* Add days to a date
|
|
* @param date - Base date
|
|
* @param days - Number of days to add (can be negative)
|
|
* @returns New date
|
|
*/
|
|
static addDays(date: Date, days: number): Date;
|
|
/**
|
|
* Add weeks to a date
|
|
* @param date - Base date
|
|
* @param weeks - Number of weeks to add (can be negative)
|
|
* @returns New date
|
|
*/
|
|
static addWeeks(date: Date, weeks: number): Date;
|
|
/**
|
|
* Get all dates in a week
|
|
* @param weekStart - Start of the week
|
|
* @returns Array of 7 dates for the full week
|
|
*/
|
|
static getFullWeekDates(weekStart: Date): Date[];
|
|
/**
|
|
* Get the day name for a date using Intl.DateTimeFormat
|
|
* @param date - Date to get day name for
|
|
* @param format - 'short' or 'long'
|
|
* @returns Day name
|
|
*/
|
|
static getDayName(date: Date, format?: 'short' | 'long'): string;
|
|
/**
|
|
* Format time to HH:MM
|
|
* @param date - Date to format
|
|
* @returns Time string
|
|
*/
|
|
static formatTime(date: Date): string;
|
|
/**
|
|
* Format time to 12-hour format
|
|
* @param date - Date to format
|
|
* @returns 12-hour time string
|
|
*/
|
|
static formatTime12(date: Date): string;
|
|
/**
|
|
* Convert minutes since midnight to time string
|
|
* @param minutes - Minutes since midnight
|
|
* @returns Time string
|
|
*/
|
|
static minutesToTime(minutes: number): string;
|
|
/**
|
|
* Convert time string to minutes since midnight
|
|
* @param timeStr - Time string
|
|
* @returns Minutes since midnight
|
|
*/
|
|
static timeToMinutes(timeStr: string): number;
|
|
/**
|
|
* Get minutes since start of day
|
|
* @param date - Date or ISO string
|
|
* @returns Minutes since midnight
|
|
*/
|
|
static getMinutesSinceMidnight(date: Date | string): number;
|
|
/**
|
|
* Calculate duration in minutes between two dates
|
|
* @param start - Start date or ISO string
|
|
* @param end - End date or ISO string
|
|
* @returns Duration in minutes
|
|
*/
|
|
static getDurationMinutes(start: Date | string, end: Date | string): number;
|
|
/**
|
|
* Check if two dates are on the same day
|
|
* @param date1 - First date
|
|
* @param date2 - Second date
|
|
* @returns True if same day
|
|
*/
|
|
static isSameDay(date1: Date, date2: Date): boolean;
|
|
/**
|
|
* Check if event spans multiple days
|
|
* @param start - Start date or ISO string
|
|
* @param end - End date or ISO string
|
|
* @returns True if spans multiple days
|
|
*/
|
|
static isMultiDay(start: Date | string, end: Date | string): boolean;
|
|
constructor();
|
|
}
|
|
export declare function createDateCalculator(config: CalendarConfig): DateCalculator;
|