Fix bug 873630 - Merge "Improve ICAL.Event time handling interface to also handle times and new properties" from upstream.,a=philipp
authorPhilipp Kewisch <mozilla@kewis.ch>
Fri, 17 May 2013 21:55:58 +0200
changeset 15541 667ebf6e2d633c0d0c77704649aed132c5678d25
parent 15540 568a50beabe994a1c418230194da334ce7346830
child 15542 7fa839f756253f8c389c1664ffe2b0995dff3767
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs873630
Fix bug 873630 - Merge "Improve ICAL.Event time handling interface to also handle times and new properties" from upstream.,a=philipp
calendar/base/modules/ical.js
--- a/calendar/base/modules/ical.js
+++ b/calendar/base/modules/ical.js
@@ -6483,43 +6483,36 @@ ICAL.Event = (function() {
      * TODO: this method handles the case where we are switching
      * from a known timezone to an implied timezone (one without TZID).
      * This does _not_ handle the case of moving between a known
      *  (by TimezoneService) timezone to an unknown timezone...
      *
      * We will not add/remove/update the VTIMEZONE subcomponents
      *  leading to invalid ICAL data...
      */
-    _setTime: function(name, value) {
-      var currentProp = this.component.getFirstProperty(name);
-      var currentValue;
-
-      if (currentProp && (currentValue = currentProp.getFirstValue())) {
-        var newTzid = value.zone.tzid;
-        var currentTzid = currentProp.getParameter('tzid');
-
-        if (currentTzid !== newTzid) {
-          /**
-           * Both the localTimezone and the utcTimezone avoid TZID.
-           * We must remove the tzid param in these cases otherwise
-           * the time is either wrong or invalid.
-           */
-          if (
-            value.zone === ICAL.Timezone.localTimezone ||
-            value.zone === ICAL.Timezone.utcTimezone
-          ) {
-            currentProp.removeParameter('tzid');
-          } else {
-            // for the case where we are switching between to timezones.
-            currentProp.setParameter('tzid', newTzid);
-          }
-        }
-      }
-
-      this._setProp(name, value);
+    _setTime: function(propName, time) {
+      var prop = this.component.getFirstProperty(propName);
+
+      if (!prop) {
+        prop = new ICAL.Property(propName);
+        this.component.addProperty(prop);
+      }
+
+      // utc and local don't get a tzid
+      if (
+        time.zone === ICAL.Timezone.localTimezone ||
+        time.zone === ICAL.Timezone.utcTimezone
+      ) {
+        // remove the tzid
+        prop.removeParameter('tzid');
+      } else {
+        prop.setParameter('tzid', time.zone.tzid);
+      }
+
+      prop.setValue(time);
     },
 
     _setProp: function(name, value) {
       this.component.updatePropertyWithValue(name, value);
     },
 
     _firstProp: function(name) {
       return this.component.getFirstPropertyValue(name);