Documentation
Most teams do not work every hour of every day. jqxGantt knows the days of the week and the hours of the day that are not working time: it shades them in the timeline and, if you ask it to, leaves them out of each task's duration, so a five-day task that starts on Thursday works until the end of the next Wednesday, not of Monday.
This page sets the nonworking days and hours, explains how a task's duration relates to its dates, counts durations in working time, changes the working time with methods, adds public holidays, and snaps dragged tasks to the timeline cells. It builds on the getting-started guide, which shows how to load the files and describe tasks. Each example is a complete page.
Two options describe the time nobody works:
nonworkingDays lists days of the week, numbered as JavaScript's Date.getDay() numbers them: 0 is Sunday, 1 is Monday and 6 is Saturday. [0, 6] is the weekend.nonworkingHours lists hours of the day, from 0 (midnight to 1:00) to 23. A pair in an array is a range that includes both ends: [[0, 7], [18, 23]] is midnight to 8:00 and 18:00 to midnight. A range can go past midnight: [[22, 5]] is 22:00 to 6:00.This sprint plan has both. Its buttons switch between the day and the week view:
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'week',
treeSize: 110,
// Weeks start on Monday
firstDayOfWeek: 1,
// Saturday and Sunday: days are numbered from Sunday (0) to Saturday (6)
nonworkingDays: [0, 6],
// Before 8:00 and from 18:00: the hours 0 to 7 and 18 to 23
nonworkingHours: [[0, 7], [18, 23]],
dateStart: '2026-04-06T00:00:00',
dateEnd: '2026-04-19T00:00:00',
source: [
{ id: 'planning', label: 'Planning', dateStart: '2026-04-06T09:00:00', dateEnd: '2026-04-06T12:00:00' },
{ id: 'form', label: 'Sign-up form', dateStart: '2026-04-06T13:00:00', dateEnd: '2026-04-10T17:00:00' },
{ id: 'review', label: 'Code review', dateStart: '2026-04-13T09:00:00', dateEnd: '2026-04-14T17:00:00' },
{ id: 'release', label: 'Release', type: 'milestone', dateStart: '2026-04-17T16:00:00' }
]
});
On their own, these options only draw: the tasks keep the dates you give them, and a task may run over a weekend. To leave nonworking time out of durations, see Count working time only.
A list that contains all seven days is refused, because the timeline would have no working day: the chart drops the last day of the list and logs a warning. nonworkingDays: [] (the default) makes every day a working day.
Nonworking time is shaded only where a timeline cell is a whole day or an hour:
| View | A cell is | Shaded |
|---|---|---|
'day' | an hour | the nonworking hours of every day, and every hour of a nonworking day |
'week' | a day | the nonworking days |
'month' (with the default monthScale: 'day') | a day | the nonworking days |
'month' with monthScale: 'week', 'quarter', 'year' | a week or a month | nothing |
The working hours example shows the day view.
The Gantt stylesheet shades nonworking cells with --jqx-gantt-chart-timeline-nonworking-color, a shade of the theme's background. It also tints every Saturday and Sunday cell with --jqx-gantt-chart-timeline-weekend-color, the theme's accent colour at 7%, whether or not those are nonworking days, so a team that works on Saturdays still sees Saturday coloured. Before 27.1.0 the two colours were #F5F5F5 and a light blue, #EFF5FD, in every theme, so they stayed light in dark themes such as tailwind-dark.
The examples on this page set both variables on the chart's container: nonworking time becomes a shade of the theme's own background, which works in light and dark themes, and Saturdays and Sundays look like other days unless they are nonworking days. The rule also narrows the day columns so that two weeks fit:
#gantt {
/* Narrower timeline cells, so that two weeks fit (the default is 70px) */
--jqx-gantt-chart-timeline-cell-min-size: 40px;
/* Nonworking time: a shade of the theme's background */
--jqx-gantt-chart-timeline-nonworking-color: color-mix(in srgb, var(--jqx-background-color) 9%, var(--jqx-background));
/* Saturday and Sunday: like any other day, unless they are nonworking days */
--jqx-gantt-chart-timeline-weekend-color: var(--jqx-background);
}
firstDayOfWeek is the day the timeline's weeks start on, from 0 (Sunday) to 6 (Saturday). The timeline then starts on that day of the week before its first date: with firstDayOfWeek: 1 and a plan that starts on Wednesday, April 8, the week view starts on Monday, April 6. Without it (the default, -1), the timeline starts on its first date, whatever day that is, and so do its weeks. The API reference says the default is Sunday; in 27.1.0 and earlier it is not.
firstDayOfWeek does not renumber the days: with firstDayOfWeek: 1, nonworkingDays: [0, 6] is still Sunday and Saturday.
A task has a start (dateStart), an end (dateEnd) and a duration. dateEnd is the moment the task ends, not its last day: a task that works all of Monday to Thursday ends at 00:00 on Friday.
durationUnit sets the unit of duration:
durationUnit | duration: 4 is |
|---|---|
'milisecond' (the default, spelt with one l) | 4 milliseconds |
'second' | 4 seconds |
'minute' | 4 minutes |
'hour' | 4 hours |
'day' | 4 days |
'week' | 4 weeks of 7 × 24 hours |
Set it whenever your tasks have a duration: without it, duration: 4 is four milliseconds and the bar has no width. 'millisecond', spelt the usual way, is not accepted; the chart logs a message and keeps 'milisecond'.
The chart works out what you leave out:
dateStart and duration gets its dateEnd.dateStart and dateEnd gets its duration, in durationUnit, with a fraction where needed: 1.5 hours is 1.5.dateStart and duration; its dateEnd is replaced.The units are fixed lengths: a day is 24 hours. Across a change to or from daylight saving time an end date therefore moves by an hour: in London, four days from March 27, 2026 end at 01:00 on March 31.
The examples write dates as '2026-04-06T00:00:00', with hours, minutes and seconds. In 27.1.0 and earlier the chart reads a date-only string such as '2026-04-06' as midnight UTC and then takes the start of that local day. West of UTC, in the Americas, that is the day before: in New York, '2026-04-06' becomes Sunday, April 5, a nonworking day. A string with a time but no seconds loses its time: '2026-04-09T21:00' becomes midnight. Date objects, such as new Date(2026, 3, 6), are always read as they are.
With adjustToNonworkingTime: true, durations count working time only: the chart steps over nonworking days when it works out an end date, and leaves them out when it works out a duration. This plan counts in working days, with Saturday and Sunday off:
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'week',
firstDayOfWeek: 1,
treeSize: 130,
nonworkingDays: [0, 6],
// Durations count working days only
adjustToNonworkingTime: true,
durationUnit: 'day',
taskColumns: [
{ label: 'Task', value: 'label', size: 85 },
{ label: 'Days', value: 'duration', formatFunction: (value) => String(Math.round(value * 10) / 10) }
],
dateStart: '2026-04-06T00:00:00',
dateEnd: '2026-04-19T00:00:00',
source: [
// A start and a duration: the chart works out the end
{ id: 'design', label: 'Design', dateStart: '2026-04-06T00:00:00', duration: 4 },
{ id: 'build', label: 'Build', dateStart: '2026-04-09T00:00:00', duration: 5 },
// A start and an end: the chart works out the duration
{ id: 'docs', label: 'Docs', dateStart: '2026-04-09T00:00:00', dateEnd: '2026-04-15T00:00:00' },
// A task can start on a nonworking day
{ id: 'test', label: 'Test', dateStart: '2026-04-11T00:00:00', duration: 2 }
]
});
The same plan without adjustToNonworkingTime counts calendar days:
| Task | Data | Working days | Calendar days |
|---|---|---|---|
| Design | Mon, Apr 6 + 4 | ends Fri, Apr 10, 00:00 | ends Fri, Apr 10, 00:00 |
| Build | Thu, Apr 9 + 5 | ends Thu, Apr 16, 00:00 | ends Tue, Apr 14, 00:00 |
| Docs | Thu, Apr 9 to Wed, Apr 15 | duration 4 | duration 6 |
| Test | Sat, Apr 11 + 2 | ends Wed, Apr 15, 00:00 | ends Mon, Apr 13, 00:00 |
A task that starts on a nonworking day keeps its start: Test still starts on Saturday, and its two working days are Monday and Tuesday.
The button switches the option while the page runs:
const toggle = document.getElementById('toggle');
toggle.addEventListener('click', () => {
gantt.adjustToNonworkingTime = !gantt.adjustToNonworkingTime;
toggle.textContent = gantt.adjustToNonworkingTime ? 'Count calendar days' : 'Count working days';
});
A switch keeps each task's duration and moves its end. After Count calendar days, Docs still lasts 4 days but now ends on Monday, April 13; switched back, it ends on Wednesday again.
Changes keep to working time too:
updateTask(id, { dateEnd }) sets the end and works out the duration; updateTask(id, { duration }) works out the end; updateTask(id, { dateStart }) keeps the duration and moves the end. The guide shows updateTask.Nonworking hours count only in the day view: see Working hours.
setWorkTime(settings) sets the working time, and unsetWorkTime(settings) takes some away. Both take an object with days, hours, or both:
setWorkTime({ days: '1-5' }) makes Monday to Friday the working days. Every other day becomes a nonworking day, whatever it was before.unsetWorkTime({ days: [3] }) makes Wednesday a nonworking day too, and keeps the others as they are.Days and hours can be written in several ways, all with both ends included:
| Form | Days | Hours |
|---|---|---|
| A string range | '1-4' | '9-16' or '9:00-16:00' |
| A range in an array | [[1, 4]] | [[9, 16]] |
| A list | [1, 2, 3, 4] | [9, 10, 11, 12, 13, 14, 15, 16] |
| One number | 2 | 12 |
An hour is the whole hour, so '9-16' is 9:00 to 17:00, not to 16:00.
Two more methods read the working time. isWorkingDay(date) returns whether a Date falls on a working day. getWorkingHours() returns the working hours as numbers.
This page counts in working days, and its buttons change them:
<p>
<button id="fiveDays">Monday to Friday</button>
<button id="fourDays">Monday to Thursday</button>
<button id="closeWednesday">Close on Wednesdays</button>
</p>
const chart = document.querySelector('#gantt jqx-gantt-chart');
function changeWorkTime(method, settings) {
gantt[method](settings);
// In 27.1.0 and earlier setWorkTime and unsetWorkTime change the chart but not the
// options of the widget, and the next option change would put the old working
// time back: copy the new values into the options.
gantt.nonworkingDays = chart.nonworkingDays.slice();
gantt.nonworkingHours = chart.nonworkingHours.slice();
// A timeline that fits in the chart keeps its old shading until the view
// changes: switch the view and back.
const view = gantt.view;
gantt.view = view === 'day' ? 'week' : 'day';
gantt.view = view;
showWorkTime();
}
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const mondayFirst = [1, 2, 3, 4, 5, 6, 0];
function showWorkTime() {
const closed = mondayFirst.filter((day) => gantt.nonworkingDays.includes(day)).map((day) => dayNames[day]).join(', ');
const friday = gantt.isWorkingDay(new Date(2026, 3, 10)) ? 'yes' : 'no';
document.getElementById('status').textContent =
`Nonworking days: ${closed}. Is Friday, April 10 a working day? ${friday}.`;
}
// Working days, from Monday (1) to Friday (5): the other days become nonworking days
document.getElementById('fiveDays').addEventListener('click', () => {
changeWorkTime('setWorkTime', { days: '1-5' });
});
document.getElementById('fourDays').addEventListener('click', () => {
changeWorkTime('setWorkTime', { days: [[1, 4]] });
});
// One more nonworking day; the others stay as they are
document.getElementById('closeWednesday').addEventListener('click', () => {
changeWorkTime('unsetWorkTime', { days: [3] });
});
chart.whenReady(showWorkTime);
After Monday to Thursday the status line reads Nonworking days: Fri, Sat, Sun. Is Friday, April 10 a working day? no., and the tasks move: Build, four working days from Wednesday, now ends on Wednesday, April 15 instead of Tuesday, April 14.
The changeWorkTime function works around two problems of 27.1.0 and earlier:
setWorkTime and unsetWorkTime change the chart but not the widget's nonworkingDays and nonworkingHours options. The next change of any option, such as gantt.view or gantt.treeSize, sends the widget's old values to the chart and undoes the change. Copying the chart's values into the options keeps them.nonworkingDays or nonworkingHours while the page runs.To make every day a working day, set nonworkingDays to []: setWorkTime({ days: '0-6' }) leaves Saturday a nonworking day.
Pass isWorkingDay a Date or a string with a time. Given '2026-04-11', a Saturday, it returns true in New York, for the reason given in Write dates with a time.
Durations in hours need the day view. In 27.1.0 and earlier, adjustToNonworkingTime leaves out nonworking hours only while view is 'day'; in the other views it leaves out nonworking days but counts every hour. This network maintenance runs on two shifts, from 6:00 to 22:00:
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
// Durations skip nonworking hours only in the day view
view: 'day',
treeSize: 120,
nonworkingDays: [0, 6],
// From 22:00 to 6:00: a range can go past midnight
nonworkingHours: [[22, 5]],
adjustToNonworkingTime: true,
durationUnit: 'hour',
taskColumns: [
{ label: 'Task', value: 'label', size: 75 },
{ label: 'Hours', value: 'duration', formatFunction: (value) => String(Math.round(value * 10) / 10) }
],
dateStart: '2026-04-09T20:00:00',
dateEnd: '2026-04-10T07:00:00',
source: [
{ id: 'announce', label: 'Announce', dateStart: '2026-04-09T20:00:00', duration: 1 },
{ id: 'switches', label: 'Switches', dateStart: '2026-04-09T21:00:00', duration: 2 },
{ id: 'firewall', label: 'Firewall', dateStart: '2026-04-09T21:00:00', duration: 1.5 }
]
});
Switches starts at 21:00 and lasts 2 working hours: one before 22:00 and one after 6:00, so it ends at 7:00. In the week view the same task would end at 23:00. The dates are worked out when the chart is created and when a task changes, so switching the view later keeps them.
The page's buttons change the working hours with the changeWorkTime function of the previous example, and its status line shows getWorkingHours():
function showWorkTime() {
const switches = gantt.getTask('switches');
document.getElementById('status').textContent =
`Working hours: ${gantt.getWorkingHours().join(', ')}. Switches ends at ${switches.dateEnd.toLocaleString()}.`;
}
// Working hours: '6-21' is 6:00 to 21:59, that is, until 22:00
document.getElementById('twoShifts').addEventListener('click', () => {
changeWorkTime('setWorkTime', { hours: '6-21' });
});
document.getElementById('dayShift').addEventListener('click', () => {
changeWorkTime('setWorkTime', { hours: '6-13' });
});
// One more nonworking hour: 12:00 to 13:00
document.getElementById('break').addEventListener('click', () => {
changeWorkTime('unsetWorkTime', { hours: [12] });
});
chart.whenReady(showWorkTime);
With the day shift only (6:00 to 14:00), Switches ends at 8:00 on Friday, and Announce, which starts at 20:00 in nonworking time, does its hour from 6:00 to 7:00. Break at 12:00 takes the hour from 12:00 to 13:00 out.
In 27.1.0 and earlier, getWorkingHours() never returns 23: without nonworking hours it returns 0 to 22.
nonworkingDays repeats every week; the chart has no option for single dates such as public holidays. The page below keeps its own calendar, the weekend plus the bank holidays of England and Wales, and works out each task's end itself. Four functions answer the calendar's questions:
// The company calendar: weekends, and the bank holidays of England and Wales in spring 2026
const weekend = [0, 6];
const holidays = [
{ date: '2026-04-03', label: 'Good Friday' },
{ date: '2026-04-06', label: 'Easter Monday' },
{ date: '2026-05-04', label: 'Early May bank holiday' },
{ date: '2026-05-25', label: 'Spring bank holiday' }
];
// The local date of a Date as 'YYYY-MM-DD'
const dayKey = (date) => [
date.getFullYear(),
String(date.getMonth() + 1).padStart(2, '0'),
String(date.getDate()).padStart(2, '0')
].join('-');
const holidayKeys = new Set(holidays.map((holiday) => holiday.date));
function isWorkingDate(date) {
return !weekend.includes(date.getDay()) && !holidayKeys.has(dayKey(date));
}
// The first working day on or after a date, at midnight
function nextWorkingDate(date) {
const day = new Date(date);
day.setHours(0, 0, 0, 0);
while (!isWorkingDate(day)) {
day.setDate(day.getDate() + 1);
}
return day;
}
// The end of a task that starts on a date and takes a number of working days:
// midnight after its last working day
function addWorkingDays(start, days) {
const day = new Date(start);
while (days > 0) {
if (isWorkingDate(day)) {
days--;
}
day.setDate(day.getDate() + 1);
}
return day;
}
// The working days from a start date up to (not including) an end date
function countWorkingDays(start, end) {
let days = 0;
for (const day = new Date(start); day < end; day.setDate(day.getDate() + 1)) {
if (isWorkingDate(day)) {
days++;
}
}
return days;
}
Each task has a start and a number of working days. The chart gets the start and the end, marks each holiday with a date marker and shows the working days in a column. adjustToNonworkingTime stays off: the chart would count the holidays as working days (Build, from Thursday, April 2 to Thursday, April 9, would last 6 days instead of 4).
// Each task has a start and a number of working days; the page works out the end.
const plan = [
{ id: 'design', label: 'Design', start: '2026-03-30T00:00:00', workDays: 4 },
{ id: 'build', label: 'Build', start: '2026-04-02T00:00:00', workDays: 4 },
{ id: 'review', label: 'Review', start: '2026-04-07T00:00:00', workDays: 3 }
];
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'week',
firstDayOfWeek: 1,
treeSize: 130,
nonworkingDays: weekend,
// The page counts the working days itself, so that holidays count too
adjustToNonworkingTime: false,
snapToNearest: true,
// A line and a label on each holiday
dateMarkers: holidays.map((holiday) => ({ date: holiday.date + 'T00:00:00', label: holiday.label })),
taskColumns: [
{ label: 'Task', value: 'label', size: 85 },
{ label: 'Days', value: 'workDays' }
],
dateStart: '2026-03-30T00:00:00',
dateEnd: '2026-04-12T00:00:00',
source: plan.map((task) => {
const dateStart = nextWorkingDate(task.start);
return {
id: task.id,
label: task.label,
workDays: task.workDays,
dateStart: dateStart,
dateEnd: addWorkingDays(dateStart, task.workDays)
};
})
});
When the user moves or resizes a task, the chart knows nothing of the holidays, so the page corrects the dates in the dragEnd and resizeEnd events. Their detail holds the task's id and the changed task as item:
function showTask(id) {
const task = gantt.getTask(id);
const lastDay = new Date(task.dateEnd.getTime() - 1);
const format = { weekday: 'short', day: 'numeric', month: 'short' };
document.getElementById('status').textContent =
`${task.label}: ${task.dateStart.toLocaleDateString('en-GB', format)} to ` +
`${lastDay.toLocaleDateString('en-GB', format)}, ${task.workDays} working days.`;
}
const element = document.getElementById('gantt');
// A moved task keeps its working days: it starts on the next working day and
// ends after the same number of working days.
element.addEventListener('dragEnd', (event) => {
const task = event.detail.item;
const dateStart = nextWorkingDate(task.dateStart);
gantt.updateTask(event.detail.id, { dateStart: dateStart, dateEnd: addWorkingDays(dateStart, task.workDays) });
showTask(event.detail.id);
});
// A resized task gets the working days between its new start and end.
element.addEventListener('resizeEnd', (event) => {
const task = event.detail.item;
const workDays = Math.max(1, countWorkingDays(task.dateStart, task.dateEnd));
gantt.updateTask(event.detail.id, { workDays: workDays, dateEnd: addWorkingDays(task.dateStart, workDays) });
showTask(event.detail.id);
});
Design moved one day later starts on Tuesday, March 31 and keeps its 4 working days, so it now ends on Tuesday, April 7. Review dropped on Easter Monday starts on the Tuesday after it. Making Review one day longer gives it 4 working days; an end dropped on Saturday stays at the end of Friday.
With snapToNearest: true, a task that the user drags or resizes stops at the nearest edge of a timeline cell: a day in the week view, an hour in the day view.
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'week',
firstDayOfWeek: 1,
treeSize: 130,
nonworkingDays: [0, 6],
durationUnit: 'day',
// Dragging and resizing stop at the nearest day (the cells of the week view)
snapToNearest: true,
taskColumns: [
{ label: 'Task', value: 'label', size: 85 },
{ label: 'Days', value: 'duration', formatFunction: (value) => String(Math.round(value * 10) / 10) }
],
dateStart: '2026-04-06T00:00:00',
dateEnd: '2026-04-19T00:00:00',
source: [
{ id: 'design', label: 'Design', dateStart: '2026-04-06T00:00:00', duration: 3 },
{ id: 'build', label: 'Build', dateStart: '2026-04-08T00:00:00', duration: 4 },
{ id: 'test', label: 'Test', dateStart: '2026-04-14T00:00:00', duration: 2 }
]
});
The page shows the new dates of a task in its status line:
const format = {
weekday: 'short', day: 'numeric', month: 'short',
hour: '2-digit', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3
};
function showDates(event) {
const { item, dateStart, dateEnd } = event.detail;
document.getElementById('status').textContent =
`${item.label}: ${dateStart.toLocaleString('en-GB', format)} to ${dateEnd.toLocaleString('en-GB', format)}`;
}
document.getElementById('gantt').addEventListener('dragEnd', showDates);
document.getElementById('gantt').addEventListener('resizeEnd', showDates);
Design dragged 2.4 days later starts on Wednesday at 00:00 and keeps its 3 days; without snapToNearest it would start on Wednesday at about 9:36. In the day view a drag of 1.4 cells moves a task by one hour.
In 27.1.0 and earlier, an end that snaps lands on the last millisecond of its cell: Test's end dragged 1.3 days later ends on Thursday at 23:59:59.999, not on Friday at 00:00. Its duration is a little under 3 days, so the page's Days column rounds it. Two more things to know:
snapToNearest in the day, week and month views only.