Skip to content

mergeCalendars

mergeCalendars(calendars: BusinessCalendar[]): BusinessCalendar | null

Compose several jurisdictions’ calendars into one whose working days are those they all share.

  • A date is a working day in the result only if it is a working day in every input: the weekend days union and so do the holidays, so a closure anywhere closes the merged calendar.
  • This is why the business-day engine is core rather than finance. FX settlement needs both currencies’ calendars, an intermodal move the origin port’s and the destination port’s, and a cross-border rail path both national calendars — one implementation, four consumers.
  • weekend and holidays come back sorted ascending and de-duplicated, so the result is stable whatever order the inputs arrive in. Holidays sort chronologically, not lexicographically, so an expanded year such as "+010000-01-01" lands where it belongs.
  • timeZone is the first calendar’s. The merged calendar spans localities that may disagree, and GMT does not invent a zone for it; the field records locality only and no business-day function reads it.
  • Returns null for an empty list — there is no timeZone to take — when calendars is not an array, when any element is not a valid BusinessCalendar, and when the merged weekend swallows all seven weekdays, leaving a calendar with no working day at all. isValidBusinessCalendar tells a legitimate result apart from that sentinel.
ParameterTypeDescription
calendarsBusinessCalendar[]array of BusinessCalendar records to compose

merged BusinessCalendar, or null on invalid input

import { mergeCalendars } from "@northguild/gmt/calendar/business";
mergeCalendars([{ weekend: [6, 7], holidays: ["2024-07-04"], timeZone: "America/New_York" }, { weekend: [6, 7], holidays: ["2024-05-06"], timeZone: "Europe/London" }]) // { weekend: [6, 7], holidays: ["2024-05-06", "2024-07-04"], timeZone: "America/New_York" }
calendars
output 

calendar/business/mergeCalendars.ts