Function isLeap

  • 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.

    Parameters

    • year: number | Date

      The year in number or Date format.

    Returns boolean

    true if the given year is a leap year; false otherwise.

    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-1
    isLeap(new Date("2000-01-01"));

    // True regardless of the local timezone
    isLeap(2000);