Functional Weave
Code in Rust

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 year
  • is_leap_year(2,026) → false 2026 is an ordinary year
  • is_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.

pub fn is_leap_year(year: i64) -> bool
yearint1 to 9999, the years an ISO date can express
returnsbool

Your code names it in one line, in the file that uses it

fune!(dates.is-leap-year@^1);  // then call is_leap_year(…)
impl/rust.rs · 26 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::dates_add_days::is_leap_year as kernel_is_leap_year;

/// 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.
///
/// # Panics
/// Panics if the year is outside 1-9999.
pub fn is_leap_year(year: i64) -> bool {
    if !(1..=9999).contains(&year) {
        panic!("year {} is outside the supported range 1 to 9999", year);
    }
    kernel_is_leap_year(year)
}

pub fn fune_vector(args: &[Value]) -> Value {
    // Refuse what the typed signature cannot hold, with the wording TypeScript
    // and Python use, rather than let the conversion below quietly change it.
    if let Value::Float(f) = args[0] {
        if f.fract() != 0.0 {
            panic!("year must be an integer, received {}", f);
        }
    }
    Value::Bool(is_leap_year(args[0].as_i64()))
}

Install

fune build

With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the Rust 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. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:

fune add dates.is-leap-year
Download for Rust dates.is-leap-year-1.0.0-rust.fune · 4,595 bytes sha256 4930b6d804598ab3a122d9527d6de1a8d19dcf3fd368318a21b443c59bc1d602

The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./dates.is-leap-year-1.0.0-rust.fune, or fetch it from a terminal with fune pull dates.is-leap-year@1.0.0:rust.

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.

CaseArgumentsExpected
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
CaseArgumentsExpected
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

PathBytes
README.md816
impl/python.py612
impl/rust.rs951
impl/typescript.ts595
vectors.json1,407