Skip to main content

@std/datetime@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function isLeap
isLeap(year: Date | number): boolean

Returns whether the given date or year (in number) is a leap year or not in the local time zone. based on: https://docs.microsoft.com/en-us/office/troubleshoot/excel/determine-a-leap-year

Examples

Example 1

import { isLeap } from "@std/datetime/is_leap";

isLeap(new Date("1970-01-02")); // => returns false
isLeap(new Date("1972-01-02")); // => returns true
isLeap(new Date("2000-01-02")); // => returns true
isLeap(new Date("2100-01-02")); // => returns false
isLeap(1972); // => returns true

Some dates may return different values depending on your timezone.

Example 2

import { isLeap } from "@std/datetime/is_leap";

isLeap(new Date("2000-01-01")); // => returns true if the local timezone is GMT+0, returns false if the local timezone is GMT-1
isLeap(2000); // => returns true regardless of the local timezone

Parameters

year in number or Date format

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/datetime

Import symbol

import { isLeap } from "@std/datetime/is_leap";
or

Import directly with a jsr specifier

import { isLeap } from "jsr:@std/datetime/is_leap";