UNPKG

865 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name endOfHour
5 * @category Hour Helpers
6 * @summary Return the end of an hour for the given date.
7 *
8 * @description
9 * Return the end of an hour for the given date.
10 * The result will be in the local timezone.
11 *
12 * @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).
13 *
14 * @param date - The original date
15 *
16 * @returns The end of an hour
17 *
18 * @example
19 * // The end of an hour for 2 September 2014 11:55:00:
20 * const result = endOfHour(new Date(2014, 8, 2, 11, 55))
21 * //=> Tue Sep 02 2014 11:59:59.999
22 */
23export function endOfHour(date) {
24 const _date = toDate(date);
25 _date.setMinutes(59, 59, 999);
26 return _date;
27}
28
29// Fallback for modularized imports:
30export default endOfHour;