From 56b9ec0aa0210cdd99144c2b77ce4507e6b3dde8 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 13 Apr 2021 16:38:50 +0200 Subject: [PATCH] Improve all day events with different timezones --- www/calendar/inner.js | 27 +++++++++++++++++++++------ www/common/outer/calendar.js | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/www/calendar/inner.js b/www/calendar/inner.js index 331785987..b6c3f5e8b 100644 --- a/www/calendar/inner.js +++ b/www/calendar/inner.js @@ -104,10 +104,6 @@ Messages.calendar_allDay = "All day"; }); }; var newEvent = function (data, cb) { - var start = data.start; - var end = data.end; - data.start = +new Date(start._date); - data.end = +new Date(end._date); APP.module.execCommand('CREATE_EVENT', data, function (obj) { if (obj && obj.error) { return void cb(obj.error); } cb(null, obj); @@ -173,6 +169,14 @@ Messages.calendar_allDay = "All day"; var obj = data.content[uid]; obj.title = obj.title || ""; obj.location = obj.location || ""; + if (obj.isAllDay && obj.startDay) { obj.start = +new Date(obj.startDay); } + if (obj.isAllDay && obj.endDay) { + var endDate = new Date(obj.endDay); + endDate.setHours(23); + endDate.setMinutes(59); + endDate.setSeconds(59); + obj.end = +endDate; + } if (c.readOnly) { obj.isReadOnly = true; } @@ -678,17 +682,28 @@ Messages.calendar_allDay = "All day"; // Use template to hide "recurrenceRule" from the detailPopup or at least to use // a non technical value + var startDate = event.start._date; + var endDate = event.end._date; + var startDay, endDay; + if (event.isAllDay) { + startDay = startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate(); + endDay = endDate.getFullYear() + '-' + (endDate.getMonth()+1) + '-' + endDate.getDate(); + } + var schedule = { id: Util.uid(), calendarId: event.calendarId, title: Util.fixHTML(event.title), category: "time", location: Util.fixHTML(event.location), - start: event.start, + start: +startDate, + startDay: startDay, isAllDay: event.isAllDay, - end: event.end, + end: +endDate, + endDay: endDay }; + newEvent(schedule, function (err) { if (err) { console.error(err); diff --git a/www/common/outer/calendar.js b/www/common/outer/calendar.js index 760a20720..d1d7732b5 100644 --- a/www/common/outer/calendar.js +++ b/www/common/outer/calendar.js @@ -624,8 +624,20 @@ ctx.calendars[channel] = { var id = data.calendarId; var c = ctx.calendars[id]; if (!c) { return void cb({error: "ENOENT"}); } + + var startDate = new Date(data.start); + var endDate = new Date(data.end); + if (data.isAllDay) { + data.startDay = startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate(); + data.endDay = endDate.getFullYear() + '-' + (endDate.getMonth()+1) + '-' + endDate.getDate(); + } else { + delete ev.startDay; + delete ev.endDay; + } + c.proxy.content = c.proxy.content || {}; c.proxy.content[data.id] = data; + Realtime.whenRealtimeSyncs(c.lm.realtime, function () { sendUpdate(ctx, c); cb(); @@ -655,6 +667,16 @@ ctx.calendars[channel] = { ev[key] = changes[key]; }); + var startDate = new Date(ev.start); + var endDate = new Date(ev.end); + if (ev.isAllDay) { + ev.startDay = startDate.getFullYear() + '-' + (startDate.getMonth()+1) + '-' + startDate.getDate(); + ev.endDay = endDate.getFullYear() + '-' + (endDate.getMonth()+1) + '-' + endDate.getDate(); + } else { + delete ev.startDay; + delete ev.endDay; + } + // Move to a different calendar? if (changes.calendarId && newC) { newC.proxy.content[data.ev.id] = Util.clone(ev);