isLeap
import { isLeap } from "jsr:@ende/datetime";function
function isLeap(year: Date | number): booleanReturns 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.
year: Date | numberThe year in number or
Dateformat.
Returns
true if the given year is a leap year; false otherwise.
Example: Basic usage
import { isLeap } from "@ende/datetime/is-leap";
import { assertEquals } from "@ende/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);
Example: Accounting for timezones
import { isLeap } from "@ende/datetime/is-leap";
// True if the local timezone is GMT+0; false if the local timezone is GMT-1
isLeap(new Date("2000-01-01"));
// True regardless of the local timezone
isLeap(2000);