UNPKG

2.79 kBTypeScriptView Raw
1import type { FormatDistanceStrictOptions } from "./formatDistanceStrict.js";
2/**
3 * The {@link formatDistanceToNowStrict} function options.
4 */
5export interface FormatDistanceToNowStrictOptions
6 extends FormatDistanceStrictOptions {}
7/**
8 * @name formatDistanceToNowStrict
9 * @category Common Helpers
10 * @summary Return the distance between the given date and now in words.
11 * @pure false
12 *
13 * @description
14 * Return the distance between the given dates in words, using strict units.
15 * This is like `formatDistance`, but does not use helpers like 'almost', 'over',
16 * 'less than' and the like.
17 *
18 * | Distance between dates | Result |
19 * |------------------------|---------------------|
20 * | 0 ... 59 secs | [0..59] seconds |
21 * | 1 ... 59 mins | [1..59] minutes |
22 * | 1 ... 23 hrs | [1..23] hours |
23 * | 1 ... 29 days | [1..29] days |
24 * | 1 ... 11 months | [1..11] months |
25 * | 1 ... N years | [1..N] years |
26 *
27 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
28 *
29 * @param date - The given date
30 * @param options - An object with options.
31 *
32 * @returns The distance in words
33 *
34 * @throws `date` must not be Invalid Date
35 * @throws `options.locale` must contain `formatDistance` property
36 *
37 * @example
38 * // If today is 1 January 2015, what is the distance to 2 July 2014?
39 * const result = formatDistanceToNowStrict(
40 * new Date(2014, 6, 2)
41 * )
42 * //=> '6 months'
43 *
44 * @example
45 * // If now is 1 January 2015 00:00:00,
46 * // what is the distance to 1 January 2015 00:00:15, including seconds?
47 * const result = formatDistanceToNowStrict(
48 * new Date(2015, 0, 1, 0, 0, 15)
49 * )
50 * //=> '15 seconds'
51 *
52 * @example
53 * // If today is 1 January 2015,
54 * // what is the distance to 1 January 2016, with a suffix?
55 * const result = formatDistanceToNowStrict(
56 * new Date(2016, 0, 1),
57 * {addSuffix: true}
58 * )
59 * //=> 'in 1 year'
60 *
61 * @example
62 * // If today is 28 January 2015,
63 * // what is the distance to 1 January 2015, in months, rounded up??
64 * const result = formatDistanceToNowStrict(new Date(2015, 0, 1), {
65 * unit: 'month',
66 * roundingMethod: 'ceil'
67 * })
68 * //=> '1 month'
69 *
70 * @example
71 * // If today is 1 January 2015,
72 * // what is the distance to 1 January 2016 in Esperanto?
73 * const eoLocale = require('date-fns/locale/eo')
74 * const result = formatDistanceToNowStrict(
75 * new Date(2016, 0, 1),
76 * {locale: eoLocale}
77 * )
78 * //=> '1 jaro'
79 */
80export declare function formatDistanceToNowStrict<DateType extends Date>(
81 date: DateType | number | string,
82 options?: FormatDistanceToNowStrictOptions,
83): string;