UNPKG

1.43 kBJavaScriptView Raw
1"use strict";
2exports.lastDayOfISOWeekYear = lastDayOfISOWeekYear;
3var _index = require("./getISOWeekYear.js");
4var _index2 = require("./startOfISOWeek.js");
5var _index3 = require("./constructFrom.js");
6
7/**
8 * @name lastDayOfISOWeekYear
9 * @category ISO Week-Numbering Year Helpers
10 * @summary Return the last day of an ISO week-numbering year for the given date.
11 *
12 * @description
13 * Return the last day of an ISO week-numbering year,
14 * which always starts 3 days before the year's first Thursday.
15 * The result will be in the local timezone.
16 *
17 * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
18 *
19 * @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).
20 *
21 * @param date - The original date
22 *
23 * @returns The end of an ISO week-numbering year
24 *
25 * @example
26 * // The last day of an ISO week-numbering year for 2 July 2005:
27 * const result = lastDayOfISOWeekYear(new Date(2005, 6, 2))
28 * //=> Sun Jan 01 2006 00:00:00
29 */
30function lastDayOfISOWeekYear(date) {
31 const year = (0, _index.getISOWeekYear)(date);
32 const fourthOfJanuary = (0, _index3.constructFrom)(date, 0);
33 fourthOfJanuary.setFullYear(year + 1, 0, 4);
34 fourthOfJanuary.setHours(0, 0, 0, 0);
35 const _date = (0, _index2.startOfISOWeek)(fourthOfJanuary);
36 _date.setDate(_date.getDate() - 1);
37 return _date;
38}