UNPKG

875 BJavaScriptView Raw
1"use strict";
2exports.endOfSecond = endOfSecond;
3var _index = require("./toDate.js");
4
5/**
6 * @name endOfSecond
7 * @category Second Helpers
8 * @summary Return the end of a second for the given date.
9 *
10 * @description
11 * Return the end of a second for the given date.
12 * The result will be in the local timezone.
13 *
14 * @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).
15 *
16 * @param date - The original date
17 *
18 * @returns The end of a second
19 *
20 * @example
21 * // The end of a second for 1 December 2014 22:15:45.400:
22 * const result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400))
23 * //=> Mon Dec 01 2014 22:15:45.999
24 */
25function endOfSecond(date) {
26 const _date = (0, _index.toDate)(date);
27 _date.setMilliseconds(999);
28 return _date;
29}