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