mergeCalendars
Signature
Section titled “Signature”mergeCalendars(calendars: BusinessCalendar[]): BusinessCalendar | nullCompose 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.
weekendandholidayscome 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.timeZoneis 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
nullfor an empty list — there is notimeZoneto take — whencalendarsis not an array, when any element is not a validBusinessCalendar, and when the merged weekend swallows all seven weekdays, leaving a calendar with no working day at all.isValidBusinessCalendartells a legitimate result apart from that sentinel.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
calendars | BusinessCalendar[] | array of BusinessCalendar records to compose |
Returns
Section titled “Returns”merged BusinessCalendar, or null on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”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" }