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