Returns whether the given year is a leap year. Passing in a Date object will return the leap year status of the year of that object and take the current timezone into account. Passing in a number will return the leap year status of that number.
This is based on https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year.
The year in number or Date format.
Date
true if the given year is a leap year; false otherwise.
true
false
import { isLeap } from "@std/datetime/is-leap";import { assertEquals } from "@std/assert";assertEquals(isLeap(new Date("1970-01-02")), false);assertEquals(isLeap(1970), false);assertEquals(isLeap(new Date("1972-01-02")), true);assertEquals(isLeap(1972), true); Copy
import { isLeap } from "@std/datetime/is-leap";import { assertEquals } from "@std/assert";assertEquals(isLeap(new Date("1970-01-02")), false);assertEquals(isLeap(1970), false);assertEquals(isLeap(new Date("1972-01-02")), true);assertEquals(isLeap(1972), true);
import { isLeap } from "@std/datetime/is-leap"; // True if the local timezone is GMT+0; false if the local timezone is GMT-1isLeap(new Date("2000-01-01"));// True regardless of the local timezoneisLeap(2000); Copy
import { isLeap } from "@std/datetime/is-leap"; // True if the local timezone is GMT+0; false if the local timezone is GMT-1isLeap(new Date("2000-01-01"));// True regardless of the local timezoneisLeap(2000);
Returns whether the given year is a leap year. Passing in a Date object will return the leap year status of the year of that object and take the current timezone into account. Passing in a number will return the leap year status of that number.
This is based on https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year.