UNPKG

907 BJavaScriptView Raw
1"use strict";
2exports.getDaysInYear = getDaysInYear;
3var _index = require("./isLeapYear.js");
4var _index2 = require("./toDate.js");
5
6/**
7 * @name getDaysInYear
8 * @category Year Helpers
9 * @summary Get the number of days in a year of the given date.
10 *
11 * @description
12 * Get the number of days in a year of the given date.
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 given date
17 *
18 * @returns The number of days in a year
19 *
20 * @example
21 * // How many days are in 2012?
22 * const result = getDaysInYear(new Date(2012, 0, 1))
23 * //=> 366
24 */
25function getDaysInYear(date) {
26 const _date = (0, _index2.toDate)(date);
27
28 if (String(new Date(_date)) === "Invalid Date") {
29 return NaN;
30 }
31
32 return (0, _index.isLeapYear)(_date) ? 366 : 365;
33}