gantt
gantt copied to clipboard
Several bugs when Gantt start is in different timezone because of daylight savings time
Several bugs happen when a shift in daylight savings time happened between the start of the Gantt and a Gantt rectangle. For example, if there's a switch from UTC-4 to UTC-5, times that are calculated using the gantt_start time as reference will gain 1 hour, since the 00:00 AM at UTC-4 is an hour later than 00:00 AM at UTC-5. My bet is that the reverse situation can also happen.
- gantt rectangles will be slightly shifted by 1 hour all across the board
- If, for example, the user set the end date on the 28-11-2018, the real end time returned by the Gantt should be the 28-11-2018 at 11:59 PM. However, with this bug, the end time will be the 29-11-2018 at 00:59 AM. Checking only the date without checking if this bug happened will get you the day after the day the user intended.
+1
Hey, I had this issue as well. The problem lies in "compute_start_end_date()" of Bar.js. They are finding the start date based off of the views start date and the x position of the bar. So, if the gantt start date is in Daylight savings and the bar start date is in standard, then the times will be off by 1 hour. The way I fixed this was by extending the Bar class in a custom Bar class, overwriting "compute_start_end_date()" with:
export class CustomBar extends Bar {
compute_start_end_date() {
const bar = this.$bar;
const x_in_units = bar.getX() / this.gantt.options.column_width;
let new_start_date = date_utils.add(
this.gantt.gantt_start,
x_in_units * this.gantt.options.step,
'hour'
);
const start_offset = this.gantt.gantt_start.getTimezoneOffset() - new_start_date.getTimezoneOffset();
if (start_offset !== 0) {
new_start_date = date_utils.add(
new_start_date,
start_offset,
'minute'
);
}
const width_in_units = bar.getWidth() / this.gantt.options.column_width;
const new_end_date = date_utils.add(
new_start_date,
width_in_units * this.gantt.options.step,
'hour'
);
return { new_start_date, new_end_date };
}
}
The key here is adding the timezone offset difference between the gantt start and the bar start.
@jcjobin Hi ! Could you give a hint how to extend and use your example "CustomBar" without modifying original source of gantt lib?
Thanks for the snippet. In theoretical terms what is supposed to be displayed on the timeline during repeating or missing hours? Should there be a skipped 2am and a double 2am?