UNPKG

1.19 kBJavaScriptView Raw
1import { toDate } from "./toDate.js";
2
3/**
4 * The {@link endOfSecond} function options.
5 */
6
7/**
8 * @name endOfSecond
9 * @category Second Helpers
10 * @summary Return the end of a second for the given date.
11 *
12 * @description
13 * Return the end of a second for the given date.
14 * The result will be in the local timezone if no `in` option is specified.
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 date - The original date
20 * @param options - An object with options
21 *
22 * @returns The end of a second
23 *
24 * @example
25 * // The end of a second for 1 December 2014 22:15:45.400:
26 * const result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400))
27 * //=> Mon Dec 01 2014 22:15:45.999
28 */
29export function endOfSecond(date, options) {
30 const _date = toDate(date, options?.in);
31 _date.setMilliseconds(999);
32 return _date;
33}
34
35// Fallback for modularized imports:
36export default endOfSecond;