UNPKG

700 BJavaScriptView Raw
1import { toDate } from "./toDate.js";
2
3/**
4 * @name isLeapYear
5 * @category Year Helpers
6 * @summary Is the given date in the leap year?
7 *
8 * @description
9 * Is the given date in the leap year?
10 *
11 * @param date - The date to check
12 * @param options - The options object
13 *
14 * @returns The date is in the leap year
15 *
16 * @example
17 * // Is 1 September 2012 in the leap year?
18 * const result = isLeapYear(new Date(2012, 8, 1))
19 * //=> true
20 */
21export function isLeapYear(date, options) {
22 const _date = toDate(date, options?.in);
23 const year = _date.getFullYear();
24 return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
25}
26
27// Fallback for modularized imports:
28export default isLeapYear;