Functional Weave
Code in Rust

dates.age@1.0.0

vectors.json

2,190 bytes · view raw

[
  { "name": "the day before a birthday", "args": ["1990-05-15", "2026-05-14"], "expect": 35 },
  { "name": "on the birthday itself the new age applies", "args": ["1990-05-15", "2026-05-15"], "expect": 36 },
  { "name": "the day after a birthday", "args": ["1990-05-15", "2026-05-16"], "expect": 36 },
  { "name": "on the day of birth the age is zero", "args": ["2026-09-22", "2026-09-22"], "expect": 0 },
  { "name": "a day short of the first birthday is still zero", "args": ["2025-09-22", "2026-09-21"], "expect": 0 },
  { "name": "born 31 December, measured on 1 January: one day later but a year number higher", "args": ["2007-12-31", "2008-01-01"], "expect": 0 },
  { "name": "born 29 February 2008 is still 17 on 28 February 2026: a naive clamp says 18", "args": ["2008-02-29", "2026-02-28"], "expect": 17 },
  { "name": "born 29 February 2008 turns 18 on 1 March 2026", "args": ["2008-02-29", "2026-03-01"], "expect": 18 },
  { "name": "born 29 February, in a leap year the birthday is 29 February itself", "args": ["2000-02-29", "2024-02-29"], "expect": 24 },
  { "name": "born 29 February, the day before a leap-year birthday", "args": ["2000-02-29", "2024-02-28"], "expect": 23 },
  { "name": "born 29 February, 2100 is not a leap year so the birthday is 1 March", "args": ["1996-02-29", "2100-02-28"], "expect": 103 },
  { "name": "born 29 February, 1 March 2100", "args": ["1996-02-29", "2100-03-01"], "expect": 104 },
  { "name": "born 28 February is unaffected by leap years", "args": ["2008-02-28", "2026-02-28"], "expect": 18 },
  { "name": "born 1 March, measured on 29 February of a leap year", "args": ["2000-03-01", "2024-02-29"], "expect": 23 },
  { "name": "a pension record from before 1970", "args": ["1901-07-04", "1968-07-04"], "expect": 67 },
  { "name": "a measuring date before the birth is an error, not a negative age", "args": ["2026-09-22", "2026-09-21"], "expectError": "is before birthDate" },
  { "name": "an impossible birth date is an error", "args": ["2026-02-29", "2027-01-01"], "expectError": "is not a real calendar date" },
  { "name": "a UK-style date is an error", "args": ["15/05/1990", "2026-05-15"], "expectError": "is not an ISO date" }
]