UNPKG

955 BJavaScriptView Raw
1"use strict";
2exports.lastDayOfYear = lastDayOfYear;
3var _index = require("./toDate.js");
4
5/**
6 * @name lastDayOfYear
7 * @category Year Helpers
8 * @summary Return the last day of a year for the given date.
9 *
10 * @description
11 * Return the last day of a year 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 last day of a year
19 *
20 * @example
21 * // The last day of a year for 2 September 2014 11:55:00:
22 * const result = lastDayOfYear(new Date(2014, 8, 2, 11, 55, 00))
23 * //=> Wed Dec 31 2014 00:00:00
24 */
25function lastDayOfYear(date) {
26 const _date = (0, _index.toDate)(date);
27 const year = _date.getFullYear();
28 _date.setFullYear(year + 1, 0, 0);
29 _date.setHours(0, 0, 0, 0);
30 return _date;
31}