Skip to main content
Module

std/datetime/mod.ts>isLeap

The Deno Standard Library
Latest
function isLeap
import { isLeap } from "https://deno.land/std@0.223.0/datetime/mod.ts";

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.

Examples

Basic usage

import { isLeap } from "https://deno.land/std@0.223.0/datetime/is_leap.ts";

isLeap(new Date("1970-01-02")); // false

isLeap(1970); // false

isLeap(new Date("1972-01-02")); // true

isLeap(1972); // true

Accounting for timezones

import { isLeap } from "https://deno.land/std@0.223.0/datetime/is_leap.ts";

isLeap(new Date("2000-01-01"));
// true if the local timezone is GMT+0; false if the local timezone is GMT-1

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

Parameters

year: Date | number

The year in number or Date format.

Returns

boolean

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