businessDaysBetween
Signature
Section titled “Signature”businessDaysBetween(start: string, end: string, calendar: BusinessCalendar): number | nullCount the working days between two local dates, excluding start and including end.
- The convention is stated, not inferred: the range is
(start, end]. Counting from Monday to Friday of the same week gives 4, not 5 — Monday itself is not counted. - That makes it the inverse of
addBusinessDayswhenn ≥ 0orstartis a business day: ifendisaddBusinessDays(start, n, calendar), this returnsn. From a weekend or holidaystart, a negativencounts one closer to zero, becausestartitself is excluded and is not a business day. endbeforestartreturns a negative count, so swapping the arguments negates the result. An empty range is always0, never-0, andbusinessDaysBetween(d, d, calendar)is 0 for anyd.- The count is computed, not walked, so there is no range limit: whole weeks contribute one of each weekday and only the holidays are visited individually.
- Both dates and
calendar.holidaysare local dates;calendar.timeZoneis not read. A caller holding an instant reduces it to a local date first, withfloorToZone. - Returns
nullwhen either date is not a valid ISO PlainDate, orcalendaris not a validBusinessCalendar. Narrow it withisValidBusinessCalendarto tell a misconfigured calendar apart from a genuine 0.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | ISO PlainDate string, excluded from the count |
end | string | ISO PlainDate string, included in the count |
calendar | BusinessCalendar | BusinessCalendar naming the weekend days and holidays |
Returns
Section titled “Returns”number of working days in (start, end], negative when end precedes start, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { businessDaysBetween } from "@northguild/gmt/calendar/business";
businessDaysBetween("2024-07-01", "2024-07-05", { weekend: [6, 7], holidays: ["2024-07-04"], timeZone: "America/New_York" }) // 3 — Tue, Wed, Fri