calendar

the interface of the working calendar object

object calendar;
Details

Read the Work Time Calculation article for detailed info on working calendars.

The calendar object possesses the following methods and properties:

Methods

  • setWorkTime (config): boolean - sets the working time for the Gantt chart
    • config - (object) - the configuration object of a time span:
      • day? - (string | number) - optional, a number of a week day [0 (Sunday) - 6 (Saturday)]. Note, you can set only 1 day at once
      • date? - (Date) - optional, a specific date to set as a working day or day off
      • hours? - (string[] | number[] | boolean) - optional, an array of working hours as 'from'-'to' pairs.'false' value sets a day-off, 'true' (default value) applies the default hours (["8:00-17:00"])
      • customWeeks? - (object) - optional, an object with different working-time rules for different periods of time. The object can contain a set of key:value pairs where key is the name of a time span and value is an object with a list of attributes.
        • [timespan: string] - (object) - the time span with the working time settings. The name of that object is used as the name of the time span
          • from - (Date) - the date when the time span is scheduled to begin
          • to - (Date) - the date when the time span is scheduled to be completed
          • hours? - (string[] | number[]) - optional, an array of working hours as 'from'-'to' pairs.'false' value sets a day-off, 'true' (default value) applies the default hours (["8:00-17:00"])
          • days? - (WorkDaysTuple | boolean) - optional, an array of 7 days of the week (from 0 - Sunday, to 6 - Saturday), where 1/true stands for a working day and 0/false - a non-working day.
calendar.setWorkTime({ hours:["9:00-18:00"] });
calendar.setWorkTime({ day: 5, hours: ["9:00-18:00"] });
calendar.setWorkTime({ day: 5, hours: false });
calendar.setWorkTime({ date: new Date(2025, 5, 6), hours: ["9:00-18:00"] });
calendar.setWorkTime({ date: new Date(2025, 5, 6), hours: false });
calendar.setWorkTime({ hours: false });
calendar.setWorkTime({
  customWeeks: {
    winter: {
      from: new Date(2025, 11, 1),
      to: new Date(2026, 2, 1),
      hours: ["8:00-13:00", "14:00-16:00"],
      days: [1, 1, 1, 1, 1, 0, 0]
    },
    summer: {
      from: new Date(2026, 5, 1),
      to: new Date(2026, 7, 1),
      hours: ["10:00-13:00", "14:00-16:00"],
      days: [1, 1, 0, 1, 1, 0, 0]
    }
  }
});
calendar.setWorkTime({
  customWeeks: {
    winter: {
      from: new Date(2025, 11, 1),
      to: new Date(2026, 2, 1),
      hours: ["8:00-13:00", "14:00-16:00"],
      days: [1, ["8:00-13:00"], 1, 1, ["14:00-16:00"], 0, 0]
    },
    summer: {
      from: new Date(2026, 5, 1),
      to: new Date(2026, 7, 1),
      hours: ["10:00-13:00", "14:00-16:00"],
      days: false
    }
  }
});
  • unsetWorkTime (config): void - unsets a working time in the Gantt Chart
    • config - (object) - the configuration object of a time span:
      • day? - (string | number) - optional, a number of a week day [0 (Sunday) - 6 (Saturday)]. Note, you can set only 1 day at once
      • date? - (Date) - optional, a specific date to set as a working day or day off
      • hours? - (string[] | number[] | boolean) - optional, an array of working hours as 'from'-'to' pairs. 'false' value unsets working hours, 'true' (default value) applies the default hours (["8:00-17:00"])
calendar.unsetWorkTime({ hours: ["9:00-18:00"] });
calendar.unsetWorkTime({ day: "5", hours: ["9:00-18:00"] });
calendar.unsetWorkTime({ day: 5, hours: false });
calendar.unsetWorkTime({ date: new Date(2025, 5, 6), hours: true });
  • isWorkTime (config, time_unit): boolean - checks whether the specified date is working
    • config - (Date | object) - either a date to check or the configuration object of a time span:
      • date - (Date) - a date to check
      • unit? - (string) - optional, a time unit: "minute", "hour", "day", "week", "month", "year"
    • time_unit? - (string) - optional, a time unit: "minute", "hour", "day", "week", "month", "year". Not needed at all when the first parameter is specified as an object
var calendar = gantt.getTaskCalendar(task);
if (calendar.isWorkTime({date: date})){
    alert("worktime of task" + task.text);
}
 
calendar.isWorkTime(new Date(2025, 5, 6));
calendar.isWorkTime(new Date(2025, 5, 6), "hour");
calendar.isWorkTime({ date: new Date(2025, 5, 6), unit: "hour" });
  • getClosestWorkTime (config): Date - returns the closest working time
    • config - (Date | object) - the configuration object:
      • date - (Date) - a date to get the closest working time for
      • dir? - (string) - optional, specifies the direction of the closest time: "future" or "past"
      • unit? - (string) - optional, a time unit to search for the closest working time
calendar.getClosestWorkTime(new Date(2025, 5, 6));
calendar.getClosestWorkTime({ 
    date: new Date(2025, 5, 6), 
    unit: "hour",
    dir: "past" 
});
  • calculateEndDate (config, duration, unit): Date - calculates the end date of a task
    • config - (Date | object) - either the date when a task is scheduled to begin or the configuration object of a time span:
      • start_date - (Date) - the date when a task is scheduled to begin
      • duration - (number) - the duration of a task
      • unit? - (string) - optional, the time unit of the duration: "minute", "hour", "day", "week", "month", "year"
    • duration? - (number) - optional, the duration of a task. Not needed at all when the first parameter is specified as an object
    • unit? - (string) - optional, the time unit of the duration. Not needed at all when the first parameter is specified as an object
calendar.calculateEndDate(new Date(2025, 5, 6), 2, "hour");
calendar.calculateEndDate({ 
    start_date: new Date(2025, 5, 6), 
    duration: 2, 
    unit: "hour" 
});
  • calculateDuration (config, end): number - calculates the duration of a task
    • config - (Date | object) - either the date when a task is scheduled to begin or the configuration object of a time span:
      • start_date - (Date) - the date when a task is scheduled to begin
      • end_date - (Date) - the date when a task is scheduled to be completed
    • end? - (Date) - the date when a task is scheduled to be completed. Not needed at all when the first parameter is specified as an object
calendar.calculateDuration(new Date(2025, 5, 6), new Date(2025, 5, 17));
calendar.calculateDuration({ 
    start_date: new Date(2025, 5, 6), 
    end_date: new Date(2025, 5, 17) 
});

Properties

  • id - (string | number) - the id of a task's calendar
See also
Back to top