gantt
gantt copied to clipboard
Test fails on EDT timezone
Noticed when running tests:
yarn test
I would get a single failure due to this line:
https://github.com/frappe/gantt/blob/master/tests/date_utils.test.js#L47
Parsing dates with the Date constructor is generally equivalent to Date.parse() which may use the local timezone to adjust its internal representation of the date.
So, for me (EDT) this date:
new Date('2017-09-18')
Returns 17 for its date component when calling date.getDate() which breaks the test.
Now, I'm not sure if you intended to use local time parsing anyways which means this issue doesn't really matter. But, if not, this might cause other issues dealing with date parsing. At the very least this breaks the test if you are on a timezone with daylights savings like I am.
I noticed this while tracking down another issue in frappe, but that's something for later when I figure out what's up.
Good job on the project by the way, its quite sleek
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.