std/calendar
std/calendar
导入自 @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.
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
c | { zone: string; week: WorkCalendar['week']; holidays?: Iterable<string>; } |
|
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
from | Instant | string | |
hours | Decimal | number | |
cal | WorkCalendar |
|
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
p | DatePeriod |
|
cal | WorkCalendar |
|
源码: packages/std/src/calendar.ts:107
cycleOf function
function cycleOf(rule: Cycle, day: PlainDate | string): DatePeriod The cycle that holds day.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
rule | Cycle | |
day | PlainDate | string |
源码: 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.
参数
| 名称 | 类型 | 说明 |
|---|---|---|
rule | Cycle | |
within | DatePeriod |
|