Skip to content

isValidBusinessCalendar

isValidBusinessCalendar(calendar: unknown): calendar is BusinessCalendar

Return true when calendar is a BusinessCalendar the business-day functions accept.

  • weekend must be an array of ISO weekday integers, 1 (Monday) through 7 (Sunday). Duplicates are ignored and [] is valid — a calendar with no weekly closure.
  • All seven weekdays being weekend is invalid: such a calendar has no business day, so nextBusinessDay and every other walk would have nothing to walk to.
  • holidays must be an array of ISO PlainDate strings. [] is valid. A datetime, a leap second or a date that does not exist is not.
  • timeZone must be a valid IANA identifier. It records which locality the calendar describes; the business-day functions never read it, because they work on local dates.
  • Returns false for non-objects, null and arrays.
  • Use it to tell a legitimate result from mergeCalendars apart from its invalid-input sentinel, which is also null, and to tell a misconfigured calendar apart from a bad date when a business-day function returns "".
ParameterTypeDescription
calendarunknowncandidate value of any type

boolean indicating whether every business-day function accepts it

import { isValidBusinessCalendar } from "@northguild/gmt/calendar/validate";
isValidBusinessCalendar({ weekend: [6, 7], holidays: [], timeZone: "UTC" }) // true
output 

calendar/validate/isValidBusinessCalendar.ts