Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

std/datetime/is_leap.ts>isLeap

The Deno Standard Library
Go to Latest
function isLeap
import { isLeap } from "https://deno.land/std@0.222.1/datetime/is_leap.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

Passing Date objects

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

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

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

Passing number values

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

isLeap(1970); // false

isLeap(1972); // true

Accounting for timezones

import { isLeap } from "https://deno.land/std@0.222.1/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.