diff --git a/www/calendar/inner.js b/www/calendar/inner.js index 93a7893ef..36cfad6c1 100644 --- a/www/calendar/inner.js +++ b/www/calendar/inner.js @@ -114,10 +114,6 @@ Messages.calendar_noNotification = "None"; }); }; 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); @@ -183,6 +179,14 @@ Messages.calendar_noNotification = "None"; 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; } @@ -695,16 +699,19 @@ Messages.calendar_noNotification = "None"; // a non technical value var reminders = APP.notificationsEntries; + var startDate = event.start._date; + var endDate = event.end._date; + 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, isAllDay: event.isAllDay, - end: event.end, - reminders: reminders + end: +endDate, + reminders: reminders, }; newEvent(schedule, function (err) { diff --git a/www/common/outer/calendar.js b/www/common/outer/calendar.js index 88ea20766..41fdc40bc 100644 --- a/www/common/outer/calendar.js +++ b/www/common/outer/calendar.js @@ -690,8 +690,20 @@ define([ 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 () { addReminders(ctx, id, data); sendUpdate(ctx, c); @@ -722,6 +734,15 @@ define([ 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) {