Bug 1168536 - Events with timezone get moved on a wrong day after a drag and drop in month view r=philipp
authorDecathlon <bv1578@gmail.com>
Tue, 26 May 2015 21:30:38 +0200
changeset 17996 f836c11cd54502ef5d819ead8339bcaaac3f18e6
parent 17995 3fe65676c36b47ebd62e9c2945efa3777f90494a
child 17997 3c00ed4749ee94339abc3d9da534b5baacba74f2
push id11060
push userssitter@gmail.com
push dateSun, 31 May 2015 13:57:23 +0000
treeherdercomm-central@f836c11cd545 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs1168536
Bug 1168536 - Events with timezone get moved on a wrong day after a drag and drop in month view r=philipp
calendar/base/content/calendar-month-view.xml
--- a/calendar/base/content/calendar-month-view.xml
+++ b/calendar/base/content/calendar-month-view.xml
@@ -270,17 +270,35 @@
             delete this.mItemHash[aItem.hashId];
           }
         ]]></body>
       </method>
 
       <method name="onDropItem">
         <parameter name="aItem"/>
         <body><![CDATA[
-          return cal.moveItem(aItem, this.mDate);
+          // When item's timezone is different than the default one, the
+          // item might get moved on a day different than the drop day.
+          // Changing the drop day allows to compensate a possible difference.
+
+          // Figure out if the timezones cause a days difference.
+          let start = (aItem[calGetStartDateProp(aItem)] ||
+                       aItem[calGetEndDateProp(aItem)]).clone();
+          let dayboxDate = this.mDate.clone();
+          if (start.timezone != dayboxDate.timezone) {
+              let startInDefaultTz = start.clone().getInTimezone(dayboxDate.timezone);
+              start.isDate = true;
+              startInDefaultTz.isDate = true;
+              startInDefaultTz.timezone = start.timezone;
+              let dayDiff = start.subtractDate(startInDefaultTz);
+              // Change the day where to drop the item.
+              dayboxDate.addDuration(dayDiff);
+          }
+
+          return cal.moveItem(aItem, dayboxDate);
         ]]></body>
       </method>
 
     </implementation>
 
     <handlers>
       <handler event="mousedown"><![CDATA[
         event.stopPropagation();