123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import type {
- ContextOptions,
- DateArg,
- LocalizedOptions,
- RoundingOptions,
- } from "./types.js";
- /**
- * The {@link formatDistanceStrict} function options.
- */
- export interface FormatDistanceStrictOptions
- extends LocalizedOptions<"formatDistance">,
- RoundingOptions,
- ContextOptions<Date> {
- /** Add "X ago"/"in X" in the locale language */
- addSuffix?: boolean;
- /** If specified, will force the unit */
- unit?: FormatDistanceStrictUnit;
- }
- /**
- * The unit used to format the distance in {@link formatDistanceStrict}.
- */
- export type FormatDistanceStrictUnit =
- | "second"
- | "minute"
- | "hour"
- | "day"
- | "month"
- | "year";
- /**
- * @name formatDistanceStrict
- * @category Common Helpers
- * @summary Return the distance between the given dates in words.
- *
- * @description
- * Return the distance between the given dates in words, using strict units.
- * This is like `formatDistance`, but does not use helpers like 'almost', 'over',
- * 'less than' and the like.
- *
- * | Distance between dates | Result |
- * |------------------------|---------------------|
- * | 0 ... 59 secs | [0..59] seconds |
- * | 1 ... 59 mins | [1..59] minutes |
- * | 1 ... 23 hrs | [1..23] hours |
- * | 1 ... 29 days | [1..29] days |
- * | 1 ... 11 months | [1..11] months |
- * | 1 ... N years | [1..N] years |
- *
- * @param laterDate - The date
- * @param earlierDate - The date to compare with
- * @param options - An object with options
- *
- * @returns The distance in words
- *
- * @throws `date` must not be Invalid Date
- * @throws `baseDate` must not be Invalid Date
- * @throws `options.unit` must be 'second', 'minute', 'hour', 'day', 'month' or 'year'
- * @throws `options.locale` must contain `formatDistance` property
- *
- * @example
- * // What is the distance between 2 July 2014 and 1 January 2015?
- * const result = formatDistanceStrict(new Date(2014, 6, 2), new Date(2015, 0, 2))
- * //=> '6 months'
- *
- * @example
- * // What is the distance between 1 January 2015 00:00:15
- * // and 1 January 2015 00:00:00?
- * const result = formatDistanceStrict(
- * new Date(2015, 0, 1, 0, 0, 15),
- * new Date(2015, 0, 1, 0, 0, 0)
- * )
- * //=> '15 seconds'
- *
- * @example
- * // What is the distance from 1 January 2016
- * // to 1 January 2015, with a suffix?
- * const result = formatDistanceStrict(new Date(2015, 0, 1), new Date(2016, 0, 1), {
- * addSuffix: true
- * })
- * //=> '1 year ago'
- *
- * @example
- * // What is the distance from 1 January 2016
- * // to 1 January 2015, in minutes?
- * const result = formatDistanceStrict(new Date(2016, 0, 1), new Date(2015, 0, 1), {
- * unit: 'minute'
- * })
- * //=> '525600 minutes'
- *
- * @example
- * // What is the distance from 1 January 2015
- * // to 28 January 2015, in months, rounded up?
- * const result = formatDistanceStrict(new Date(2015, 0, 28), new Date(2015, 0, 1), {
- * unit: 'month',
- * roundingMethod: 'ceil'
- * })
- * //=> '1 month'
- *
- * @example
- * // What is the distance between 1 August 2016 and 1 January 2015 in Esperanto?
- * import { eoLocale } from 'date-fns/locale/eo'
- * const result = formatDistanceStrict(new Date(2016, 7, 1), new Date(2015, 0, 1), {
- * locale: eoLocale
- * })
- * //=> '1 jaro'
- */
- export declare function formatDistanceStrict(
- laterDate: DateArg<Date> & {},
- earlierDate: DateArg<Date> & {},
- options?: FormatDistanceStrictOptions,
- ): string;
|