Functional Weave
Code in TypeScript

dates.overlap@1.0.0

vectors.json

2,441 bytes · view raw

[
  { "name": "inclusive: 1-10 Jan and 5-20 Jan share 5 to 10 January, six days", "args": ["2026-01-01", "2026-01-10", "2026-01-05", "2026-01-20", true], "expect": 6 },
  { "name": "exclusive: the same dates as half-open ranges share five days", "args": ["2026-01-01", "2026-01-10", "2026-01-05", "2026-01-20", false], "expect": 5 },
  { "name": "inclusive: ranges sharing only their boundary day overlap by one", "args": ["2026-01-01", "2026-01-10", "2026-01-10", "2026-01-20", true], "expect": 1 },
  { "name": "exclusive: a stay ending on the day the next begins does not overlap", "args": ["2026-01-01", "2026-01-10", "2026-01-10", "2026-01-20", false], "expect": 0 },
  { "name": "ranges that do not meet give zero, not a negative number", "args": ["2026-01-01", "2026-01-10", "2026-03-01", "2026-03-10", true], "expect": 0 },
  { "name": "the order of the ranges does not matter", "args": ["2026-01-05", "2026-01-20", "2026-01-01", "2026-01-10", true], "expect": 6 },
  { "name": "a range inside another overlaps by its own length: February 2026", "args": ["2026-01-01", "2026-12-31", "2026-02-01", "2026-02-28", true], "expect": 28 },
  { "name": "a leap February counts its 29th", "args": ["2024-02-01", "2024-03-31", "2024-02-15", "2024-02-29", true], "expect": 15 },
  { "name": "a policy year against the UK tax year from 6 April", "args": ["2025-10-01", "2026-09-30", "2026-04-06", "2027-04-05", true], "expect": 178 },
  { "name": "inclusive: a one-day range inside another is one day", "args": ["2026-09-23", "2026-09-23", "2026-09-01", "2026-09-30", true], "expect": 1 },
  { "name": "exclusive: a range whose start equals its end is empty", "args": ["2026-09-23", "2026-09-23", "2026-09-01", "2026-09-30", false], "expect": 0 },
  { "name": "across a year end, inclusive", "args": ["2026-12-20", "2027-01-05", "2026-12-25", "2027-01-01", true], "expect": 8 },
  { "name": "a range that ends before it starts is an error", "args": ["2026-01-10", "2026-01-01", "2026-01-05", "2026-01-20", true], "expectError": "range A starts 2026-01-10, after its end 2026-01-01" },
  { "name": "the second range is checked too", "args": ["2026-01-01", "2026-01-10", "2026-01-20", "2026-01-05", false], "expectError": "range B starts 2026-01-20, after its end 2026-01-05" },
  { "name": "an impossible date is an error", "args": ["2026-02-30", "2026-03-10", "2026-03-01", "2026-03-05", true], "expectError": "is not a real calendar date" }
]