Skip to content

std/calendar

std/calendar

Import from @norbital-ai/std/calendar

std/calendar (§3.7, §5.4): pay and billing cycles (a cycle is named by the day it OPENS), working days and business-hour deadlines (SLAs) over a work week and holiday rows.

Cycle type

type Cycle = {
    readonly every: 'month';
    readonly opensOn?: number;
} | {
    readonly every: 'semiMonth';
    readonly secondOpensOn?: number;
} | {
    readonly every: 'week';
    readonly opensOn: 1 | 2 | 3 | 4 | 5 | 6 | 7;
} | {
    readonly every: 'days';
    readonly n: number;
    readonly anchor: PlainDate | string;
};

A pay or billing cycle, named by the day it opens: monthly (opensOn 1–28), semi-monthly, weekly (ISO weekday) or every n days from an anchor date.

Source: packages/std/src/calendar.ts:11

WorkCalendar function

function WorkCalendar(c: { zone: string; week: WorkCalendar["week"]; holidays?: Iterable<string>; }): WorkCalendar

A checked work calendar: every day's hours are start < end, holidays are calendar dates.

Parameters

NameTypeDescription
c{ zone: string; week: WorkCalendar['week']; holidays?: Iterable<string>; }
  • zone: string
  • week: WorkCalendar['week']
  • holidays?: Iterable<string>

Source: packages/std/src/calendar.ts:18

addBusinessHours function

function addBusinessHours(from: Instant | string, hours: Decimal | number, cal: WorkCalendar): Instant

The instant hours working hours after from, counting only each working day's hours in the calendar's zone (an SLA due time). Zero hours from outside hours is the next opening.

Parameters

NameTypeDescription
fromInstant | string
hoursDecimal | number
calWorkCalendar
  • zone: string
  • week: { readonly [D in 1 | 2 | 3 | 4 | 5 | 6 | 7]: Hours; }
  • holidays: ReadonlySet<string>

Source: packages/std/src/calendar.ts:118

businessDays function

function businessDays(p: DatePeriod, cal: WorkCalendar): number

Working days in a closed period: a weekday with hours that is not a holiday.

Parameters

NameTypeDescription
pDatePeriod
  • from: PlainDate
  • to: PlainDate | null
calWorkCalendar
  • zone: string
  • week: { readonly [D in 1 | 2 | 3 | 4 | 5 | 6 | 7]: Hours; }
  • holidays: ReadonlySet<string>

Source: packages/std/src/calendar.ts:107

cycleOf function

function cycleOf(rule: Cycle, day: PlainDate | string): DatePeriod

The cycle that holds day.

Parameters

NameTypeDescription
ruleCycle
dayPlainDate | string

Source: packages/std/src/calendar.ts:52

cycles function

function cycles(rule: Cycle, within: DatePeriod): DatePeriod[]

Every cycle that shares a day with within (a closed period), in order.

Parameters

NameTypeDescription
ruleCycle
withinDatePeriod
  • from: PlainDate
  • to: PlainDate | null

Source: packages/std/src/calendar.ts:91