calendar
工作日历对象的接口
object calendar;
Details
有关工作日历的更多详细信息,请参阅 工作时间计算 文章。
calendar 对象包含以下方法和属性:
方法
- setWorkTime (config): boolean - 定义甘特图的工作时间
- config - (object) - 描述时间范围的配置对象:
- day? - (string | number) - 可选,周几编号 [0(星期日)- 6(星期六)]。注意一次只能设置一天
- date? - (Date) - 可选,指定某个日期作为工作日或非工作日
- hours? - (string[] | number[] | boolean) - 可选,表示工作时间的“开始-结束”对数组。设置为 'false' 表示休息日,'true'(默认)应用默认时间(["8:00-17:00"])
- customWeeks? - (object) - 可选,定义不同时间段工作时间规则的对象。包含键值对,键为时间段名称,值为带属性的对象:
- [timespan: string] - (object) - 带有工作时间设置的时间段,键名作为时间段名称
- from - (Date) - 时间段开始日期
- to - (Date) - 时间段结束日期
- hours? - (string[] | number[]) - 可选,表示工作时间的“开始-结束”对数组。'false' 表示休息日,'true'(默认)应用默认时间(["8:00-17:00"])
- days? - (WorkDaysTuple | boolean) - 可选,长度为7的数组,表示一周的每天(0 - 星期日,6 - 星期六),1/true 表示工作日,0/false 表示非工作日。
calendar.setWorkTime({ hours:["9:00-18:00"] });
- unsetWorkTime (config): void - 从甘特图中移除工作时间设置
- config - (object) - 描述时间范围的配置对象:
- day? - (string | number) - 可选,周几编号 [0(星期日)- 6(星期六)]。一次只能设置一天
- date? - (Date) - 可选,指定某个日期作为工作日或非工作日
- hours? - (string[] | number[] | boolean) - 可选,表示工作时间的“开始-结束”对数组。'false' 表示休息日,'true'(默认)应用默认时间(["8:00-17:00"])
calendar.unsetWorkTime({ hours:["9:00-18:00"] });
- isWorkTime (config, time_unit): boolean - 判断指定日期是否为工作时间
- config - (Date | object) - 要检查的日期或描述时间范围的配置对象:
- date - (Date) - 要检查的日期
- unit? - (string) - 可选,时间单位:"minute", "hour", "day", "week", "month", "year"
- task? - (Task) - 可选,需考虑其持续时间的任务对象
- time_unit? - (string) - 可选,时间单位:"minute", "hour", "day", "week", "month", "year"。如果第一个参数是对象,则不必提供
var calendar = gantt.getTaskCalendar(task);
if (calendar.isWorkTime({date: date})){
alert("worktime of task" + task.text);
}
- getClosestWorkTime (config): Date - 查找最近的工作时间
- config - (Date | object) - 配置对象:
- date - (Date) - 要查找最近工作时间的日期
- dir? - (string) - 可选,搜索方向:"future" 或 "past"
- unit? - (string) - 可选,搜索使用的时间单位
- task? - (Task) - 可选,使用其 calendar 的任务对象
calendar.getClosestWorkTime({
date:new Date(2013,0,1),
dir:"future",
unit:"hour"
});
- calculateEndDate (config, duration, unit): Date - 计算任务的结束日期
- config - (Date | object) - 任务的开始日期或描述时间范围的配置对象:
- start_date - (Date) - 任务开始日期
- duration - (number) - 任务持续时间
- unit? - (string) - 可选,持续时间的时间单位:"minute", "hour", "day", "week", "month", "year"
- task? - (Task) - 可选,要计算持续时间的任务对象
- duration? - (number) - 可选,任务持续时间。如果第一个参数是对象,则不需要
- unit? - (string) - 可选,持续时间的时间单位。如果第一个参数是对象,则不需要
var end_date = calendar.calculateEndDate({start_date:date, duration:duration});
- calculateDuration (config, end): number - 计算任务的持续时间
- config - (Date | object) - 任务开始日期或描述时间范围的配置对象:
- start_date - (Date) - 任务开始日期
- end_date - (Date) - 任务结束日期
- task? - (Task) - 可选,要计算持续时间的任务对象
- end? - (Date) - 任务结束日期。如果第一个参数是对象,则不需要
calendar.calculateDuration(new Date(2013,02,15), new Date(2013,02,25));
属性
- id - (string | number) - 任务日历的标识符
See also
Back to top