diff --git a/calendar/base/public/calIItemBase.idl b/calendar/base/public/calIItemBase.idl index 1da1482ac4d..0efb6365748 100644 --- a/calendar/base/public/calIItemBase.idl +++ b/calendar/base/public/calIItemBase.idl @@ -168,7 +168,7 @@ interface calIItemBase : nsISupports */ const unsigned long ALARM_RELATED_END = 1; - // The last time this alarm was fired and acknowledged by the user + // The last time this alarm was fired and acknowledged by the user; coerced to UTC. attribute calIDateTime alarmLastAck; // diff --git a/calendar/base/src/calAlarmService.js b/calendar/base/src/calAlarmService.js index 4534824abe4..c646fe72d30 100644 --- a/calendar/base/src/calAlarmService.js +++ b/calendar/base/src/calAlarmService.js @@ -504,12 +504,6 @@ calAlarmService.prototype = { }, removeAlarm: function cas_removeAlarm(aItem) { - // If the item has no alarm start date, then it was never added so don't - // remove it. - if (!this.getAlarmDate(aItem)) { - return; - } - // make sure already fired alarms are purged out of the alarm window: this.notifyObservers("onRemoveAlarmsByItem", [aItem]); for each (var timer in this.removeTimers(aItem)) { diff --git a/calendar/base/src/calEvent.js b/calendar/base/src/calEvent.js index 8fa37c2b3fb..eb81038a255 100644 --- a/calendar/base/src/calEvent.js +++ b/calendar/base/src/calEvent.js @@ -133,7 +133,7 @@ calEvent.prototype = { { cal: "DTEND", ics: "endTime" }], set icalString(value) { - this.icalComponent = icalFromString(value); + this.icalComponent = getIcsService().parseICS(value, null); }, get icalString() { diff --git a/calendar/base/src/calItemBase.js b/calendar/base/src/calItemBase.js index 17cc099b833..5f069003607 100644 --- a/calendar/base/src/calItemBase.js +++ b/calendar/base/src/calItemBase.js @@ -173,9 +173,9 @@ calItemBase.prototype = { if (this.alarmOffset) { this.alarmOffset.makeImmutable(); - if (this.alarmLastAck) { - this.alarmLastAck.makeImmutable(); - } + } + if (this.alarmLastAck) { + this.alarmLastAck.makeImmutable(); } this.ensureNotDirty(); @@ -269,14 +269,14 @@ calItemBase.prototype = { // Clone any alarm info that exists, set it to null if it doesn't if (this.alarmOffset) { m.alarmOffset = this.alarmOffset.clone(); - if (this.alarmLastAck) { - m.alarmLastAck = this.alarmLastAck.clone(); - } else { - m.alarmLastAck = null; - } } else { m.alarmOffset = null; } + if (this.alarmLastAck) { + m.alarmLastAck = this.alarmLastAck.clone(); + } else { + m.alarmLastAck = null; + } m.alarmRelated = this.alarmRelated; return m; @@ -295,6 +295,19 @@ calItemBase.prototype = { return (this.mAlarmOffset = aValue); }, + mAlarmLastAck: null, + get alarmLastAck cib_get_alarmLastAck() { + return this.mAlarmLastAck; + }, + + set alarmLastAck cib_set_alarmLastAck(aValue) { + this.modify(); + if (aValue && !aValue.timezone.isUTC) { + aValue = aValue.getInTimezone(UTC()); + } + return (this.mAlarmLastAck = aValue); + }, + get lastModifiedTime() { this.ensureNotDirty(); return this.getProperty("LAST-MODIFIED"); @@ -625,18 +638,17 @@ calItemBase.prototype = { else this.alarmRelated = Components.interfaces.calIItemBase.ALARM_RELATED_START; - var lastAck = alarmComp.getFirstProperty("X-MOZ-LASTACK"); - if (lastAck) { - var lastAckTime = Components.classes["@mozilla.org/calendar/datetime;1"] - .createInstance(Components.interfaces.calIDateTime); - lastAckTime.icalString = lastAck.valueAsIcalString; - this.alarmLastAck = lastAckTime; - } - var email = alarmComp.getFirstProperty("X-EMAILADDRESS"); if (email) this.setProperty("alarmEmailAddress", email.value); } + + var lastAck = icalcomp.getFirstProperty("X-MOZ-LASTACK"); + if (lastAck) { + var lastAckTime = createDateTime(); + lastAckTime.icalString = lastAck.value; + this.alarmLastAck = lastAckTime; + } }, importUnpromotedProperties: function (icalcomp, promoted) { @@ -715,12 +727,6 @@ calItemBase.prototype = { alarmComp.addProperty(triggerProp); - if (this.alarmLastAck) { - var lastAck = icssvc.createIcalProperty("X-MOZ-LASTACK"); - lastAck.valueAsIcalString = this.alarmLastAck.icalString; - alarmComp.addProperty(lastAck); - } - // We don't use this, but the ics-spec requires it var descProp = icssvc.createIcalProperty("DESCRIPTION"); descProp.value = "Mozilla Alarm: "+ this.title; @@ -740,6 +746,13 @@ calItemBase.prototype = { icalcomp.addSubcomponent(alarmComp); } + + if (this.alarmLastAck) { + var lastAck = getIcsService().createIcalProperty("X-MOZ-LASTACK"); + // - should we further ensure that those are UTC or rely on calAlarmService doing so? + lastAck.value = this.alarmLastAck.icalString; + icalcomp.addProperty(lastAck); + } }, getOccurrencesBetween: function(aStartDate, aEndDate, aCount) { @@ -777,17 +790,3 @@ function makeMemberAttr(ctor, varname, dflt, attr, asProperty) ctor.prototype.__defineGetter__(attr, getter); ctor.prototype.__defineSetter__(attr, setter); } - -// -// helper functions -// - -function icalFromString(str) -{ - return getIcsService().parseICS(str, null); -} - -function icalProp(kind) -{ - return getIcsService().createIcalProperty(kind); -} diff --git a/calendar/base/src/calTodo.js b/calendar/base/src/calTodo.js index 390739d2cf5..fc47373505e 100644 --- a/calendar/base/src/calTodo.js +++ b/calendar/base/src/calTodo.js @@ -161,7 +161,7 @@ calTodo.prototype = { { cal: "COMPLETED", ics: "completedTime" }], set icalString(value) { - this.icalComponent = icalFromString(value); + this.icalComponent = getIcsService().parseICS(value, null); }, get icalString() { diff --git a/calendar/providers/storage/calStorageCalendar.js b/calendar/providers/storage/calStorageCalendar.js index 6481e524a4b..ebae5304c89 100644 --- a/calendar/providers/storage/calStorageCalendar.js +++ b/calendar/providers/storage/calStorageCalendar.js @@ -1535,10 +1535,10 @@ calStorageCalendar.prototype = { item.alarmOffset = duration; item.alarmRelated = row.alarm_related; - if (row.alarm_last_ack) { - // alarm acks are always in utc - item.alarmLastAck = newDateTime(row.alarm_last_ack, "UTC"); - } + } + if (row.alarm_last_ack) { + // alarm acks are always in utc + item.alarmLastAck = newDateTime(row.alarm_last_ack, "UTC"); } if (row.recurrence_id) @@ -1998,9 +1998,9 @@ calStorageCalendar.prototype = { if (item.alarmOffset) { ip.alarm_offset = item.alarmOffset.inSeconds; ip.alarm_related = item.alarmRelated; - if (item.alarmLastAck) { - ip.alarm_last_ack = item.alarmLastAck.nativeTime; - } + } + if (item.alarmLastAck) { + ip.alarm_last_ack = item.alarmLastAck.nativeTime; } },