# Working calendars

> Define working days, working hours with breaks, per-weekday hours, holidays and working exceptions, use one calendar for the project and others per task, and match durations to your working day.

Durations and lags in the Gantt are **working time**. A calendar says when work can happen: which weekdays, which hours, and which dates are holidays or extra working days. The engine lays every task out on its calendar, so a five-day task that starts on a Thursday ends the following Wednesday.

## The default calendar

Without any calendar, the project works Monday to Friday, 08:00 to 12:00 and 13:00 to 17:00: eight hours a day with a one-hour lunch break. It is exported as `DEFAULT_CALENDAR` (id `'standard'`) if you want to start from it.

## Define calendars

Pass `calendars` and choose the project calendar with `calendarId`:

```ts
import { createGantt } from '@birchui/gantt';

createGantt(container, {
  calendars: [
    {
      id: 'office',
      name: 'London office',
      workingDays: [1, 2, 3, 4, 5],
      workingHours: [
        { from: '09:00', to: '12:30' },
        { from: '13:30', to: '17:30' },
      ],
      exceptions: [
        { start: '2026-12-24', end: '2027-01-01', name: 'Office closed' },
        { start: '2027-04-02', end: '2027-04-05', name: 'Easter' },
        { start: '2027-05-03', name: 'Early May bank holiday' },
      ],
    },
    {
      id: 'site',
      name: 'Construction site',
      workingDays: [1, 2, 3, 4, 5, 6],
      workingHours: [{ from: '07:00', to: '16:00' }],
      weekHours: { 6: [{ from: '08:00', to: '13:00' }] },
    },
  ],
  calendarId: 'office',
  hoursPerDay: 7.5,
  tasks,
  dependencies,
});
```

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | Unique identifier. Required. |
| `name` | `string` | Display name, also written to MS Project XML. |
| `workingDays` | `number[]` | Working weekdays, `0` (Sunday) to `6` (Saturday). Defaults to Monday to Friday. |
| `workingHours` | `{ from, to }[]` | Working intervals of a working day as `'HH:mm'`. Gaps between intervals are breaks. Defaults to 08:00–12:00 and 13:00–17:00. |
| `weekHours` | `{ [weekday]: { from, to }[] }` | Different hours for specific weekdays, such as a short Saturday. An empty list makes that weekday non-working. |
| `exceptions` | `CalendarException[]` | Holidays and other dates that differ from the normal week. |

Overlapping intervals are merged, and an interval whose `to` is not after its `from` is ignored. A calendar without an `id`, with weekdays outside 0–6, or without any working time logs a warning; a calendar without working time falls back to Monday to Friday. A `calendarId` that does not match any calendar logs a warning and uses the standard calendar.

## Holidays and exceptions

| Field | Description |
| --- | --- |
| `start` | First date of the exception. |
| `end` | Last date, inclusive. Omit it for a single day. |
| `name` | A label, such as "Christmas Day". |
| `isWorking` | `true` turns the dates into working days, for example a Saturday shift before a deadline. |
| `hours` | Working intervals for a working exception. Defaults to the calendar's `workingHours`. |

```ts
const exceptions = [
  { start: '2027-12-25', end: '2027-12-26', name: 'Christmas' },
  { start: '2027-11-27', isWorking: true, name: 'Saturday cut-over shift', hours: [{ from: '06:00', to: '14:00' }] },
  { start: '2027-12-24', isWorking: true, name: 'Christmas Eve, half day', hours: [{ from: '09:00', to: '13:00' }] },
];
```

A non-working exception removes the whole day; a working exception replaces the day's hours, so it also shortens a day, as in the Christmas Eve example.

## Task calendars

A task's `calendarId` overrides the project calendar for that task. Use it for crews, contractors or machines that work different hours:

```ts
const tasks = [
  { id: 'design', name: 'Kitchen design', duration: 5 },
  { id: 'fabrication', name: 'Worktop fabrication (supplier)', duration: 10, calendarId: 'supplier' },
  { id: 'install', name: 'Kitchen installation', duration: 4, calendarId: 'site' },
];
```

- A task's duration, start and finish snap to its own calendar.
- **Lag is measured in the successor's calendar**: a two-day lag before `install` means two working days of the site crew.
- Summary tasks use the project calendar for their rolled-up duration.
- Elapsed lags (`'elapsedDay'`, `'elapsedHour'`) ignore all calendars.

## Match hoursPerDay to your calendar

`hoursPerDay` (default `8`) converts durations in days to working hours, and `daysPerWeek` (default `5`) converts weeks to days. Keep `hoursPerDay` equal to the length of a normal working day in your calendar. With a 7.5-hour office day and the default of 8, a one-day task would run into the next morning. Valid values are above 0 and up to 24 hours, and above 0 and up to 7 days.

## Time zone

`timeZone` (an IANA name) is the zone the whole project is scheduled and shown in. Working hours, exceptions and wall-clock strings such as `'2027-01-04T08:00'` are read in it. It defaults to the browser's zone; an invalid name logs a warning and falls back to it. For projects shared across offices, set it explicitly so everyone sees the same schedule.

## Non-working time on the timeline

The timeline shades the project calendar's non-working time: whole non-working days once a day is at least 6 pixels wide, and non-working hours once an hour is at least 2 pixels wide. Restyle it with `--lq-gantt-nonworking-bg`.

## Next steps

- [Scheduling](https://docs.birchui.com/gantt/scheduling.md) for how calendars, links and constraints combine.
- [MS Project XML](https://docs.birchui.com/gantt/ms-project.md) to exchange calendars with other tools.
