Calendar/wwwroot/js/utils/DateService.d.ts

255 lines
8.2 KiB
TypeScript
Raw Normal View History

2026-02-03 00:02:25 +01:00
/**
* DateService - Unified date/time service using day.js
* Handles all date operations, timezone conversions, and formatting
*/
import { Configuration } from '../configurations/CalendarConfig';
export declare class DateService {
private timezone;
constructor(config: Configuration);
/**
* Convert local date to UTC ISO string
* @param localDate - Date in local timezone
* @returns ISO string in UTC (with 'Z' suffix)
*/
toUTC(localDate: Date): string;
/**
* Convert UTC ISO string to local date
* @param utcString - ISO string in UTC
* @returns Date in local timezone
*/
fromUTC(utcString: string): Date;
/**
* Format time as HH:mm or HH:mm:ss
* @param date - Date to format
* @param showSeconds - Include seconds in output
* @returns Formatted time string
*/
formatTime(date: Date, showSeconds?: boolean): string;
/**
* Format time range as "HH:mm - HH:mm"
* @param start - Start date
* @param end - End date
* @returns Formatted time range
*/
formatTimeRange(start: Date, end: Date): string;
/**
* Format date and time in technical format: yyyy-MM-dd HH:mm:ss
* @param date - Date to format
* @returns Technical datetime string
*/
formatTechnicalDateTime(date: Date): string;
/**
* Format date as yyyy-MM-dd
* @param date - Date to format
* @returns ISO date string
*/
formatDate(date: Date): string;
/**
* Format date as "Month Year" (e.g., "January 2025")
* @param date - Date to format
* @param locale - Locale for month name (default: 'en-US')
* @returns Formatted month and year
*/
formatMonthYear(date: Date, locale?: string): string;
/**
* Format date as ISO string (same as formatDate for compatibility)
* @param date - Date to format
* @returns ISO date string
*/
formatISODate(date: Date): string;
/**
* Format time in 12-hour format with AM/PM
* @param date - Date to format
* @returns Time string in 12-hour format (e.g., "2:30 PM")
*/
formatTime12(date: Date): string;
/**
* Get day name for a date
* @param date - Date to get day name for
* @param format - 'short' (e.g., 'Mon') or 'long' (e.g., 'Monday')
* @param locale - Locale for day name (default: 'da-DK')
* @returns Day name
*/
getDayName(date: Date, format?: 'short' | 'long', locale?: string): string;
/**
* Format a date range with customizable options
* @param start - Start date
* @param end - End date
* @param options - Formatting options
* @returns Formatted date range string
*/
formatDateRange(start: Date, end: Date, options?: {
locale?: string;
month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow';
day?: 'numeric' | '2-digit';
year?: 'numeric' | '2-digit';
}): string;
/**
* Convert time string (HH:mm or HH:mm:ss) to total minutes since midnight
* @param timeString - Time in format HH:mm or HH:mm:ss
* @returns Total minutes since midnight
*/
timeToMinutes(timeString: string): number;
/**
* Convert total minutes since midnight to time string HH:mm
* @param totalMinutes - Minutes since midnight
* @returns Time string in format HH:mm
*/
minutesToTime(totalMinutes: number): string;
/**
* Format time from total minutes (alias for minutesToTime)
* @param totalMinutes - Minutes since midnight
* @returns Time string in format HH:mm
*/
formatTimeFromMinutes(totalMinutes: number): string;
/**
* Get minutes since midnight for a given date
* @param date - Date to calculate from
* @returns Minutes since midnight
*/
getMinutesSinceMidnight(date: Date): 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
*/
getDurationMinutes(start: Date | string, end: Date | string): number;
/**
* Get start and end of week (Monday to Sunday)
* @param date - Reference date
* @returns Object with start and end dates
*/
getWeekBounds(date: Date): {
start: Date;
end: Date;
};
/**
* Add weeks to a date
* @param date - Base date
* @param weeks - Number of weeks to add (can be negative)
* @returns New date
*/
addWeeks(date: Date, weeks: number): Date;
/**
* Add months to a date
* @param date - Base date
* @param months - Number of months to add (can be negative)
* @returns New date
*/
addMonths(date: Date, months: number): Date;
/**
* Get ISO week number (1-53)
* @param date - Date to get week number for
* @returns ISO week number
*/
getWeekNumber(date: Date): number;
/**
* Get all dates in a full week (7 days starting from given date)
* @param weekStart - Start date of the week
* @returns Array of 7 dates
*/
getFullWeekDates(weekStart: Date): Date[];
/**
* Get dates for work week using ISO 8601 day numbering (Monday=1, Sunday=7)
* @param weekStart - Any date in the week
* @param workDays - Array of ISO day numbers (1=Monday, 7=Sunday)
* @returns Array of dates for the specified work days
*/
getWorkWeekDates(weekStart: Date, workDays: number[]): Date[];
/**
* Create a date at a specific time (minutes since midnight)
* @param baseDate - Base date (date component)
* @param totalMinutes - Minutes since midnight
* @returns New date with specified time
*/
createDateAtTime(baseDate: Date, totalMinutes: number): Date;
/**
* Snap date to nearest interval
* @param date - Date to snap
* @param intervalMinutes - Snap interval in minutes
* @returns Snapped date
*/
snapToInterval(date: Date, intervalMinutes: number): Date;
/**
* Check if two dates are the same day
* @param date1 - First date
* @param date2 - Second date
* @returns True if same day
*/
isSameDay(date1: Date, date2: Date): boolean;
/**
* Get start of day
* @param date - Date
* @returns Start of day (00:00:00)
*/
startOfDay(date: Date): Date;
/**
* Get end of day
* @param date - Date
* @returns End of day (23:59:59.999)
*/
endOfDay(date: Date): Date;
/**
* Add days to a date
* @param date - Base date
* @param days - Number of days to add (can be negative)
* @returns New date
*/
addDays(date: Date, days: number): Date;
/**
* Add minutes to a date
* @param date - Base date
* @param minutes - Number of minutes to add (can be negative)
* @returns New date
*/
addMinutes(date: Date, minutes: number): Date;
/**
* Parse ISO string to date
* @param isoString - ISO date string
* @returns Parsed date
*/
parseISO(isoString: string): Date;
/**
* Check if date is valid
* @param date - Date to check
* @returns True if valid
*/
isValid(date: Date): boolean;
/**
* Calculate difference in calendar days between two dates
* @param date1 - First date
* @param date2 - Second date
* @returns Number of calendar days between dates (can be negative)
*/
differenceInCalendarDays(date1: Date, date2: Date): number;
/**
* Validate date range (start must be before or equal to end)
* @param start - Start date
* @param end - End date
* @returns True if valid range
*/
isValidRange(start: Date, end: Date): boolean;
/**
* Check if date is within reasonable bounds (1900-2100)
* @param date - Date to check
* @returns True if within bounds
*/
isWithinBounds(date: Date): boolean;
/**
* Validate date with comprehensive checks
* @param date - Date to validate
* @param options - Validation options
* @returns Validation result with error message
*/
validateDate(date: Date, options?: {
requireFuture?: boolean;
requirePast?: boolean;
minDate?: Date;
maxDate?: Date;
}): {
valid: boolean;
error?: string;
};
}