UNPKG

903 BJavaScriptView Raw
1import { toDate } from "./toDate.mjs";
2
3/**
4 * @name startOfSecond
5 * @category Second Helpers
6 * @summary Return the start of a second for the given date.
7 *
8 * @description
9 * Return the start of a second 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 start of a second
17 *
18 * @example
19 * // The start of a second for 1 December 2014 22:15:45.400:
20 * const result = startOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400))
21 * //=> Mon Dec 01 2014 22:15:45.000
22 */
23export function startOfSecond(date) {
24 const _date = toDate(date);
25 _date.setMilliseconds(0);
26 return _date;
27}
28
29// Fallback for modularized imports:
30export default startOfSecond;