import { Simplify } from 'type-fest'; import { I18NLocale } from '../providers/I18NProvider'; type Format = "date" | "time" | "timeWithSeconds" | "full" | "fullWithSeconds" | "distanceToNow"; interface FormatDateOptions { /** * JavaScript ISO date string. Example '2022-10-06T11:59:30.371Z' */ isoDate?: string; /** * Set a specific timezone, when not passed default value is 'UTC' */ timezone?: string; /** * How to format the date: * - `date` – can be `Today` when today, `Feb 28` when current year or `Feb 28, 2022` when previous year * - `time` – `04:34` `18:54` * - `timeWithSeconds` – `04:34:23` `18:54:12` * - `full` – `Feb 28, 2023 · 15:30` the date in this string behaves like the `date` format * - `fullWithSeconds` – `Feb 28, 2023 · 15:30:43` the date in this string behaves like the `date` format * - `distanceToNow` – `about 1 hour ago` `10 months ago` `less than a minute ago` * @default date */ format?: Format; /** * Whether to show or not the current year. * @default false */ showCurrentYear?: boolean; /** * Locale to use for formatting the date. * @default en */ locale?: I18NLocale; } /** * Format the date as nice string also specifying a custom timezone * @param opts a set of `FormatDateOptions` * @returns a nice string representation. Example: 'Jul 21, 2022' or 'Jul 21, 2022 · 1:16 PM' if includeTime */ export declare function formatDate({ isoDate, timezone, locale, showCurrentYear, ...opts }: FormatDateOptions): string; interface FormatDateWithPredicateOptions extends FormatDateOptions { /** * Date predicate verb string. Example: 'Created' or 'Updated'. */ predicate: string; } /** * Generate a string containing provided predicate, a separator and provided date formatted according to `formatDate` method * @param opts a set of `FormatDateOptions` along with a date verb predicate. In this method `format` prop has 'full' default value. * @returns a nice string representation of the predicate, followed by the proper separator and the formatted date. Examples: 'Created today · 1:16 PM', 'Updated on Jul 21, 2022 · 1:16 PM' or 'Updated at 1:16 PM' */ export declare function formatDateWithPredicate({ isoDate, timezone, format, predicate, locale, }: FormatDateWithPredicateOptions): string; export declare const timeSeparator = ", "; type DateISOString = string; /** * Calculate the time-zoned start or end of the day from an ISO date string. * Useful when getting date from a date range picker. * @param isoString a JavaScript ISO date string. Example '2022-10-06T11:59:30.371Z' * @param edge 'startOfTheDay' or 'endOfTheDay' * @param timezone Set a specific timezone, when not passed default value is 'UTC' * @returns a JavaScript ISO date string that reflect the start or end of the day * based on the user timezone. Example '2022-10-06T22:00:00.000Z' when timezone is 'Europe/Rome' */ export declare function getIsoDateAtDayEdge({ isoString, edge, timezone, }: { isoString: DateISOString; edge: "startOfTheDay" | "endOfTheDay"; timezone?: string; }): string | undefined; /** * Subtract n days from an ISO date string * to always return the correspondent time-zoned start of the day * * Example: if date-now is the 8th of March at 16:00 Italian time * and I want to get the date at -7, the result will be * '2022-03-01T23:00:00.000Z' as UTC string since my timezone is 'Europe/Rome' * and on the 8th of March I was at +1 from UTC * * @param isoString JavaScript ISO date (eg: '2022-03-01T23:00:00.000Z') * @param days positive number of days to subtract * @param timezone (optional) in case of working with a specific timezone different from UTC * @returns a new iso string */ export declare function getIsoDateAtDaysBefore({ isoString, days, timezone, }: { isoString: DateISOString; days: number; timezone?: string; }): string | undefined; /** * Given the event date (`startsAt` and `expiresAt`) it returns whether the the event is `active`, `past` or `upcoming`. */ export declare function getEventDateInfo({ startsAt, expiresAt, timezone, }: { /** The activation date/time of the event (ISO date string. Example '2022-10-06T11:59:30.371Z'). */ startsAt: DateISOString; /** The expiration date/time of the promotion (must be after startsAt) (ISO date string. Example '2022-10-06T11:59:30.371Z'). */ expiresAt: DateISOString; /** Set a specific timezone, when not passed default value is 'UTC' */ timezone?: string; }): "active" | "past" | "upcoming"; /** * Format a date range as a nice string also specifying a custom timezone * @returns a nice string representation. Example: '1-21 Jul, 2022' or 'Jul 21, 2022 - Jan 12, 2023' */ export declare function formatDateRange({ rangeFrom, rangeTo, timezone, locale, }: { /** JavaScript Date or ISO string. Example '2022-10-06T11:59:30.371Z' */ rangeFrom: DateISOString | Date; /** JavaScript Date or ISO string. Example '2022-11-06T11:59:30.371Z' */ rangeTo: DateISOString | Date; /** Set a specific timezone, when not passed default value is 'UTC' */ timezone?: string; /** Locale to use for formatting the date. */ locale?: I18NLocale; zonedAlready?: boolean; }): string; export interface Event { date: string; } type Position = "first" | "other"; /** * * @param events * @param options * @returns */ export declare function sortAndGroupByDate(events: T[], { timezone, locale, orders, }?: { timezone?: string; locale?: I18NLocale; orders?: "asc" | "desc"; }): Record>>; /** * Remove milliseconds from a date ISO string. * * Example: * ``` * removeMilliseconds('2022-04-24T13:44:59.452Z') // '2022-04-24T13:44:59Z' * ``` */ export declare function removeMillisecondsFromIsoDate(isoDate: string): string; /** * Creates a date range spanning a specified number of years back from a given reference date. * The range includes the start date and ends exactly one second before the reference date to form a precise interval. * * @param now The reference date from which the range is calculated. Typically the current date. * @param yearsAgo The number of years to go back from the reference date to determine the start of the range. * @param showMilliseconds If set to false, the resulting date strings are formatted to exclude milliseconds. * @returns An object containing `date_from` and `date_to` properties. `date_from` is the calculated start date of the range, * going back the specified number of years from `now`. `date_to` is adjusted to be one second before `now`, * effectively marking the end of the range. Both dates are returned as ISO 8601 formatted strings, with an option * to include or exclude milliseconds. * * Example usage: * ``` * const range = makeDateYearsRange(new Date(), 1, false); * console.log(range); * // Output when showMilliseconds is false: * // { date_from: '2022-04-24T13:45:01Z, date_to: '2023-04-24T13:45:00Z' } * // Output when showMilliseconds is true: * // { date_from: '2022-04-24T13:45:01.000Z, date_to: '2023-04-24T13:45:00.000Z' } * ``` */ export declare function makeDateYearsRange({ now, yearsAgo, showMilliseconds, }: { now: Date; yearsAgo: number; showMilliseconds: boolean; }): { date_from: string; date_to: string; }; /** * Check if the given date is valid. * @param date The date to check. * @returns True if the date is valid, false otherwise. */ export declare function isDateValid(date: Date): boolean; export {};