Skip to content

businessDaysBetween

businessDaysBetween(start: string, end: string, calendar: BusinessCalendar): number | null

Count 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 addBusinessDays when n ≥ 0 or start is a business day: if end is addBusinessDays(start, n, calendar), this returns n. From a weekend or holiday start, a negative n counts one closer to zero, because start itself is excluded and is not a business day.
  • end before start returns a negative count, so swapping the arguments negates the result. An empty range is always 0, never -0, and businessDaysBetween(d, d, calendar) is 0 for any d.
  • 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.holidays are local dates; calendar.timeZone is not read. A caller holding an instant reduces it to a local date first, with floorToZone.
  • Returns null when either date is not a valid ISO PlainDate, or calendar is not a valid BusinessCalendar. Narrow it with isValidBusinessCalendar to tell a misconfigured calendar apart from a genuine 0.
ParameterTypeDescription
startstringISO PlainDate string, excluded from the count
endstringISO PlainDate string, included in the count
calendarBusinessCalendarBusinessCalendar naming the weekend days and holidays

number of working days in (start, end], negative when end precedes start, or null on invalid input

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
output 

calendar/business/businessDaysBetween.ts