UNPKG

842 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name setHours
5 * @category Hour Helpers
6 * @summary Set the hours to the given date.
7 *
8 * @description
9 * Set the hours to the given date.
10 *
11 * @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).
12 *
13 * @param date - The date to be changed
14 * @param hours - The hours of the new date
15 *
16 * @returns The new date with the hours set
17 *
18 * @example
19 * // Set 4 hours to 1 September 2014 11:30:00:
20 * const result = setHours(new Date(2014, 8, 1, 11, 30), 4)
21 * //=> Mon Sep 01 2014 04:30:00
22 */
23export function setHours(date, hours) {
24 const _date = toDate(date);
25 _date.setHours(hours);
26 return _date;
27}
28
29// Fallback for modularized imports:
30export default setHours;