将多个工作日历合并为一个日历
calendars | Calendar[] | Calendar | 可以是日历对象数组,也可以是单个日历对象 |
calendar2 | Calendar | 可选,第二个日历对象 |
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]
}
});
// 提供一个日历数组进行合并
const joinedCalendar = gantt.mergeCalendars([
gantt.getCalendar(mikeCalendarId),
gantt.getCalendar(johnCalendarId)
]);
你也可以将多个日历对象作为独立参数传递给 mergeCalendars 方法:
// 以独立参数形式提供日历
const joinedCalendar = gantt.mergeCalendars(
gantt.getCalendar(mikeCalendarId),
gantt.getCalendar(johnCalendarId)
);
合并日历时,合并后日历的工作日通过检查所有被合并日历中对应日期是否均为工作日来确定(使用逻辑与(&&)操作):
// 日历1 + 日历2 = 合并后的日历;
// 情况1:
// 工作日 (1/true) + 工作日 (1/true) = 工作日 (1/true);
// 情况2:
// 工作日 (1/true) + 非工作日 (0/false) = 非工作日 (0/false);
// 情况3:
// 非工作日 (0/false) + 非工作日 (0/false) = 非工作日 (0/false);
例如,给定两个日历:
const calendar1Id = gantt.addCalendar({
id: "calendar1",
worktime: {
days: [ 0, 1, 0, 1, 0, 0, 0 ]
}
});
const calendar2Id = gantt.addCalendar({
id: "calendar2",
worktime: {
days: [ 0, 1, 1, 0, 1, 0, 0 ]
}
});
合并这两个日历:
const joinedCalendar = gantt.mergeCalendars([
gantt.getCalendar(calendar1Id),
gantt.getCalendar(calendar2Id)
]);
结果是一个只有周一为工作日的日历:
// days: [ 0, 1, 0, 1, 0, 0, 0 ]
// +
// days: [ 0, 1, 1, 0, 1, 0, 0 ]
// =
// days: [ 0, 1, 0, 0, 0, 0, 0 ]
相关示例: Gantt. Merge work calendars (via mergeCalendars() method)
合并逻辑不考虑 customWeeks。
v7.0 新增
Back to top