UNPKG

656 BJavaScriptView Raw
1"use strict";
2exports.getYear = getYear;
3var _index = require("./toDate.js");
4
5/**
6 * @name getYear
7 * @category Year Helpers
8 * @summary Get the year of the given date.
9 *
10 * @description
11 * Get the year of the given date.
12 *
13 * @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).
14 *
15 * @param date - The given date
16 *
17 * @returns The year
18 *
19 * @example
20 * // Which year is 2 July 2014?
21 * const result = getYear(new Date(2014, 6, 2))
22 * //=> 2014
23 */
24function getYear(date) {
25 return (0, _index.toDate)(date).getFullYear();
26}