1 | import { constructNow } from "./constructNow.js";
|
2 |
|
3 | /**
|
4 | * The {@link endOfTomorrow} function options.
|
5 | */
|
6 |
|
7 | /**
|
8 | * @name endOfTomorrow
|
9 | * @category Day Helpers
|
10 | * @summary Return the end of tomorrow.
|
11 | * @pure false
|
12 | *
|
13 | * @description
|
14 | * Return the end of tomorrow.
|
15 | *
|
16 | * @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).
|
17 | * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
|
18 | *
|
19 | * @param options - The options
|
20 | * @returns The end of tomorrow
|
21 | *
|
22 | * @example
|
23 | * // If today is 6 October 2014:
|
24 | * const result = endOfTomorrow()
|
25 | * //=> Tue Oct 7 2014 23:59:59.999
|
26 | */
|
27 | export function endOfTomorrow(options) {
|
28 | const now = constructNow(options?.in);
|
29 | const year = now.getFullYear();
|
30 | const month = now.getMonth();
|
31 | const day = now.getDate();
|
32 |
|
33 | const date = constructNow(options?.in);
|
34 | date.setFullYear(year, month, day + 1);
|
35 | date.setHours(23, 59, 59, 999);
|
36 | return options?.in ? options.in(date) : date;
|
37 | }
|
38 |
|
39 | // Fallback for modularized imports:
|
40 | export default endOfTomorrow;
|