Fix event positionning in the grid.
This commit is contained in:
parent
504044b1cf
commit
b2dabd1dc4
1 changed files with 10 additions and 4 deletions
|
@ -1,7 +1,10 @@
|
|||
// Based on https://stackoverflow.com/a/15289883
|
||||
function computeDateDifferenceInHours (date1, date2) {
|
||||
d1 = new Date(date1.getYear(), date1.getMonth(), date1.getDate(), date1.getHours());
|
||||
d2 = new Date(date2.getYear(), date2.getMonth(), date2.getDate(), date2.getHours());
|
||||
|
||||
const msPerHour = 60 * 60 * 1000;
|
||||
return Math.floor(Math.abs(date2.getTime() - date1.getTime()) / msPerHour);
|
||||
return Math.abs(d2.getTime() - d1.getTime()) / msPerHour;
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,7 +90,8 @@ class Calendar {
|
|||
this.startHourToDisplay = this.startDate.getHours();
|
||||
this.endHourToDisplay = this.endDate.getHours();
|
||||
|
||||
this.nbHoursToDisplay = computeDateDifferenceInHours(this.startDate, this.endDate);
|
||||
this.nbHoursToDisplay = Math.floor(computeDateDifferenceInHours(this.startDate, this.endDate));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -484,7 +488,7 @@ class Event {
|
|||
return 1;
|
||||
}
|
||||
|
||||
return 1 + computeDateDifferenceInHours(this.calendar.startDate, this.startDate);
|
||||
return 1 + Math.floor(computeDateDifferenceInHours(this.calendar.startDate, this.startDate));
|
||||
}
|
||||
|
||||
// Assuming the events can appear in the calendar
|
||||
|
@ -493,8 +497,10 @@ class Event {
|
|||
return 1 + this.calendar.nbHoursToDisplay;
|
||||
}
|
||||
|
||||
let shiftedEndDate = new Date(this.endDate.getTime() + 1000 * 60 * 59);
|
||||
|
||||
return 1 + this.calendar.nbHoursToDisplay
|
||||
- computeDateDifferenceInHours(this.endDate, this.calendar.endDate);
|
||||
- Math.ceil(computeDateDifferenceInHours(shiftedEndDate, this.calendar.endDate));
|
||||
}
|
||||
|
||||
updatePositionInGrid () {
|
||||
|
|
Loading…
Reference in a new issue