1 | import type { ContextOptions, DateArg } from "./types.js";
|
2 | /**
|
3 | * The {@link differenceInDays} function options.
|
4 | */
|
5 | export interface DifferenceInDaysOptions extends ContextOptions<Date> {}
|
6 | /**
|
7 | * @name differenceInDays
|
8 | * @category Day Helpers
|
9 | * @summary Get the number of full days between the given dates.
|
10 | *
|
11 | * @description
|
12 | * Get the number of full day periods between two dates. Fractional days are
|
13 | * truncated towards zero.
|
14 | *
|
15 | * One "full day" is the distance between a local time in one day to the same
|
16 | * local time on the next or previous day. A full day can sometimes be less than
|
17 | * or more than 24 hours if a daylight savings change happens between two dates.
|
18 | *
|
19 | * To ignore DST and only measure exact 24-hour periods, use this instead:
|
20 | * `Math.trunc(differenceInHours(dateLeft, dateRight)/24)|0`.
|
21 | *
|
22 | * @param laterDate - The later date
|
23 | * @param earlierDate - The earlier date
|
24 | * @param options - An object with options
|
25 | *
|
26 | * @returns The number of full days according to the local timezone
|
27 | *
|
28 | * @example
|
29 | * // How many full days are between
|
30 | * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?
|
31 | * const result = differenceInDays(
|
32 | * new Date(2012, 6, 2, 0, 0),
|
33 | * new Date(2011, 6, 2, 23, 0)
|
34 | * )
|
35 | * //=> 365
|
36 | *
|
37 | * @example
|
38 | * // How many full days are between
|
39 | * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?
|
40 | * const result = differenceInDays(
|
41 | * new Date(2011, 6, 3, 0, 1),
|
42 | * new Date(2011, 6, 2, 23, 59)
|
43 | * )
|
44 | * //=> 0
|
45 | *
|
46 | * @example
|
47 | * // How many full days are between
|
48 | * // 1 March 2020 0:00 and 1 June 2020 0:00 ?
|
49 | * // Note: because local time is used, the
|
50 | * // result will always be 92 days, even in
|
51 | * // time zones where DST starts and the
|
52 | * // period has only 92*24-1 hours.
|
53 | * const result = differenceInDays(
|
54 | * new Date(2020, 5, 1),
|
55 | * new Date(2020, 2, 1)
|
56 | * )
|
57 | * //=> 92
|
58 | */
|
59 | export declare function differenceInDays(
|
60 | laterDate: DateArg<Date> & {},
|
61 | earlierDate: DateArg<Date> & {},
|
62 | options?: DifferenceInDaysOptions | undefined,
|
63 | ): number;
|