# Calendars
URL: https://pro.rv-grid.com/api/calendars/
Source: src/content/docs/api/calendars.md
### `calendarKey`

```ts
export function calendarKey(calendarId: CalendarId): string;
```

---

### `normalizeIsoWorkingDays`

```ts
export function normalizeIsoWorkingDays(
  days: readonly number[] | undefined,
  fallback: readonly number[] = DEFAULT_CALENDAR.workingDays,
): readonly number[];
```

---

### `jsWeekdayFromIsoWeekday`

```ts
export function jsWeekdayFromIsoWeekday(day: number): number;
```

---

### `jsWeekdaysFromIsoWeekdays`

```ts
export function jsWeekdaysFromIsoWeekdays(days: readonly number[]): readonly number[];
```

---

### `normalizeCalendarHolidaySet`

```ts
export function normalizeCalendarHolidaySet(holidays: readonly ISODateString[] | undefined): ReadonlySet<string>;
```

---

### `normalizeCalendarWorkingHours`

```ts
export function normalizeCalendarWorkingHours(
  workingHours: CalendarWorkingTimeRange | readonly CalendarWorkingTimeRange[] | undefined,
  options:;
```

---

### `normalizeCalendar`

```ts
export function normalizeCalendar(
  calendar: CalendarEntity,
  options:;
```

---

### `createResolvedCalendarMap`

```ts
export function createResolvedCalendarMap(
  calendars: readonly CalendarEntity[] | undefined,
  options:;
```

---

### `createCalendarMap`

```ts
export function createCalendarMap(calendars: readonly CalendarEntity[] | undefined): Map<CalendarId, CalendarEntity>;
```

---

### `resolveCalendarFromMap`

```ts
export function resolveCalendarFromMap(
  target: CalendarLookupTarget,
  calendarsById: ReadonlyMap<CalendarId, CalendarEntity>,
  primaryCalendar: CalendarEntity | null,
): CalendarEntity | null;
```

---

### `resolveCalendarFromList`

```ts
export function resolveCalendarFromList(
  context: CalendarListLookupContext,
  target?: CalendarLookupTarget,
): CalendarEntity | null;
```

---

### `resolveCalendarItemFromMap`

```ts
export function resolveCalendarItemFromMap<T>(
  target: CalendarLookupTarget,
  items: ReadonlyMap<string, T>,
): T | null;
```

---

### `isCalendarHoliday`

```ts
export function isCalendarHoliday(
  date: ISODateString | string,
  calendar: Pick<CalendarEntity, 'holidays'> | Pick<ResolvedCalendarEntity, 'holidays'> | null | undefined,
): boolean;
```

---

### `isCalendarWorkingWeekday`

```ts
export function isCalendarWorkingWeekday(
  weekday: number,
  calendar: Pick<CalendarEntity, 'workingDays'> | Pick<ResolvedCalendarEntity, 'workingDays'> | null | undefined,
): boolean;
```

---

### `isWorkingCalendarDate`

```ts
export function isWorkingCalendarDate(
  date: ISODateString | string,
  weekday: number,
  calendar: (
    Pick<CalendarEntity, 'workingDays' | 'holidays'>
    | Pick<ResolvedCalendarEntity, 'workingDays' | 'holidays'>
    | null
    | undefined
  ),
): boolean;
```

---

### `isCalendarWorkingHour`

```ts
export function isCalendarWorkingHour(
  date: ISODateString | string,
  calendar: CalendarEntity | ResolvedCalendarEntity | null | undefined,
): boolean;
```

---

### `CalendarId`

Unique identifier for a working calendar.

```ts
/** Unique identifier for a working calendar. */
export type CalendarId = string | number;
```

---

### `CalendarWorkingTimeRange`

Time-of-day working window for calendar-aware schedulers.

```ts
interface CalendarWorkingTimeRange {
  /** Start time in `HH:mm` or AM/PM format. */
    readonly start: string;
  /** End time in `HH:mm` or AM/PM format. */
    readonly end: string
}
```

---

### `CalendarResolvedWorkingTimeRange`

Parsed working time window expressed as minutes from midnight.

```ts
interface CalendarResolvedWorkingTimeRange {
  readonly startMinutes: number;
  readonly endMinutes: number
}
```

---

### `CalendarEntity`

Defines the working schedule for tasks, events, and resources.
Working days use ISO weekday numbers: 1 = Monday ... 7 = Sunday.

```ts
interface CalendarEntity {
  /** Unique calendar identifier. */
    readonly id: CalendarId;
  /** Display name, for example `"Standard"` or `"Night Shift"`. */
    readonly name: string;
  /** IANA time zone, for example `"America/New_York"`. */
    readonly timeZone: string;
  /** ISO weekday numbers that are working days. */
    readonly workingDays: readonly number[];
  /** Specific dates that are non-working regardless of weekday. */
    readonly holidays: readonly ISODateString[];
  /** Optional working time windows inside a working day. */
    readonly workingHours?: CalendarWorkingTimeRange | readonly CalendarWorkingTimeRange[];
  /** Number of working hours per day, used for effort/capacity calculations. */
    readonly hoursPerDay: number
}
```

---

### `DEFAULT_CALENDAR`

Default Monday-Friday calendar shared by Gantt and Event Scheduler.

```ts
DEFAULT_CALENDAR: {
  id: string;
  name: string;
  timeZone: string;
  workingDays: number[];
  holidays: never[];
  workingHours: { start: string; end: string; };
  hoursPerDay: number;
};
```

---

### `ResolvedCalendarEntity`

Calendar with derived lookup-friendly fields used by schedulers.

```ts
interface ResolvedCalendarEntity {
  readonly calendar: CalendarEntity;
  readonly workingDays: readonly number[];
  readonly workingHours: readonly CalendarResolvedWorkingTimeRange[];
  readonly holidays: ReadonlySet<string>
}
```

---

### `CalendarListLookupContext`

```ts
interface CalendarListLookupContext {
  readonly calendars: readonly CalendarEntity[];
  readonly primaryCalendarId?: CalendarId
}
```

---

### `CalendarLookupTarget`

```ts
export type CalendarLookupTarget = CalendarId | { readonly calendarId?: CalendarId } | undefined;
```
