import defaultDayjs, { type Dayjs } from "dayjs"; import { type AdapterOptions, type ParserResult, type RecommendedFormats, type SaltDateAdapter, type TimeFields, type Timezone } from "../types"; type Constructor = { (...args: Parameters): Dayjs; tz?: (value: Parameters[0], timezone: string) => Dayjs; utc?: (value?: Parameters[0]) => Dayjs; }; declare module "@salt-ds/date-adapters" { interface DateFrameworkTypeMap { dayjs: Dayjs; } } /** * Adapter for Day.js library, implementing the SaltDateAdapter interface. * Provides methods for date manipulation and formatting using Day.js. */ export declare class AdapterDayjs implements SaltDateAdapter { private hasExplicitOffset; /** * The Day.js instance used for date operations. */ dayjs: Constructor; /** * The locale used for date formatting. */ locale: string; /** * The name of the date library. */ lib: string; /** * Creates an instance of AdapterDayjs. * @param options - Adapter options including locale. * @param instance - The Day.js instance to use. */ constructor({ locale }?: AdapterOptions, instance?: Constructor); /** * Type guard for Dayjs object * @param date * @private */ private isDayjs; private resolveTimezone; /** * Creates a Day.js date object in the system timezone. * @param value - The date string to parse. * @returns The parsed Day.js date object. */ private createSystemDate; /** * Creates a Day.js date object in UTC. * @param value - The date string to parse. * @returns The parsed Day.js date object. * @throws Error if the UTC plugin is missing. */ private createUTCDate; /** * Creates a Day.js date object in a specified timezone. * @param value - The date string to parse. * @param timezone - The timezone to use. * @returns The parsed Day.js date object. * @throws Error if the timezone plugin is missing. */ private createTZDate; /** * Creates a Day.js date 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 Day.js date object or an invalid date object. */ date: (value?: T, timezone?: Timezone) => Dayjs; /** * Formats a Day.js date object using the specified format string. * Returns an empty string when null or undefined date is given. * @param date - The Day.js date object to format. * @param format - The format string to use. * @returns The formatted date string. */ format(date: Dayjs | null | undefined, format?: RecommendedFormats): string; /** * Compares two Day.js date objects. * @param dateA - The first Day.js date object. * @param dateB - The second Day.js date object. * @returns 0 if equal, 1 if dateA is after dateB, -1 if dateA is before dateB. */ compare(dateA: Dayjs, dateB: Dayjs): 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 Day.js date object is valid. * @param date - The Day.js date object to check, null or undefined. * @returns True if the date is valid date object, false otherwise. */ isValid(date: Dayjs | null | undefined): date is Dayjs; /** * Subtracts time from a Day.js date object. * @param date - The Day.js date object to subtract from. * @param duration - The duration to subtract. * @returns The resulting Day.js date object. */ subtract(date: Dayjs, { days, weeks, months, years, hours, minutes, seconds, milliseconds, }: { days?: number; weeks?: number; months?: number; years?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }): Dayjs; /** * Adds time to a Day.js date object. * @param date - The Day.js date object to add to. * @param duration - The duration to add. * @returns The resulting Day.js date object. */ add(date: Dayjs, { days, weeks, months, years, hours, minutes, seconds, milliseconds, }: { days?: number; weeks?: number; months?: number; years?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }): Dayjs; /** * Sets specific components of a Day.js date object. * @param date - The Day.js date object to modify. * @param components - The components to set, the month is a number (1-12). * @returns The resulting Day.js date object. */ set(date: Dayjs, { day, month, year, hour, minute, second, millisecond, }: { day?: number; month?: number; year?: number; hour?: number; minute?: number; second?: number; millisecond?: number; }): Dayjs; /** * Get the timezone from the Day.js object * @param date - A Day.js object * @returns 'UTC' | 'system' or the IANA time zone */ getTimezone: (date: Dayjs) => string; /** * Set the timezone for the Day.js object * @param date - A Day.js object * @param timezone - Timezone to set date object to * @returns date object set to the timezone */ setTimezone: (date: Dayjs, timezone: Timezone) => Dayjs; private adjustOffset; /** * Checks if two Day.js date objects are the same based on the specified granularity. * @param dateA - The first Day.js date object. * @param dateB - The second Day.js date object. * @param granularity - The granularity to compare by ("day", "month", "year"). * @returns True if the dates are the same, false otherwise. */ isSame(dateA: Dayjs, dateB: Dayjs, granularity?: "day" | "month" | "year"): boolean; /** * Gets the start of a specified time period for a Day.js date object. * @param date - The Day.js date object. * @param offset - The time period ("day", "week", "month", "year"). * @returns The Day.js date object representing the start of the period. */ startOf(date: Dayjs, offset: "day" | "week" | "month" | "year"): Dayjs; /** * Gets the end of a specified time period for a Day.js date object. * @param date - The Day.js date object. * @param offset - The time period ("day", "week", "month", "year"). * @returns The Day.js date object representing the end of the period. */ endOf(date: Dayjs, offset: "day" | "week" | "month" | "year"): Dayjs; /** * 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): Dayjs; /** * Gets the current date and time. * @param timezone - Timezone, defaults to library "default" * @returns The current date and time. */ now(timezone?: Timezone): Dayjs; /** * 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 Day.js date object. * @param date - The Day.js date object. * @returns The day of the month as a number (1-31). */ getDay(date: Dayjs): number; /** * Gets the month for a Day.js date object. * @param date - The Day.js date object. * @returns The month as a number (0-11). */ getMonth(date: Dayjs): number; /** * Gets the year for a Day.js date object. * @param date - The Day.js date object. * @returns The year as a number. */ getYear(date: Dayjs): number; /** * Gets the time components for a Day.js date object. * @param date - The Day.js date object. * @returns An object containing the hour, minute, second, and millisecond. */ getTime(date: Dayjs): TimeFields; /** * Validate date string so it can be parsed * @param value */ isValidDateString(value: string): boolean; /** * Clone the date object * @param date */ clone(date: Dayjs): Dayjs; toJSDate: (value: Dayjs) => Date; } export {};