From bbf63b0b563dbf55c07fb0c5bfe5cf17f3b84fb8 Mon Sep 17 00:00:00 2001 From: Adrien Dieudonne Date: Thu, 10 Aug 2017 15:52:49 +0200 Subject: [FIX] web: Calendar: correctly display events Before this rev., the events in Calendar views (month mode) weren't correctly displayed: the last day of the event wasn't displayed as being part of the event. For instance, in leaves, a leave of 3 days from the 16th of Augustus until the 18th was only displayed over the 16th and the 17th. Moreover, when an event was created from a Calendar view with option all_day=False, the default start and end dates weren't correctly computed according to the user timezone, which could lead to the creation of multiple days event whereas the user clicked on a specific day. For instance, with timezone GMT+2, when clicking on the 18th of Augustus in the Leave Calendar view (month mode), it opened a dialog for the creation of a 2-day leave from the 18th to the 19th. This rev. fixes those two issues. --- .../web/static/src/js/views/calendar/calendar_model.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src') diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js index ed02983d957..e338ae55ece 100644 --- a/addons/web/static/src/js/views/calendar/calendar_model.js +++ b/addons/web/static/src/js/views/calendar/calendar_model.js @@ -45,20 +45,26 @@ return AbstractModel.extend({ if (event.allDay || end.diff(start) % 86400000 === 0) { event.allDay = true; - if (this.scale === 'month') { + if (this.data.scale === 'month') { + // In month, FullCalendar gives the end day as the + // next day at midnight (instead of 23h59). + end.add(-1, 'days'); if (event.r_start) { start.hours(event.r_start.hours()) .minutes(event.r_start.minutes()) .seconds(event.r_start.seconds()) .utc(); - end.add(-1, 'days') - .hours(event.r_end.hours()) + end.hours(event.r_end.hours()) .minutes(event.r_end.minutes()) .seconds(event.r_end.seconds()) .utc(); - } else { + } else if (this.mapping.all_day) { start.utc(); end.utc(); + } else { + // default hours in the user's timezone + start.hours(7).add(-this.getSession().getTZOffset(start), 'minutes'); + end.hours(19).add(-this.getSession().getTZOffset(end), 'minutes'); } } else if (this.mapping.all_day) { start.startOf('day'); @@ -622,6 +628,10 @@ return AbstractModel.extend({ // r.start = date_start.format('YYYY-MM-DD'); // r.end = date_stop.format('YYYY-MM-DD'); } else if (this.data.scale === 'month' && this.fields[this.mapping.date_start].type !== 'date') { + // In month, FullCalendar gives the end day as the + // next day at midnight (instead of 23h59). + date_stop.add(1, 'days'); + // allow to resize in month mode r.reset_allday = r.allDay; r.allDay = true; -- cgit v1.2.3