Functional Weave
Code in Rust

health.age-in-months@1.0.1

vectors.json

2,914 bytes · view raw

[
  { "name": "on the day of birth everything is zero", "args": ["2026-03-10", "2026-03-10"], "expect": { "months": 0, "days": 0, "totalDays": 0 } },
  { "name": "one day old", "args": ["2026-03-10", "2026-03-11"], "expect": { "months": 0, "days": 1, "totalDays": 1 } },
  { "name": "the day before the first monthly anniversary", "args": ["2026-03-10", "2026-04-09"], "expect": { "months": 0, "days": 30, "totalDays": 30 } },
  { "name": "on the first monthly anniversary", "args": ["2026-03-10", "2026-04-10"], "expect": { "months": 1, "days": 0, "totalDays": 31 } },
  { "name": "2 months 15 days", "args": ["2026-03-10", "2026-05-25"], "expect": { "months": 2, "days": 15, "totalDays": 76 } },
  { "name": "born 31 January is not a month old on 28 February: a naive clamp says it is", "args": ["2026-01-31", "2026-02-28"], "expect": { "months": 0, "days": 28, "totalDays": 28 } },
  { "name": "born 31 January completes the first month on 1 March", "args": ["2026-01-31", "2026-03-01"], "expect": { "months": 1, "days": 0, "totalDays": 29 } },
  { "name": "born 31 January, 30 March is 1 month 29 days", "args": ["2026-01-31", "2026-03-30"], "expect": { "months": 1, "days": 29, "totalDays": 58 } },
  { "name": "born 31 January, 31 March is 2 months: the 31st does not decay after February", "args": ["2026-01-31", "2026-03-31"], "expect": { "months": 2, "days": 0, "totalDays": 59 } },
  { "name": "born 31 January 2024, 29 February 2024 is still short of the 31st", "args": ["2024-01-31", "2024-02-29"], "expect": { "months": 0, "days": 29, "totalDays": 29 } },
  { "name": "born 31 January 2024, 1 March 2024 completes the month", "args": ["2024-01-31", "2024-03-01"], "expect": { "months": 1, "days": 0, "totalDays": 30 } },
  { "name": "born 29 February 2024 is 11 months 30 days on 28 February 2025", "args": ["2024-02-29", "2025-02-28"], "expect": { "months": 11, "days": 30, "totalDays": 365 } },
  { "name": "born 29 February 2024 is 12 months on 1 March 2025, as dates.age turns 1", "args": ["2024-02-29", "2025-03-01"], "expect": { "months": 12, "days": 0, "totalDays": 366 } },
  { "name": "born 30 April, 30 May is one month", "args": ["2026-04-30", "2026-05-30"], "expect": { "months": 1, "days": 0, "totalDays": 30 } },
  { "name": "across the year end", "args": ["2025-11-20", "2026-01-05"], "expect": { "months": 1, "days": 16, "totalDays": 46 } },
  { "name": "a two-year-old counted in months", "args": ["2024-06-15", "2026-09-23"], "expect": { "months": 27, "days": 8, "totalDays": 830 } },
  { "name": "a measuring date before the birth is an error", "args": ["2026-03-10", "2026-03-09"], "expectError": "is before birthDate" },
  { "name": "an impossible birth date is an error", "args": ["2026-02-30", "2026-04-01"], "expectError": "is not a real calendar date" },
  { "name": "a UK-style date is an error", "args": ["10/03/2026", "2026-04-01"], "expectError": "is not an ISO date" }
]