mergeCalendars

merges several working calendars into one

void mergeCalendars(array calendars);

Parameters

calendarsarrayan array of calendars' objects

Example

const johnCalendarId = gantt.addCalendar({
    worktime: {
        hours: ["0:00-24:00"],
        days: [0, 1, 1, 1, 1, 1, 0]
    }
});
const mikeCalendarId = gantt.addCalendar({
    worktime: {
        hours: ["8:00-12:00", "13:00-17:00"],
        days: [0, 1, 1, 1, 1, 1, 0]
    }
});
 
// pass an array of calendars as an argument
const joinedCalendar = gantt.mergeCalendars([
    gantt.getCalendar(mikeCalendarId),
    gantt.getCalendar(johnCalendarId)
]);

Details

You can also specify a set of objects of calendars as parameters of the mergeCalendars method:

// pass calendars as arguments
const joinedCalendar = gantt.mergeCalendars(
    gantt.getCalendar(mikeCalendarId),
    gantt.getCalendar(johnCalendarId)
);

Logic for merging calendars

When merging calendars, the following logic applies - the day of the week in the new calendar will be considered a working day (1/true) only if it is a working day in all merged calendars (Logical AND (&&)):

// calendar 1 + calendar 2 = merged calendar;
 
// Case 1: 
// working day (1/true) + working day (1/true) = working day (1/true);
 
// Case 2: 
// working day (1/true) + non-working day (0/false) = non-working day (0/false);
 
// Case 3: 
// non-working day (0/false) + non-working day (0/false) = non-working day (0/false);

So, if we have two calendars:

  • the first one with working days: Monday and Wednesday:
const calendar1Id = gantt.addCalendar({
    id: "calendar1",
    worktime: {
        days: [ 0, 1, 0, 1, 0, 0, 0 ]
    }
});
  • the second one with working days: Monday, Tuesday and Thursday:
const calendar2Id = gantt.addCalendar({
    id: "calendar2",
    worktime: {
        days: [ 0, 1, 1, 0, 1, 0, 0 ]
    }
});

When the calendars merge:

const joinedCalendar = gantt.mergeCalendars([
    gantt.getCalendar(calendar1Id),
    gantt.getCalendar(calendar2Id)
]);

we get a new calendar with working days only on Mondays:

// days: [ 0, 1, 0, 1, 0, 0, 0 ]
 
// +
 
// days: [ 0, 1, 1, 0, 1, 0, 0 ]
 
// =
 
// days: [ 0, 1, 0, 0, 0, 0, 0 ]

Related sample: Gantt. Merge work calendars (via mergeCalendars() method)

The logic does not take into account customWeeks.

See also
Change log

added in v7.0

Back to top