1 | import type {
|
2 | ContextOptions,
|
3 | DateArg,
|
4 | LocalizedOptions,
|
5 | WeekOptions,
|
6 | } from "./types.js";
|
7 | /**
|
8 | * The {@link formatRelative} function options.
|
9 | */
|
10 | export interface FormatRelativeOptions
|
11 | extends LocalizedOptions<
|
12 | "options" | "localize" | "formatLong" | "formatRelative"
|
13 | >,
|
14 | WeekOptions,
|
15 | ContextOptions<Date> {}
|
16 | /**
|
17 | * @name formatRelative
|
18 | * @category Common Helpers
|
19 | * @summary Represent the date in words relative to the given base date.
|
20 | *
|
21 | * @description
|
22 | * Represent the date in words relative to the given base date.
|
23 | *
|
24 | * | Distance to the base date | Result |
|
25 | * |---------------------------|---------------------------|
|
26 | * | Previous 6 days | last Sunday at 04:30 AM |
|
27 | * | Last day | yesterday at 04:30 AM |
|
28 | * | Same day | today at 04:30 AM |
|
29 | * | Next day | tomorrow at 04:30 AM |
|
30 | * | Next 6 days | Sunday at 04:30 AM |
|
31 | * | Other | 12/31/2017 |
|
32 | *
|
33 | * @param date - The date to format
|
34 | * @param baseDate - The date to compare with
|
35 | * @param options - An object with options
|
36 | *
|
37 | * @returns The date in words
|
38 | *
|
39 | * @throws `date` must not be Invalid Date
|
40 | * @throws `baseDate` must not be Invalid Date
|
41 | * @throws `options.locale` must contain `localize` property
|
42 | * @throws `options.locale` must contain `formatLong` property
|
43 | * @throws `options.locale` must contain `formatRelative` property
|
44 | *
|
45 | * @example
|
46 | * // Represent the date of 6 days ago in words relative to the given base date. In this example, today is Wednesday
|
47 | * const result = formatRelative(subDays(new Date(), 6), new Date())
|
48 | * //=> "last Thursday at 12:45 AM"
|
49 | */
|
50 | export declare function formatRelative(
|
51 | date: DateArg<Date> & {},
|
52 | baseDate: DateArg<Date> & {},
|
53 | options?: FormatRelativeOptions,
|
54 | ): string;
|