Functional Weave
Code in Python

dates.overlap@1.0.0

README.md

1,017 bytes · view raw

# dates.overlap

How many days two ranges share: the days of a policy that fall in a tax year,
the nights of a booking inside a rate season, the part of a lease inside a
service-charge year.

Whether a range's end date is one of its days is the question every overlap
bug comes from, so it is an argument rather than a default. With
`endInclusive` true, ranges are written the way a statement prints them:
1 to 10 January is ten days, and ranges that share only 10 January overlap by
one day. With it false, ranges are half-open, the way a hotel stay or
dates.business-days-between works: 1 to 10 January is nine days (or nights),
and ranges that meet at 10 January do not overlap at all. Both ranges use the
same convention.

Ranges that do not meet give 0, never a negative number. A range whose end is
before its start is an error; an exclusive range whose start equals its end is
empty (0 days) and allowed.

Dates are calendar days from the dates.add-days kernel, so leap days count and
there are no time zones.