dates.is-leap-year
Whether a year is a Gregorian leap year: every 4th, except centuries, except every 400th.
1.0.0 · published 2026-10-03 by charlie · Anterra
Pinned by 15 tests, run in TypeScript, Python and Rust.
What it does
True when February of the year has 29 days. The rule is the full Gregorian one: divisible by 4, except century years, except those divisible by 400. So 2024 and 2000 were leap years and 1900 was not, and 2100 will not be. Code that tests only `year % 4` gets 1900 and 2100 wrong, and 1900 is still inside real data (pension and land records).
The rule itself lives in dates.add-days, the calendar kernel every dates capability shares; this package is the searchable, validated front door to it, so nobody re-types the rule.
For example
is_leap_year(2,024)→ true 2024 is divisible by 4, so a leap yearis_leap_year(2,026)→ false 2026 is an ordinary yearis_leap_year(1,900)→ false 1900 is a century year and not divisible by 400: not a leap year, though 1900 % 4 is 0
The function
The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.
def is_leap_year(year: int) -> bool
| year | int | 1 to 9999, the years an ISO date can express |
| returns | bool |
Your code names it in one line, in the file that uses it
from fune.dates.is_leap_year import is_leap_year # dates.is-leap-year@^1
Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.
from .dates_add_days import is_leap_year as _kernel_is_leap_year ← from dates.add-days ^1.0.0 · built alongside by fune
def is_leap_year(year: int) -> bool:
"""Whether a year is a Gregorian leap year.
The rule lives in dates.add-days; this adds the range check so a year of 0
or 10000 fails loudly rather than answering for a year no ISO date can name.
"""
if isinstance(year, bool) or not isinstance(year, int):
raise TypeError("year must be an integer, received %r" % (year,))
if year < 1 or year > 9999:
raise ValueError("year %s is outside the supported range 1 to 9999" % (year,))
return _kernel_is_leap_year(year)Install
fune build
With that line in your source, in a Python project (language python in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the Python package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:
fune add dates.is-leap-year
The manifest, vectors and README with only the Python implementation. Install it without the registry with fune add ./dates.is-leap-year-1.0.0-python.fune, or fetch it from a terminal with fune pull dates.is-leap-year@1.0.0:python.
The whole function, every language, is one file too: dates.is-leap-year-1.0.0.fune, 5,878 bytes, sha256 41bf219585d5ca69808b1f991cae821ac237a69e9b4e28b0b4ac998c7c3d5049. It installs into a project of any language.
Customise it in your app
The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.
before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.
# fune: before dates.is-leap-year
after — your function gets the result and the arguments, and returns the final result.
# fune: after dates.is-leap-year
replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.
# fune: replace dates.add-days in dates.is-leap-year
step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show dates.is-leap-year --steps.
# fune: step dates.is-leap-year after <n|label>
Tests
A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.
| Case | Arguments | Expected | |
|---|---|---|---|
| 2024 is divisible by 4, so a leap year | 2,024 | → | true |
| 2026 is an ordinary year | 2,026 | → | false |
| 1900 is a century year and not divisible by 400: not a leap year, though 1900 % 4 is 0 | 1,900 | → | false |
| 2000 is divisible by 400, so it is a leap year after all | 2,000 | → | true |
| 2100 will not be a leap year | 2,100 | → | false |
| 2400 will be | 2,400 | → | true |
| 2023, the year before a leap year | 2,023 | → | false |
| year 1 is not a leap year | 1 | → | false |
| year 4 is the first leap year in range | 4 | → | true |
| 9996 is the last leap year in range | 9,996 | → | true |
Show the other 5 tests
| Case | Arguments | Expected | |
|---|---|---|---|
| 9999 is the last supported year | 9,999 | → | false |
| year 0 is outside the supported range | 0 | → | error: outside the supported range |
| year 10000 is outside the supported range | 10,000 | → | error: outside the supported range |
| a negative year is rejected | -4 | → | error: outside the supported range |
| a fractional year is an error | 2,024.5 | → | error: year must be an integer |
More from the author
The year must be a whole number from 1 to 9999, the range the rest of the dates family supports. The Gregorian calendar is applied proleptically: years before 1582 (1752 in Britain) are answered by the Gregorian rule, not the Julian one that was actually in use then.
Files
| Path | Bytes |
|---|---|
| README.md | 816 |
| impl/python.py | 612 |
| impl/rust.rs | 951 |
| impl/typescript.ts | 595 |
| vectors.json | 1,407 |