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, DateTz } from '@jetblack/date-tz'

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

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

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

isHoliday(date: DateTz): boolean {
return this.isWeekend(date)
}
}

Hierarchy

Index

Constructors

Accessors

Methods

Constructors

Accessors

  • get name(): string

Methods

  • isHoliday(dateTz: DateTz): boolean
  • Check if the date is a holiday.

    Parameters

    • dateTz: DateTz

      The date to check.

    Returns boolean

    True if the date is a holiday, otherwise false.

Generated using TypeDoc