Bug 909183 - calIDateTime.compare returns incorrect result with floating timezone. r=philipp, a=Paenglab
authorGeoff Lankow <geoff@darktrojan.net>
Fri, 26 Dec 2014 10:49:47 +1300
changeset 21544 202b212de64406fa3e100a27c2f6cc4c9135ec05
parent 21543 aa932bf6d9abbe6ab4856dfc07332a21beac4df3
child 21545 f0cd3c2d651892477d0f2a842352877d64558697
push id1305
push usermbanner@mozilla.com
push dateMon, 23 Feb 2015 19:48:12 +0000
treeherdercomm-beta@3ae4f13858fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp, Paenglab
bugs909183
Bug 909183 - calIDateTime.compare returns incorrect result with floating timezone. r=philipp, a=Paenglab
calendar/base/backend/icaljs/calDateTime.js
--- a/calendar/base/backend/icaljs/calDateTime.js
+++ b/calendar/base/backend/icaljs/calDateTime.js
@@ -85,23 +85,32 @@ calDateTime.prototype = {
         this.innerObject.addDuration(val);
     }),
 
     subtractDate: unwrap(ICAL.Time, function(val) {
         return new calDuration(this.innerObject.subtractDateTz(val));
     }),
 
     compare: unwrap(ICAL.Time, function(val) {
-        if (this.innerObject.isDate != val.isDate) {
+        let a = this.innerObject;
+        let b = val;
+
+        // If either this or aOther is floating, both objects are treated
+        // as floating for the comparison.
+        if (a.zone == ICAL.Timezone.localTimezone || b.zone == ICAL.Timezone.localTimezone) {
+            a = a.convertToZone(ICAL.Timezone.localTimezone);
+            b = b.convertToZone(ICAL.Timezone.localTimezone);
+        }
+
+        if (a.isDate || b.isDate) {
             // Lightning expects 20120101 and 20120101T010101 to be equal
-            tz = (this.innerObject.isDate ? val.zone : this.innerObject.zone);
-            return this.innerObject.compareDateOnlyTz(val, tz);
+            return a.compareDateOnlyTz(b, a.zone);
         } else {
             // If both are dates or date-times, then just do the normal compare
-            return this.innerObject.compare(val);
+            return a.compare(b);
         }
     }),
 
     get startOfWeek() new calDateTime(this.innerObject.startOfWeek()),
     get endOfWeek() new calDateTime(this.innerObject.endOfWeek()),
     get startOfMonth() new calDateTime(this.innerObject.startOfMonth()),
     get endOfMonth() new calDateTime(this.innerObject.endOfMonth()),
     get startOfYear() new calDateTime(this.innerObject.startOfYear()),