Reference · Dates

date.is_leap_year

signature
date.is_leap_year(int | str) -> bool

What it does

Whether a year has a 29th of February: true for years divisible by 4, except centuries, except those divisible by 400 (the Gregorian rule). It takes the year as an int, or a date or date-time, whose year it uses.

Examples

print(date.is_leap_year(2024), date.is_leap_year(2023))print(date.is_leap_year(1900), date.is_leap_year(2000))print(date.is_leap_year("2024-06-01"))
output
true falsefalse truetrue

Edge cases

print(date.is_leap_year("2024-12-31T23:00:00-05:00"))print(date.is_leap_year(0), date.is_leap_year(-4), date.is_leap_year(2024.0))
output
truetrue true true

Errors

A string that is not a date, or a value that is neither an int nor a string, is a runtime error, not an error value.

this one fails
print(date.is_leap_year("2024"))
output
line 1: `date.is_leap_year` expects a date or a date-time as argument 1, got "2024"

Chaining

print(range(2023, 2029) | filter(date.is_leap_year))print("2024-02-10" | date.is_leap_year)
output
[2024, 2028]true

See also

date.days_in_month, date.parts, date.add_years, date.end_of_month

Thread
6Useful? Like it, or add to its thread below.

Thread 0 posts

On date.is_leap_year(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo