Taskintro
Check for a leap year
Also called leap year, is leap year, isleap, IsLeapYear, Year.isLeap, Gregorian leap year rule, February 29, the year 1900 problem.
Check if a year is a leap year of the Gregorian calendar. A year divisible by 4 is a leap year, except a century year that is not divisible by 400, so 1900 was not a leap year and 2000 was.
- Evidence
- Code in 10 languages
Task
Check if a year is a leap year of the Gregorian calendar. A leap year has 366 days, with February 29 as the extra day.
The rule has three parts:
- A year divisible by 4 is a leap year,
- except a year divisible by 100, which is not,
- except a year divisible by 400, which is.
So 2024 and 2000 are leap years, and 2023, 1900 and 2100 are not. 400 Gregorian years have 97 leap years and 146097 days.
The contract is_leap_year(year) returns true or false. The years use the proleptic Gregorian calendar, in which the rule applies to all years, also the years before 1582. The numbering is astronomical, as in ISO 8601: year 0 is 1 BC, and year -1 is 2 BC. Year 0 is divisible by 400, so it is a leap year.
Solutions
The rule fits in one expression: year % 4 == 0 && (year % 100 != 0 || year % 400 == 0). A test for a remainder of 0 is also right for negative years, because -4 % 4 is 0 in each language.
- Python.
calendar.isleap(year)takes any integer.calendar.leapdays(y1, y2)counts the leap years fromy1toy2, withy2not included. - JavaScript. There is no function, so the solution writes the rule. The trick
new Date(year, 1, 29).getMonth() === 1reads the years 0 to 99 as 1900 to 1999, so it gives false for the year 0. - TypeScript. The same code as JavaScript, with the types
numberandboolean. - Java.
Year.isLeap(long year)is a static method. The documentation says that it checks "according to the ISO proleptic calendar system rules", and that the numbering has a year 0.LocalDate.isLeapYear()gives the same result for a date. - C#.
DateTime.IsLeapYear(int year)throwsArgumentOutOfRangeExceptionwhen the year is less than 1 or greater than 9999. The solution writes the rule, and the tests compare it withDateTime.IsLeapYearfor the years 1 to 9999. - Go. The
timepackage has no exported function for the rule, so the solution writes it. The tests check it againstYearDay()of December 31, which is 366 in a leap year. - Rust. The standard library has no calendar, so the solution writes the rule for
i64. - C. The C standard library has no function for the rule, so the solution writes it.
- C++.
std::chrono::year{y}.is_leap()applies the rule. Ayearholds the years -32767 to 32767. - Bash. The arithmetic command
(( ... ))returns status 0 when the expression is not zero, sois_leap_yearcan be used in anifstatement.
The library function of Python and the count of 400 years:
import calendar
for year in [2024, 2023, 1900, 2000, 2100, 0, -4]:
print(year, calendar.isleap(year))
print(calendar.leapdays(2000, 2400))
2024 True
2023 False
1900 False
2000 True
2100 False
0 True
-4 True
97
Edge cases
The cases are in cases/basic.jsonl and cases/edge.jsonl.
divisible-by-4andnot-divisible-by-4: 2024 is a leap year and 2023 is not.century,next-centuryandyear-1700: 1900, 2100 and 1700 are divisible by 100 and not by 400.divisible-by-400,year-1600andyear-2400: these century years are leap years.year-1,year-4andyear-100: small years follow the same rule. An API that reads them as 1901, 1904 and 2000 can give the wrong answer foryear-100.year-1500-julian-leapandyear-1582: 1500 was a leap year in the Julian calendar, but not in the proleptic Gregorian calendar.year-9999: the last year of most date types.year-zero,year-minus-1,year-minus-4,year-minus-100andyear-minus-400: year 0 and the negative years of astronomical numbering. Year 0 and -4 and -400 are leap years.
Pitfalls
- The rules in the wrong order. A test for 4 that returns at once never reaches the tests for 100 and 400. The function below says that 1900 and 2100 are leap years:
This code runs but gives a wrong answer on purpose.
def is_leap(year):
if year % 4 == 0:
return True
if year % 100 == 0:
return False
return year % 400 == 0
print(is_leap(1900), is_leap(2100), is_leap(2000))
True True True
Test the largest divisor first, or use the single expression of the rule.
-
The year 1900 in spreadsheets. Microsoft says that "Microsoft Excel incorrectly assumes that the year 1900 is a leap year." Lotus 1-2-3 had this error first, and Excel kept it for compatibility. Excel has a February 29, 1900, and the document says that "The WEEKDAY function returns incorrect values for dates before March 1, 1900." The same document says that Excel "correctly handles all other leap years, including century years that are not leap years (for example, 2100)".
-
A date type with a limited range. Python
dateand .NETDateTimehold only the years 1 to 9999.calendar.isleapworks for year 0, but a date in year 0 raises an error:
This code runs but gives a wrong answer on purpose.
import calendar
from datetime import date
print(calendar.isleap(0))
try:
date(0, 2, 29)
except ValueError as e:
print(type(e).__name__)
True
ValueError
This code runs but gives a wrong answer on purpose.
try
{
Console.WriteLine(DateTime.IsLeapYear(0));
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine(e.GetType().Name);
}
Console.WriteLine(DateTime.IsLeapYear(2000));
ArgumentOutOfRangeException
True
- Historical dates used the Julian calendar. The Julian calendar has a leap year every 4 years with no exception for century years. The countries of Europe changed to the Gregorian calendar between 1582 and 1923, so a historical date before the change in a country needs the Julian rule:
import calendar
def is_julian_leap(year):
return year % 4 == 0
for year in [1500, 1582, 1600, 1700]:
print(year, is_julian_leap(year), calendar.isleap(year))
1500 True False
1582 False False
1600 True True
1700 True False
Related tasks
- Add days to a date: February 29 plus one year.
- Compute the difference of two dates: a year of 365 or 366 days.
- Find the day of the week: a leap day moves the weekdays of the rest of the year.
- Parse and format a date: a parser that accepts or rejects February 29.
See Calendar arithmetic for the rules of the Gregorian calendar.
Code
The build runs the native tests of each language in a pinned toolchain.
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/check-for-a-leap-year/.
import calendar
def is_leap_year(year: int) -> bool:
"""Return True for a leap year of the proleptic Gregorian calendar."""
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
def is_leap_year_library(year: int) -> bool:
"""Return the same result with the standard library."""
return calendar.isleap(year)
test_leap.py 44 lines
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/check-for-a-leap-year/.
import calendar
import pytest
from leap import is_leap_year, is_leap_year_library
CASES = [
("divisible-by-4", 2024, True),
("not-divisible-by-4", 2023, False),
("century", 1900, False),
("divisible-by-400", 2000, True),
("next-century", 2100, False),
("year-1600", 1600, True),
("year-1700", 1700, False),
("year-2400", 2400, True),
("year-1", 1, False),
("year-4", 4, True),
("year-100", 100, False),
("year-1500-julian-leap", 1500, False),
("year-1582", 1582, False),
("year-9999", 9999, False),
("year-zero", 0, True),
("year-minus-1", -1, False),
("year-minus-4", -4, True),
("year-minus-100", -100, False),
("year-minus-400", -400, True),
]
@pytest.mark.parametrize(("name", "year", "want"), CASES, ids=[c[0] for c in CASES])
def test_is_leap_year(name, year, want):
assert is_leap_year(year) is want
assert is_leap_year_library(year) is want
def test_same_as_library_for_every_year():
assert all(is_leap_year(y) == calendar.isleap(y) for y in range(-9999, 10000))
def test_leap_days_in_400_years():
assert sum(is_leap_year(y) for y in range(2000, 2400)) == 97
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
#ifndef IS_LEAP_YEAR_HPP
#define IS_LEAP_YEAR_HPP
#include <chrono>
// Returns true for a leap year of the proleptic Gregorian calendar.
// std::chrono::year holds the years -32767 to 32767.
inline bool is_leap_year(int y) {
return std::chrono::year{y}.is_leap();
}
#endif
test_leap.cpp 60 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
#include <cstdio>
#include "leap.hpp"
namespace {
struct test_case {
const char* name;
int year;
bool want;
};
const test_case cases[] = {
{"divisible-by-4", 2024, true},
{"not-divisible-by-4", 2023, false},
{"century", 1900, false},
{"divisible-by-400", 2000, true},
{"next-century", 2100, false},
{"year-1600", 1600, true},
{"year-1700", 1700, false},
{"year-2400", 2400, true},
{"year-1", 1, false},
{"year-4", 4, true},
{"year-100", 100, false},
{"year-1500-julian-leap", 1500, false},
{"year-1582", 1582, false},
{"year-9999", 9999, false},
{"year-zero", 0, true},
{"year-minus-1", -1, false},
{"year-minus-4", -4, true},
{"year-minus-100", -100, false},
{"year-minus-400", -400, true},
};
} // namespace
int main() {
int failures = 0;
for (const auto& c : cases) {
if (is_leap_year(c.year) != c.want) {
std::printf("FAIL %s\n", c.name);
++failures;
}
}
for (int year = -9999; year <= 9999; ++year) {
const bool rule = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
if (is_leap_year(year) != rule) {
std::printf("FAIL %d\n", year);
++failures;
}
}
if (failures != 0) {
return 1;
}
std::printf("ok\n");
return 0;
}
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
import java.time.Year;
/** Checks for a leap year of the proleptic Gregorian calendar. */
public final class Leap {
private Leap() {}
/** Returns true for a leap year. Year.isLeap uses the ISO proleptic calendar with year 0. */
public static boolean isLeapYear(int year) {
return Year.isLeap(year);
}
}
LeapTest.java 58 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.time.LocalDate;
import java.time.Year;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class LeapTest {
static Stream<Arguments> cases() {
return Stream.of(
Arguments.of("divisible-by-4", 2024, true),
Arguments.of("not-divisible-by-4", 2023, false),
Arguments.of("century", 1900, false),
Arguments.of("divisible-by-400", 2000, true),
Arguments.of("next-century", 2100, false),
Arguments.of("year-1600", 1600, true),
Arguments.of("year-1700", 1700, false),
Arguments.of("year-2400", 2400, true),
Arguments.of("year-1", 1, false),
Arguments.of("year-4", 4, true),
Arguments.of("year-100", 100, false),
Arguments.of("year-1500-julian-leap", 1500, false),
Arguments.of("year-1582", 1582, false),
Arguments.of("year-9999", 9999, false),
Arguments.of("year-zero", 0, true),
Arguments.of("year-minus-1", -1, false),
Arguments.of("year-minus-4", -4, true),
Arguments.of("year-minus-100", -100, false),
Arguments.of("year-minus-400", -400, true)
);
}
@ParameterizedTest(name = "{0}")
@MethodSource("cases")
void isLeapYear(String name, int year, boolean want) {
assertEquals(want, Leap.isLeapYear(year));
}
@Test
void sameAsArithmetic() {
for (int year = -9999; year <= 9999; year++) {
boolean rule = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
assertEquals(rule, Year.isLeap(year), Integer.toString(year));
}
}
@Test
void localDateAgrees() {
assertEquals(true, LocalDate.of(2024, 1, 1).isLeapYear());
assertEquals(false, LocalDate.of(1900, 1, 1).isLeapYear());
}
}
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
#include "leap.h"
// The % operator of C keeps the sign of the left operand, so -4 % 4 is 0
// and -1 % 4 is -1. A test for 0 is right for negative years too.
bool is_leap_year(int year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
leap.h 12 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
#ifndef IS_LEAP_YEAR_H
#define IS_LEAP_YEAR_H
#include <stdbool.h>
// Returns true for a leap year of the proleptic Gregorian calendar.
bool is_leap_year(int year);
#endif
test_leap.c 60 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
#include "leap.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct test_case {
const char *name;
int year;
bool want;
};
static const struct test_case cases[] = {
{"divisible-by-4", 2024, true},
{"not-divisible-by-4", 2023, false},
{"century", 1900, false},
{"divisible-by-400", 2000, true},
{"next-century", 2100, false},
{"year-1600", 1600, true},
{"year-1700", 1700, false},
{"year-2400", 2400, true},
{"year-1", 1, false},
{"year-4", 4, true},
{"year-100", 100, false},
{"year-1500-julian-leap", 1500, false},
{"year-1582", 1582, false},
{"year-9999", 9999, false},
{"year-zero", 0, true},
{"year-minus-1", -1, false},
{"year-minus-4", -4, true},
{"year-minus-100", -100, false},
{"year-minus-400", -400, true},
};
int main(void) {
int failures = 0;
for (size_t i = 0; i < sizeof cases / sizeof cases[0]; i++) {
const struct test_case *c = &cases[i];
if (is_leap_year(c->year) != c->want) {
printf("FAIL %s\n", c->name);
failures++;
}
}
int count = 0;
for (int year = 2000; year < 2400; year++) {
count += is_leap_year(year);
}
if (count != 97) {
printf("FAIL %d leap years in 400 years\n", count);
failures++;
}
if (failures != 0) {
return EXIT_FAILURE;
}
printf("ok\n");
return EXIT_SUCCESS;
}
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
using System;
/// <summary>Checks for a leap year of the proleptic Gregorian calendar.</summary>
public static class Leap
{
/// <summary>Returns true for a leap year. DateTime.IsLeapYear accepts only the years 1 to 9999, so the rule is written out.</summary>
public static bool IsLeapYear(int year)
{
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}
}
LeapTests.cs 54 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
using System;
using Xunit;
public sealed class LeapTests
{
public static TheoryData<string, int, bool> Cases => new()
{
{ "divisible-by-4", 2024, true },
{ "not-divisible-by-4", 2023, false },
{ "century", 1900, false },
{ "divisible-by-400", 2000, true },
{ "next-century", 2100, false },
{ "year-1600", 1600, true },
{ "year-1700", 1700, false },
{ "year-2400", 2400, true },
{ "year-1", 1, false },
{ "year-4", 4, true },
{ "year-100", 100, false },
{ "year-1500-julian-leap", 1500, false },
{ "year-1582", 1582, false },
{ "year-9999", 9999, false },
{ "year-zero", 0, true },
{ "year-minus-1", -1, false },
{ "year-minus-4", -4, true },
{ "year-minus-100", -100, false },
{ "year-minus-400", -400, true },
};
[Theory]
[MemberData(nameof(Cases))]
public void IsLeapYear(string name, int year, bool want)
{
Assert.NotNull(name);
Assert.Equal(want, Leap.IsLeapYear(year));
}
[Fact]
public void SameAsDateTimeInItsRange()
{
for (var year = 1; year <= 9999; year++)
{
Assert.Equal(DateTime.IsLeapYear(year), Leap.IsLeapYear(year));
}
}
[Fact]
public void DateTimeRejectsYearZero()
{
Assert.Throws<ArgumentOutOfRangeException>(() => DateTime.IsLeapYear(0));
}
}
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
/** Returns true for a leap year of the proleptic Gregorian calendar. */
export function isLeapYear(year) {
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
}
leap.test.js 43 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
import assert from "node:assert/strict";
import { test } from "node:test";
import { isLeapYear } from "./leap.js";
const cases = [
["divisible-by-4", 2024, true],
["not-divisible-by-4", 2023, false],
["century", 1900, false],
["divisible-by-400", 2000, true],
["next-century", 2100, false],
["year-1600", 1600, true],
["year-1700", 1700, false],
["year-2400", 2400, true],
["year-1", 1, false],
["year-4", 4, true],
["year-100", 100, false],
["year-1500-julian-leap", 1500, false],
["year-1582", 1582, false],
["year-9999", 9999, false],
["year-zero", 0, true],
["year-minus-1", -1, false],
["year-minus-4", -4, true],
["year-minus-100", -100, false],
["year-minus-400", -400, true],
];
for (const [name, year, want] of cases) {
test(name, () => {
assert.equal(isLeapYear(year), want);
});
}
test("leap days in 400 years", () => {
let count = 0;
for (let year = 2000; year < 2400; year++) {
if (isLeapYear(year)) count++;
}
assert.equal(count, 97);
});
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
/** Returns true for a leap year of the proleptic Gregorian calendar. */
export function isLeapYear(year: number): boolean {
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
}
leap.test.ts 43 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
import assert from "node:assert/strict";
import { test } from "node:test";
import { isLeapYear } from "./leap.ts";
const cases: [string, number, boolean][] = [
["divisible-by-4", 2024, true],
["not-divisible-by-4", 2023, false],
["century", 1900, false],
["divisible-by-400", 2000, true],
["next-century", 2100, false],
["year-1600", 1600, true],
["year-1700", 1700, false],
["year-2400", 2400, true],
["year-1", 1, false],
["year-4", 4, true],
["year-100", 100, false],
["year-1500-julian-leap", 1500, false],
["year-1582", 1582, false],
["year-9999", 9999, false],
["year-zero", 0, true],
["year-minus-1", -1, false],
["year-minus-4", -4, true],
["year-minus-100", -100, false],
["year-minus-400", -400, true],
];
for (const [name, year, want] of cases) {
test(name, () => {
assert.equal(isLeapYear(year), want);
});
}
test("leap days in 400 years", () => {
let count = 0;
for (let year = 2000; year < 2400; year++) {
if (isLeapYear(year)) count++;
}
assert.equal(count, 97);
});
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
// Package leap checks for a leap year of the proleptic Gregorian calendar.
package leap
// IsLeapYear returns true for a leap year. The time package has no exported
// function for this rule.
func IsLeapYear(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}
leap_test.go 55 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
package leap
import (
"testing"
"time"
)
var cases = []struct {
name string
year int
want bool
}{
{"divisible-by-4", 2024, true},
{"not-divisible-by-4", 2023, false},
{"century", 1900, false},
{"divisible-by-400", 2000, true},
{"next-century", 2100, false},
{"year-1600", 1600, true},
{"year-1700", 1700, false},
{"year-2400", 2400, true},
{"year-1", 1, false},
{"year-4", 4, true},
{"year-100", 100, false},
{"year-1500-julian-leap", 1500, false},
{"year-1582", 1582, false},
{"year-9999", 9999, false},
{"year-zero", 0, true},
{"year-minus-1", -1, false},
{"year-minus-4", -4, true},
{"year-minus-100", -100, false},
{"year-minus-400", -400, true},
}
func TestIsLeapYear(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := IsLeapYear(c.year); got != c.want {
t.Fatalf("got %v, want %v", got, c.want)
}
})
}
}
// The last day of a leap year is day 366 of the year.
func TestSameAsYearDay(t *testing.T) {
for year := -9999; year <= 9999; year++ {
last := time.Date(year, time.December, 31, 0, 0, 0, 0, time.UTC)
if got := last.YearDay() == 366; got != IsLeapYear(year) {
t.Fatalf("%d: YearDay %d", year, last.YearDay())
}
}
}
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
/// Returns true for a leap year of the proleptic Gregorian calendar.
pub fn is_leap_year(year: i64) -> bool {
year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
}
tests/leap_test.rs 38 lines
// SPDX-License-Identifier: MIT
// Part of https://programming.tamnd.com/check-for-a-leap-year/.
use algo_check_for_a_leap_year::is_leap_year;
const CASES: &[(&str, i64, bool)] = &[
("divisible-by-4", 2024, true),
("not-divisible-by-4", 2023, false),
("century", 1900, false),
("divisible-by-400", 2000, true),
("next-century", 2100, false),
("year-1600", 1600, true),
("year-1700", 1700, false),
("year-2400", 2400, true),
("year-1", 1, false),
("year-4", 4, true),
("year-100", 100, false),
("year-1500-julian-leap", 1500, false),
("year-1582", 1582, false),
("year-9999", 9999, false),
("year-zero", 0, true),
("year-minus-1", -1, false),
("year-minus-4", -4, true),
("year-minus-100", -100, false),
("year-minus-400", -400, true),
];
#[test]
fn cases() {
for &(name, year, want) in CASES {
assert_eq!(is_leap_year(year), want, "{name}");
}
}
#[test]
fn leap_days_in_400_years() {
assert_eq!((2000..2400).filter(|&y| is_leap_year(y)).count(), 97);
}
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/check-for-a-leap-year/.
# is_leap_year YEAR
# Returns status 0 for a leap year of the proleptic Gregorian calendar and
# status 1 otherwise, so it can be used in an if statement.
is_leap_year() {
local year=$1
(( year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) ))
}
test_leap.bats 27 lines
#!/usr/bin/env bats
# SPDX-License-Identifier: MIT
# Part of https://programming.tamnd.com/check-for-a-leap-year/.
setup() {
source "$BATS_TEST_DIRNAME/leap.sh"
}
@test "divisible-by-4" { run is_leap_year 2024; [ "$status" -eq 0 ]; }
@test "not-divisible-by-4" { run is_leap_year 2023; [ "$status" -eq 1 ]; }
@test "century" { run is_leap_year 1900; [ "$status" -eq 1 ]; }
@test "divisible-by-400" { run is_leap_year 2000; [ "$status" -eq 0 ]; }
@test "next-century" { run is_leap_year 2100; [ "$status" -eq 1 ]; }
@test "year-1600" { run is_leap_year 1600; [ "$status" -eq 0 ]; }
@test "year-1700" { run is_leap_year 1700; [ "$status" -eq 1 ]; }
@test "year-2400" { run is_leap_year 2400; [ "$status" -eq 0 ]; }
@test "year-1" { run is_leap_year 1; [ "$status" -eq 1 ]; }
@test "year-4" { run is_leap_year 4; [ "$status" -eq 0 ]; }
@test "year-100" { run is_leap_year 100; [ "$status" -eq 1 ]; }
@test "year-1500-julian-leap" { run is_leap_year 1500; [ "$status" -eq 1 ]; }
@test "year-1582" { run is_leap_year 1582; [ "$status" -eq 1 ]; }
@test "year-9999" { run is_leap_year 9999; [ "$status" -eq 1 ]; }
@test "year-zero" { run is_leap_year 0; [ "$status" -eq 0 ]; }
@test "year-minus-1" { run is_leap_year -1; [ "$status" -eq 1 ]; }
@test "year-minus-4" { run is_leap_year -4; [ "$status" -eq 0 ]; }
@test "year-minus-100" { run is_leap_year -100; [ "$status" -eq 1 ]; }
@test "year-minus-400" { run is_leap_year -400; [ "$status" -eq 0 ]; }
References
- Wikipedia, Gregorian calendar, the introduction
- The Python Standard Library, calendar, calendar.isleap; calendar.leapdays
- The Python Standard Library, datetime, datetime.MINYEAR; class date
- Java SE 25 API, java.time.Year, the description of the class; isLeap(long)
- .NET API reference, DateTime.IsLeapYear, Exceptions
- Go standard library, time, func (Time) YearDay
- cppreference.com, std::chrono::year::is_leap, the description of the function
- cppreference.com, std::chrono::year, the description of the class
- Microsoft Learn, Excel incorrectly assumes that the year 1900 is a leap year, Summary; More information
- Wikipedia, Leap year, Gregorian calendar
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Code (bash) | I0 not checked yet |
|
| Code (c) | I0 not checked yet |
|
| Code (cpp) | I0 not checked yet |
|
| Code (csharp) | I0 not checked yet |
|
| Code (go) | I0 not checked yet |
|
| Code (java) | I0 not checked yet |
|
| Code (javascript) | I0 not checked yet |
|
| Code (python) | I0 not checked yet |
|
| Code (rust) | I0 not checked yet |
|
| Code (typescript) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag QSBRWK Edit this page History Report an error Markdown