Skip to content

Commit b34f160

Browse files
committed
[update] calendar object and unsetWorkTime() api pages
1 parent 55bcbf7 commit b34f160

File tree

2 files changed

+78
-22
lines changed

2 files changed

+78
-22
lines changed

data/api/gantt_calendar_other.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,79 @@ The **calendar** object possesses the following methods and properties:
3030
- **_to_** - (*Date*) - the date when the time span is scheduled to be completed
3131
- **_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"])
3232
- **_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.
33-
3433

3534
~~~js
3635
calendar.setWorkTime({ hours:["9:00-18:00"] });
36+
calendar.setWorkTime({ day: 5, hours: ["9:00-18:00"] });
37+
calendar.setWorkTime({ day: 5, hours: false });
38+
calendar.setWorkTime({ date: new Date(2025, 5, 6), hours: ["9:00-18:00"] });
39+
calendar.setWorkTime({ date: new Date(2025, 5, 6), hours: false });
40+
calendar.setWorkTime({ hours: false });
41+
calendar.setWorkTime({
42+
customWeeks: {
43+
winter: {
44+
from: new Date(2025, 11, 1),
45+
to: new Date(2026, 2, 1),
46+
hours: ["8:00-13:00", "14:00-16:00"],
47+
days: [1, 1, 1, 1, 1, 0, 0]
48+
},
49+
summer: {
50+
from: new Date(2026, 5, 1),
51+
to: new Date(2026, 7, 1),
52+
hours: ["10:00-13:00", "14:00-16:00"],
53+
days: [1, 1, 0, 1, 1, 0, 0]
54+
}
55+
}
56+
});
57+
calendar.setWorkTime({
58+
customWeeks: {
59+
winter: {
60+
from: new Date(2025, 11, 1),
61+
to: new Date(2026, 2, 1),
62+
hours: ["8:00-13:00", "14:00-16:00"],
63+
days: [1, ["8:00-13:00"], 1, 1, ["14:00-16:00"], 0, 0]
64+
},
65+
summer: {
66+
from: new Date(2026, 5, 1),
67+
to: new Date(2026, 7, 1),
68+
hours: ["10:00-13:00", "14:00-16:00"],
69+
days: false
70+
}
71+
}
72+
});
3773
~~~
3874

3975
- <span class=submethod>**unsetWorkTime (config): void**</span> - unsets a working time in the Gantt Chart
4076
- **_config_** - (*object*) - the [configuration object](api/gantt_unsetworktime.md#configurationobjectproperties) of a time span:
4177
- **_day?_** - (*string | number*) - optional, a number of a week day [0 (Sunday) - 6 (Saturday)]. Note, you can set only 1 day at once
4278
- **_date?_** - (*Date*) - optional, a specific date to set as a working day or day off
4379
- **_hours?_** - (*string[] | number[] | boolean*) - optional, an array of working hours as 'from'-'to' pairs.
44-
'false' value sets a day-off, 'true' (default value) applies the default hours (["8:00-17:00"])
80+
'false' value unsets working hours, 'true' (default value) applies the default hours (["8:00-17:00"])
4581

4682

4783
~~~js
48-
calendar.unsetWorkTime({ hours:["9:00-18:00"] });
84+
calendar.unsetWorkTime({ hours: ["9:00-18:00"] });
85+
calendar.unsetWorkTime({ day: "5", hours: ["9:00-18:00"] });
86+
calendar.unsetWorkTime({ day: 5, hours: false });
87+
calendar.unsetWorkTime({ date: new Date(2025, 5, 6), hours: true });
4988
~~~
5089

5190
- <span class=submethod>**isWorkTime (config, time_unit): boolean**</span> - checks whether the specified date is working
5291
- **_config_** - (*Date | object*) - either a date to check or the [configuration object](api/gantt_isworktime.md#configurationobjectproperties) of a time span:
5392
- **_date_** - (*Date*) - a date to check
5493
- **_unit?_** - (*string*) - optional, a time unit: "minute", "hour", "day", "week", "month", "year"
5594
- **_task?_** - (*Task*) - optional, the object of the task the duration of which should be calculated
56-
- **_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<br><br>
95+
- **_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
5796

5897
~~~js
5998
var calendar = gantt.getTaskCalendar(task);
6099
if (calendar.isWorkTime({date: date})){
61100
alert("worktime of task" + task.text);
62101
}
102+
103+
calendar.isWorkTime(new Date(2025, 5, 6));
104+
calendar.isWorkTime(new Date(2025, 5, 6), "hour");
105+
calendar.isWorkTime({ date: new Date(2025, 5, 6), unit: "hour" });
63106
~~~
64107

65108
- <span class=submethod>**getClosestWorkTime (config): Date**</span> - returns the closest working time
@@ -70,14 +113,15 @@ if (calendar.isWorkTime({date: date})){
70113
- **_task?_** - (*Task*) - optional, the object of the task to use its calendar
71114

72115
~~~js
73-
calendar.getClosestWorkTime({
74-
date:new Date(2013,0,1),
75-
dir:"future",
76-
unit:"hour"
116+
calendar.getClosestWorkTime(new Date(2025, 5, 6));
117+
calendar.getClosestWorkTime({
118+
date: new Date(2025, 5, 6),
119+
unit: "hour",
120+
task: gantt.getTask(2),
121+
dir: "past"
77122
});
78123
~~~
79124

80-
81125
- <span class=submethod>**calculateEndDate (config, duration, unit): Date**</span> - calculates the end date of a task
82126
- **_config_** - (*Date | object*) - either the date when a task is scheduled to begin or the [configuration object](api/gantt_calculateenddate.md#configurationobjectproperties) of a time span:
83127
- **_start_date_** - (*Date*) - the date when a task is scheduled to begin
@@ -88,7 +132,12 @@ calendar.getClosestWorkTime({
88132
- **_unit?_** - (*string*) - optional, the time unit of the duration. Not needed at all when the first parameter is specified as an object<br>
89133

90134
~~~js
91-
var end_date = calendar.calculateEndDate({start_date:date, duration:duration});
135+
calendar.calculateEndDate(new Date(2025, 5, 6), 2, "hour");
136+
calendar.calculateEndDate({
137+
start_date: new Date(2025, 5, 6),
138+
duration: 2,
139+
unit: "hour"
140+
});
92141
~~~
93142

94143
- <span class=submethod>**calculateDuration (config, end): number**</span> - calculates the duration of a task
@@ -99,10 +148,13 @@ var end_date = calendar.calculateEndDate({start_date:date, duration:duration});
99148
- **_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<br>
100149

101150
~~~js
102-
calendar.calculateDuration(new Date(2013,02,15), new Date(2013,02,25));
151+
calendar.calculateDuration(new Date(2025, 5, 6), new Date(2025, 5, 17));
152+
calendar.calculateDuration({
153+
start_date: new Date(2025, 5, 6),
154+
end_date: new Date(2025, 5, 17)
155+
});
103156
~~~
104157

105-
106158
###Properties
107159

108160
- <span class=subproperty>**id**</span> - (*string | number*) - the id of a task's calendar

data/api/gantt_unsetworktime.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ unsetWorkTime
1515
gantt.config.work_time = true;
1616

1717
// changes the working time of working days from ["8:00-17:00"] to ["9:00-18:00"]
18-
gantt.setWorkTime({ hours:["9:00-18:00"] });
18+
gantt.setWorkTime({ hours: ["9:00-18:00"] });
1919
// unsets the working time
20-
gantt.unsetWorkTime({ hours:["9:00-18:00"] });
20+
gantt.unsetWorkTime({ hours: ["9:00-18:00"] });
2121

2222
@template: api_method
2323
@descr:
@@ -51,32 +51,36 @@ The configuration object can contain the following properties:
5151
<tr>
5252
<td colspan=2 style="text-align:left !important; ">
5353
~~~js
54-
//makes all Mondays day-offs
55-
gantt.unsetWorkTime({ day:1, hours:false });
54+
// unsets working hours for Mondays
55+
gantt.unsetWorkTime({ day: 1, hours: false });
5656
~~~
5757
</td>
5858
</tr>
5959
<tr>
6060
<td rowspan=2><b id="date">date</b></td>
61-
<td> a specific date to set as a working day or day off</td>
61+
<td> a specific date to set/unset working hours for</td>
6262
</tr>
6363
<tr>
6464
<td colspan=2 style="text-align:left !important; ">
6565
~~~js
66-
//makes a specific date a day-off
67-
gantt.unsetWorkTime({date:new Date(2013,0,1), hours:false})
66+
// unsets working hours for a specific date
67+
gantt.unsetWorkTime({
68+
date: new Date(2025, 11, 1),
69+
hours: false
70+
});
6871
~~~
6972
</td>
7073
</tr>
7174
<tr>
7275
<td rowspan=2><b id="hours">hours</b></td>
73-
<td> an array of working hours as 'from'-'to' pairs. <br><i>'false'</i> value sets a day-off, <i>'true' (default value)</i> applies the default hours (["8:00-17:00"])</td>
76+
<td> an array of working hours as 'from'-'to' pairs. <br><i>'false'</i> value unsets working hours,
77+
<i>'true' (default value)</i> applies the default hours: (["8:00-17:00"])</td>
7478
</tr>
7579
<tr>
7680
<td colspan=2 style="text-align:left !important; ">
7781
~~~js
78-
//sets the working time for Fridays from 8:00 till 12:00
79-
gantt.unsetWorkTime({day : 5, hours : ["8:00-12:00"]});
82+
// unsets the working time for Fridays from 8:00 till 12:00
83+
gantt.unsetWorkTime({ day : 5, hours : ["8:00-12:00"] });
8084
~~~
8185
</td>
8286
</tr>

0 commit comments

Comments
 (0)