UNPKG

604 BJavaScriptView Raw
1import { toDate } from "./toDate.js";
2
3/**
4 * The {@link getYear} function options.
5 */
6
7/**
8 * @name getYear
9 * @category Year Helpers
10 * @summary Get the year of the given date.
11 *
12 * @description
13 * Get the year of the given date.
14 *
15 * @param date - The given date
16 * @param options - An object with options
17 *
18 * @returns The year
19 *
20 * @example
21 * // Which year is 2 July 2014?
22 * const result = getYear(new Date(2014, 6, 2))
23 * //=> 2014
24 */
25export function getYear(date, options) {
26 return toDate(date, options?.in).getFullYear();
27}
28
29// Fallback for modularized imports:
30export default getYear;