Options
All
  • Public
  • Public/Protected
  • All
Menu

The base class for calendars.

Calendars are required when working with functions that require knowledge of weekends and holidays (e.g. addBusinessDays).

There is a tutorial here.

Two calendar classes are defined: WeekendCalendar and HolidayCalendar. The object calWeekends is the default calendar. It simply defines Saturday and Sunday as holiday dates.

This is how the WeekendCalendar is defined.

import { Calendar, Timezone } from '@jetblack/date'

export class WeekendCalendar extends Calendar {
#weekends: number[]

constructor(name: string = 'WeekendCalendar', weekends: number[] = [0, 6]) {
super(name)
this.#weekends = weekends
}

isWeekend(date: Date, tz: Timezone): boolean {
const dayOfWeek = tz.weekday(date)
return this.#weekends.some(x => x === dayOfWeek)
}

isHoliday(date: Date, tz: Timezone): boolean {
return this.isWeekend(date)
}
}

Hierarchy

Index

Constructors

Accessors

Methods

Constructors

Accessors

  • get name(): string

Methods

  • isHoliday(date: Date, tz: Timezone): boolean
  • Check if the date is a holiday.

    Parameters

    • date: Date

      The date to check.

    • tz: Timezone

      The timezone.

    Returns boolean

    True if the date is a holiday, otherwise false.

Generated using TypeDoc