import { DateTime } from "luxon"; import { type AdapterOptions, type ParserResult, type RecommendedFormats, type SaltDateAdapter, type TimeFields, type Timezone } from "../types"; declare module "@salt-ds/date-adapters" { interface DateFrameworkTypeMap { luxon: DateTime; } } /** * Adapter for Luxon library, implementing the SaltDateAdapter interface. * Provides methods for date manipulation and formatting using Luxon. */ export declare class AdapterLuxon implements SaltDateAdapter { /** * The locale used for date formatting. */ locale: string; /** * The name of the date library. */ lib: string; /** * Mapping of format tokens from other libraries to Luxon format tokens. */ formats: { [key: string]: string; }; /** * Creates an instance of AdapterLuxon. * @param options - Adapter options including locale. */ constructor({ locale }?: AdapterOptions); /** * Maps format tokens from other libraries to Luxon format tokens. * @param adapterFormat - The format string to map. * @returns The mapped format string. */ private mapToLuxonFormat; /** * Creates a Luxon DateTime object in the system timezone. * @param value - The date string to parse. * @returns The parsed Luxon DateTime object. */ private createSystemDate; /** * Creates a Luxon DateTime object in UTC. * @param value - The date string to parse. * @returns The parsed Luxon DateTime object. */ private createUTCDate; /** * Creates a Luxon DateTime object in a specified timezone. * @param value - The date string to parse. * @param timezone - The timezone to use. * @returns The parsed Luxon DateTime object. */ private createTZDate; /** * Creates a Luxon DateTime object from a string or returns an invalid date. * @param value - The date string to parse. * @param timezone - The timezone to use (default is "default"). * @returns The parsed Luxon DateTime object or an invalid date object. */ date: (value?: T, timezone?: Timezone) => DateTime; /** * Formats a Luxon DateTime object using the specified format string. * Returns an empty string when null or undefined date is given. * @param date - The Luxon DateTime object to format. * @param format - The format string to use. * @returns The formatted date string. */ format(date: DateTime | null | undefined, format?: RecommendedFormats): string; /** * Compares two Luxon DateTime objects. * @param dateA - The first Luxon DateTime object. * @param dateB - The second Luxon DateTime object. * @returns 0 if equal, 1 if dateA is after dateB, -1 if dateA is before dateB. */ compare(dateA: DateTime, dateB: DateTime): number; /** * Parses a date string using the specified format. * @param value - The date string to parse. * @param format - The format string to use. * @returns A DateDetail object containing the parsed date and any errors. */ parse(value: string, format: string): ParserResult; /** * Checks if a Luxon DateTime object is valid. * @param date - The Luxon DateTime object to check, null or undefined. * @returns True if the date is valid date object, false otherwise. */ isValid(date: DateTime | null | undefined): date is DateTime; /** * Subtracts time from a Luxon DateTime object. * @param date - The Luxon DateTime object to subtract from. * @param duration - The duration to subtract. * @returns The resulting Luxon DateTime object. */ subtract(date: DateTime, { days, weeks, months, years, hours, minutes, seconds, milliseconds, }: { days?: number; weeks?: number; months?: number; years?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }): DateTime; /** * Adds time to a Luxon DateTime object. * @param date - The Luxon DateTime object to add to. * @param duration - The duration to add. * @returns The resulting Luxon DateTime object. */ add(date: DateTime, { days, weeks, months, years, hours, minutes, seconds, milliseconds, }: { days?: number; weeks?: number; months?: number; years?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }): DateTime; /** * Sets specific components of a Luxon DateTime object. * @param date - The Luxon DateTime object to modify. * @param components - The components to set, the month is a number (1-12). * @returns The resulting Luxon DateTime object. */ set(date: DateTime, { day, month, year, hour, minute, second, millisecond, }: { day?: number; month?: number; year?: number; hour?: number; minute?: number; second?: number; millisecond?: number; }): DateTime; /** * Get the timezone from the DateTime object * @param date - A Luxon DateTime object * @returns 'UTC' | 'system' or the IANA time zone */ getTimezone: (date: DateTime) => string; /** * Set the timezone for the DateTime object * @param date - A Luxon DateTime object * @param timezone - Timezone to set date object to * @returns date object set to the timezone */ setTimezone: (date: DateTime, timezone: Timezone) => DateTime; /** * Checks if two Luxon DateTime objects are the same based on the specified granularity. * @param dateA - The first Luxon DateTime object. * @param dateB - The second Luxon DateTime object. * @param granularity - The granularity to compare by ("day", "month", "year"). * @returns True if the dates are the same, false otherwise. */ isSame(dateA: DateTime, dateB: DateTime, granularity?: "day" | "month" | "year"): boolean; /** * Gets the start of a specified time period for a Luxon DateTime object. * @param date - The Luxon DateTime object. * @param offset - The time period ("day", "week", "month", "year"). * @returns The Luxon DateTime object representing the start of the period. */ startOf(date: DateTime, offset: "day" | "week" | "month" | "year"): DateTime; /** * Gets the end of a specified time period for a Luxon DateTime object. * @param date - The Luxon DateTime object. * @param offset - The time period ("day", "week", "month", "year"). * @returns The Luxon DateTime object representing the end of the period. */ endOf(date: DateTime, offset: "day" | "week" | "month" | "year"): DateTime; /** * Gets the current date with the time set to the start of the day. * @param timezone - Timezone, defaults to library "default" * @returns The current date at the start of the day. */ today(timezone?: Timezone): DateTime; /** * Gets the current date and time. * @param timezone - Timezone, defaults to library "default" * @returns The current date and time. */ now(timezone?: Timezone): DateTime; /** * Gets the name of the day of the week. * @param dow - The day of the week as a number (0-6). * @param format - The format for the day name ("long", "short", "narrow"). * @returns The name of the day of the week. */ getDayOfWeekName(dow: number, format: "long" | "short" | "narrow"): string; /** * Gets the day of the month for a Luxon DateTime object. * @param date - The Luxon DateTime object. * @returns The day of the month as a number (1-31). */ getDay(date: DateTime): number; /** * Gets the month for a Luxon DateTime object. * @param date - The Luxon DateTime object. * @returns The month as a number (1-12). */ getMonth(date: DateTime): number; /** * Gets the year for a Luxon DateTime object. * @param date - The Luxon DateTime object. * @returns The year as a number. */ getYear(date: DateTime): number; /** * Gets the time components for a Luxon DateTime object. * @param date - The Luxon DateTime object. * @returns An object containing the hour, minute, second, and millisecond. */ getTime(date: DateTime): TimeFields; /** * Validate date string so it can be parsed * @param value */ isValidDateString(value: string): boolean; /** * Clone the date object * @param date */ clone(date: DateTime): DateTime; toJSDate: (value: DateTime) => Date; }