Skip to content

Schedule holidays and split shifts with JavaScript Gantt working calendars ​

A seven-hour task starts at 10:00 on a short Monday. The team can work five hours before closing, so the task finishes at 11:00 Tuesday. If Tuesday is a holiday, the same work finishes at 11:00 Wednesday.

RevoGrid Gantt calculates those dates from the task’s working calendar. This example sets up a shared workweek, overrides Monday’s hours for one team, and adds a holiday that the team inherits.

Run the working calendar example ​

The React example uses pinned Gantt and Pro trial packages.

sh
git clone https://github.com/revolist/revogrid-docs.git
cd revogrid-docs/examples/gantt-workflows
npm ci
npm run dev

Choose Working calendars. The project is local to the browser. The task is locked against direct editing so its seven-hour workload stays fixed while you change calendars. Verify expected dates runs the engine checks for the original schedule and inherited holiday.

You can also try the packaged editor in the calendar documentation's live example and explore the Gantt demo.

Define a base week and a team override ​

The standard week runs Monday–Friday, with two working intervals: 09:00–12:00 and 13:00–18:00. That is eight working hours, with lunch excluded. The support team inherits this week but works shorter Mondays: 10:00–12:00 and 13:00–16:00.

Calendar ruleStandard weekSupport team
Tuesday–Friday09:00–12:00, 13:00–18:00Inherited
Monday09:00–12:00, 13:00–18:0010:00–12:00, 13:00–16:00
Saturday–SundayClosedInherited
Annual December 25 closureRecurring exceptionInherited
ts
export function createCalendarProject(): ProjectSnapshot {
  const calendars: CalendarEntity[] = [
    {
      ...standardCalendar,
      workingHours: [
        { start: '09:00', end: '12:00' },
        { start: '13:00', end: '18:00' },
      ],
      exceptions: [
        {
          id: 'annual-closure',
          name: 'Annual closure',
          startDate: '2026-12-25',
          workingHours: [],
          recurrence: { frequency: 'yearly' },
        },
      ],
    },
    {
      id: 'support',
      name: 'Support team',
      timeZone: 'UTC',
      baseCalendarId: 'standard',
      workingDays: [],
      holidays: [],
      hoursPerDay: 8,
      weekdayWorkingHours: {
        1: [
          { start: '10:00', end: '12:00' },
          { start: '13:00', end: '16:00' },
        ],
      },
    },
  ];
  return project({
    name: 'Team calendar example',
    calendars,
    tasks: [
      task('support-review', 'Support review', {
        startDate: '2026-07-13T10:00:00.000Z',
        endDate: '2026-07-14T11:00:00.000Z',
        duration: 7,
        durationUnit: 'hour',
        calendarId: 'support',
        locked: true,
      }),
    ],
  });
}

baseCalendarId establishes inheritance. A child uses its base working week unless inheritWorkingWeek: false requests a local week. weekdayWorkingHours changes individual ISO weekdays: Monday is 1, Sunday is 7, and an empty interval list closes that weekday.

The example's workingDays: [] on the child is intentional: it inherits the base week. It does not describe an independently empty calendar. Removing its base reference without supplying a usable local week would change the meaning and can fail validation.

Schedule a seven-hour task across working intervals ​

The task has duration: 7 and durationUnit: 'hour'. In a ProjectSnapshot, numeric durations are canonical hours. hoursPerDay: 8 is a conversion setting; it does not force the support team to work eight hours every Monday.

Enable working-time exclusion in the Gantt configuration:

ts
const gantt = {
  // Keep the project's required id, name, calendar and metadata fields.
  ...project,
  scheduling: { excludeHolidaysFromDuration: true },
};

The task starts Monday, July 13, 2026, at 10:00 UTC and uses calendarId: 'support'. Its finish is calculated as follows:

Working intervalHours consumedHours remaining
Monday 10:00–12:0025
Monday 13:00–16:0032
Tuesday 09:00–11:0020

The expected finish is Tuesday, July 14, at 11:00 UTC. Lunch and the closed interval after Monday 16:00 contribute no working time.

The duration guide explains storage and display conversions. Changing a day-length conversion is separate from changing workingHours; make both changes explicitly when both are intended.

Add a holiday and inspect the new finish ​

Click Close Tuesday July 14. The example adds that date to the standard calendar's holidays and calls the public Gantt method:

ts
const accepted = ganttPlugin.setCalendars(nextCalendars);

if (!accepted) {
  showMessage('The calendar change was rejected.');
}

Here ganttPlugin is the installed GanttPlugin instance obtained from grid.getPlugins(). It is not the grid.gantt configuration object. The complete React component includes instance lookup, errors, and the button handlers.

The support calendar inherits the closure. Monday still contributes five hours, Tuesday contributes none, and Wednesday supplies the final two. The task now finishes Wednesday, July 15, at 11:00 UTC. No task duration or assignment changed.

setCalendars validates the complete calendar collection and referenced calendar IDs. It returns false for an invalid change, a read-only project, a broken task/resource reference, or a canceled gantt-before-calendar-change event. Accepted changes participate in the Gantt edit/history system; persistence is a separate application concern.

Use exceptions for replacement hours and recurrence ​

A holidays entry closes a date. An exception can instead replace its working intervals, name the reason, span a range, or recur. The annual closure in the fixture uses:

ts
{
  id: 'annual-closure',
  name: 'Annual closure',
  startDate: '2026-12-25',
  workingHours: [],
  recurrence: { frequency: 'yearly' },
}

For a shortened day, provide the replacement intervals. Recurrence supports daily, weekly, monthly, and yearly frequencies, with an optional positive interval and an inclusive until date. A matching child exception takes precedence over an inherited exception, so a team can reopen a date that its base calendar closes.

Keep the precedence visible to users. If a holiday appears ineffective, inspect the task's assigned calendar and its matching child exceptions before changing the task duration. Calendar dates are civil YYYY-MM-DD dates; interval values belong to that calendar date.

Open the built-in calendar editor ​

Register GanttCalendarEditorPlugin beside GanttPlugin:

ts
const plugins = [GanttPlugin, GanttCalendarEditorPlugin];

const editor = (await grid.getPlugins()).find(
  (plugin) => plugin instanceof GanttCalendarEditorPlugin,
);

editor?.open({
  selectedCalendarId: 'support',
  referenceDate: '2026-07-13',
});

The editor holds a draft. Users can change inheritance, edit weekday intervals, add exceptions, and inspect effective hours in the month preview. Save changes validates and applies the collection; Cancel or Escape discards the draft.

If the application uses the packaged Gantt toolbar, enable controls.calendars: true in defineGanttToolbar(...) to expose View → Working calendars. The editor plugin must still be registered. Creating a calendar does not automatically assign it to existing tasks or resources: update their calendarId deliberately.

Use the cancelable gantt-before-calendar-change event for a local permission or review gate. On the backend, validate authorization and the project revision again before persisting a calendar replacement. A client-side canceled event is a UI policy, not a server authorization check.

Time zones and scheduling boundaries ​

This fixture uses UTC so that its expected times are unambiguous. For real teams, set the effective calendar's IANA timeZone and test dates around daylight-saving transitions. Working intervals are evaluated in that calendar's zone; changing display formatting does not change the scheduling zone or migrate stored task timestamps.

Do not treat date-only tasks and datetime tasks as interchangeable. Date-only values retain civil-date semantics. Intraday scheduling consumes the available working intervals. An elapsed-duration task is another deliberate choice: it ignores working calendars for its continuous duration.

Resource calendars participate in resource-capacity checks, while task calendars govern their scheduling. Do not assume every combination behaves identically to Microsoft Project. The compatibility guide describes the current scope.

Before saving a calendar change, check the affected finishes and deadlines. Reject missing base calendars, inheritance cycles, invalid dates, and unusable weeks. Long nonworking ranges also have validation limits; the calendar reference documents the traversal horizon.

If a task now competes with another assignment, continue with resource leveling. When importing a plan, Microsoft Project conversion needs special care because the adapter creates a default calendar instead of preserving the original Microsoft Project calendar definitions.