Fix bug 457536 - [Today Pane] Wrong time shown on events spanning multiple days. r=philipp
authorDecathlon <bv1578@gmail.com>
Tue, 13 Apr 2010 07:15:00 +0200
changeset 5649 282e94e8418903d37734761b7b34e9cfd02c67d6
parent 5648 ef1c30b9771442d03fba7da984a2e0ec9d76b9ac
child 5650 adfb2bf41daf99fe2f5eb14d39c408b1b766c5a0
push idunknown
push userunknown
push dateunknown
reviewersphilipp
bugs457536
Fix bug 457536 - [Today Pane] Wrong time shown on events spanning multiple days. r=philipp
calendar/base/content/agenda-listbox.js
calendar/base/content/agenda-listbox.xml
calendar/base/themes/common/images/calendar-overlay.png
calendar/base/themes/pinstripe/today-pane.css
calendar/base/themes/winstripe/today-pane.css
--- a/calendar/base/content/agenda-listbox.js
+++ b/calendar/base/content/agenda-listbox.js
@@ -305,17 +305,17 @@ function addItemBefore(aNewItem, aAgenda
     // set the item at the richlistItem. When the duration of the period
     // is bigger than 1 (day) the starttime of the item has to include
     // information about the day of the item
     if (aAgendaItem == null) {
         this.agendaListboxControl.appendChild(newelement);
     } else {
         this.agendaListboxControl.insertBefore(newelement, aAgendaItem);
     }
-    newelement.setOccurrence(aNewItem, (aPeriod.duration > 1));
+    newelement.setOccurrence(aNewItem, aPeriod);
     newelement.removeAttribute("selected");
     return newelement;
 }
 
 /**
  * Adds an item to the agenda listbox. This function finds the correct period
  * for the item and inserts it correctly so the period stays sorted.
  *
--- a/calendar/base/content/agenda-listbox.xml
+++ b/calendar/base/content/agenda-listbox.xml
@@ -120,17 +120,18 @@
   <binding id="agenda-allday-richlist-item"
            extends="chrome://calendar/content/agenda-listbox.xml#agenda-base-richlist-item">
     <content tooltip="itemTooltip">
       <xul:hbox anonid="agenda-container-box"
                 class="agenda-allday-container-box"
                 xbl:inherits="selected,disabled"
                 flex="1">
         <xul:vbox pack="center" flex="1">
-          <xul:hbox flex="1">
+          <xul:hbox flex="1" align="center">
+            <xul:image anonid="agenda-multiDayEvent-image" class="agenda-multiDayEvent-image"/>
             <xul:calendar-month-day-box-item anonid="allday-item" 
                                              flex="1"
                                              flat="true"/>
           </xul:hbox>
         </xul:vbox>
       </xul:hbox>
     </content>
     <implementation>
@@ -139,64 +140,132 @@
           this.mAllDayItem = document.getAnonymousElementByAttribute(this, "anonid", "allday-item");
       ]]></constructor>
       <method name="setOccurrence">
         <parameter name="aOccurrence"/>
         <parameter name="aPeriod"/>
         <body><![CDATA[
             this.mOccurrence = aOccurrence;
             this.mAllDayItem.occurrence = aOccurrence;
+
+            let periodStartDate = aPeriod.start.clone();
+            periodStartDate.isDate = true;
+            let periodEndDate = aPeriod.end;
+            let startDate = this.mOccurrence[calGetStartDateProp(this.mOccurrence)]
+                                .getInTimezone(calendarDefaultTimezone());
+            let endDate = this.mOccurrence[calGetEndDateProp(this.mOccurrence)]
+                              .getInTimezone(calendarDefaultTimezone());
+            let endPreviousDay = endDate.clone();
+            endPreviousDay.day--;
+
+            let iconType = "";
+            if (startDate.compare(endPreviousDay) != 0) {
+                // all day event spanning multiple days
+                if (startDate.compare(periodStartDate) >= 0 &&
+                     startDate.compare(periodEndDate) <= 0) {
+                    iconType = "start";
+                } else if (endDate.compare(periodStartDate) >= 0 &&
+                           endDate.compare(periodEndDate) <= 0) {
+                    iconType = "end";
+                } else {
+                    iconType = "continue";
+                }
+            }
+            let multiDayImage = document.getAnonymousElementByAttribute(this, "anonid", "agenda-multiDayEvent-image");
+            multiDayImage.setAttribute("type", iconType);
         ]]></body>
       </method>
     </implementation>
     <handlers>
       <handler event="draggesture" phase="capturing"><![CDATA[
         invokeEventDragSession(this.mAllDayItem.occurrence.clone(), this);
         event.stopPropagation();
         event.preventDefault();
       ]]></handler>
     </handlers>
   </binding>
 
   <binding id="agenda-richlist-item"
            extends="chrome://calendar/content/agenda-listbox.xml#agenda-base-richlist-item">
     <content tooltip="itemTooltip">
       <xul:hbox anonid="agenda-container-box" class="agenda-container-box" xbl:inherits="selected,disabled,current" flex="1">
-      <xul:hbox>
-        <xul:vbox>
-          <xul:image anonid="agenda-calendar-image" class="agenda-calendar-image"/>
-          <xul:spacer flex="1"/>
-        </xul:vbox>
-      </xul:hbox>
+        <xul:hbox>
+          <xul:vbox>
+            <xul:image anonid="agenda-calendar-image" class="agenda-calendar-image"/>
+            <xul:spacer flex="1"/>
+          </xul:vbox>
+        </xul:hbox>
         <xul:vbox anonid="agenda-description">
-          <xul:label anonid="agenda-event-start" class="agenda-event-start" crop="end" xbl:inherits="selected"/>
+          <xul:hbox align="center">
+            <xul:image anonid="agenda-multiDayEvent-image" class="agenda-multiDayEvent-image"/>
+            <xul:label anonid="agenda-event-start" class="agenda-event-start" crop="end" xbl:inherits="selected"/>
+          </xul:hbox>
           <xul:label anonid="agenda-event-title" class="agenda-event-title" crop="end" xbl:inherits="selected"/>
         </xul:vbox>
       </xul:hbox>
     </content>
     <implementation>
       <method name="setOccurrence">
         <parameter name="aItem"/>
-        <parameter name="aLongFormat"/>
+        <parameter name="aPeriod"/>
         <body><![CDATA[
             this.mOccurrence = aItem;
-            var titlebox = document.getAnonymousElementByAttribute(this, "anonid", "agenda-event-title");
+            let titlebox = document.getAnonymousElementByAttribute(this, "anonid", "agenda-event-title");
             titlebox.value = aItem.title;
-
-            var dateFormatter = Components.classes["@mozilla.org/calendar/datetime-formatter;1"]
+            let dateFormatter = Components.classes["@mozilla.org/calendar/datetime-formatter;1"]
                                   .getService(Components.interfaces.calIDateTimeFormatter);
-            var duration = "";
-            var start =  this.mOccurrence[calGetStartDateProp(this.mOccurrence)]
+
+            let periodStartDate = aPeriod.start.clone();
+            periodStartDate.isDate = true;
+            let periodEndDate = aPeriod.end.clone();
+            let start = this.mOccurrence[calGetStartDateProp(this.mOccurrence)]
                             .getInTimezone(calendarDefaultTimezone());
-            if (aLongFormat) {
-                duration = dateFormatter.formatDateTime(start);
+            let end = this.mOccurrence[calGetEndDateProp(this.mOccurrence)]
+                          .getInTimezone(calendarDefaultTimezone());
+            let startDate = start.clone();
+            startDate.isDate = true;
+            let endDate = end.clone();
+            endDate.isDate = true;
+            let endAtMidnight = (end.hour == 0 && end.minute == 0);
+            let endPreviousDay = endDate.clone();
+            endPreviousDay.day--;
+            let longFormat = aPeriod.duration > 1;
+
+            let duration = "";
+            let iconType = "";
+            if (startDate.compare(endDate) == 0 ||
+                 (startDate.compare(endPreviousDay) == 0 && endAtMidnight)) {
+                // event that starts and ends in the same day, midnight included
+                duration = longFormat ? dateFormatter.formatDateTime(start) :
+                                        dateFormatter.formatTime(start);
             } else {
-                duration = dateFormatter.formatTime(start);
+                // event spanning multiple days
+                if (startDate.compare(periodStartDate) >= 0 &&
+                     startDate.compare(periodEndDate) <= 0) {
+                    iconType = "start";
+                    duration = longFormat ? dateFormatter.formatDateTime(start) :
+                                            dateFormatter.formatTime(start);
+                } else if (endDate.compare(periodStartDate) >= 0 &&
+                           endDate.compare(periodEndDate) <= 0) {
+                    iconType = "end";
+                    if (endAtMidnight) {
+                        duration = dateFormatter.formatDate(endPreviousDay) + " ";
+                        duration = longFormat ? duration + calGetString("dateFormat", "midnight") :
+                                                calGetString("dateFormat", "midnight");
+                    } else {
+                        duration = longFormat ? dateFormatter.formatDateTime(end) :
+                                                dateFormatter.formatTime(end);
+                    }
+                } else {
+                    iconType = "continue";
+                }
             }
-            var durationbox = document.getAnonymousElementByAttribute(this, "anonid", "agenda-event-start");
+            let multiDayImage = document.getAnonymousElementByAttribute(this, "anonid", "agenda-multiDayEvent-image");
+            multiDayImage.setAttribute("type", iconType);
+            let durationbox = document.getAnonymousElementByAttribute(this, "anonid", "agenda-event-start");
             durationbox.value = duration;
             this.refreshColor();
         ]]></body>
       </method>
       <method name="refreshColor">
         <body><![CDATA[
             var calcolor = ((this.mOccurrence &&
                              this.mOccurrence.calendar.getProperty("color")) ||
index e0abeade6b15d46d4932931f562781d24980d866..af341e77dff8d303962c63eac55c9327b08e88a3
GIT binary patch
literal 441
zc$@*b0Y?6bP)<h;3K|Lk000e1NJLTq001Ze000UI1^@s6#+n>Z00001b5ch_0Itp)
z=>Px#24YJ`L;yGdH~=_mXhe<x000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2igP*
z6cq*_wVS{I00B8kL_t(I%e9m}PQ)+}g+HT+CXrYnDpuK+hK^=#uos}>07yPjB+kG=
z+@RFdtEE{fl`9H{CYFq2=ciyKD~bI)etvH<20&F`nF(Xe8-R#t3FDkIxp@)M(prp}
z&7-O>rOol0h-lyUlaUZN=hNvAKCFlN9KlQ;0IKmhc<<{1$07c(*0K<~Z(Bq}yRHME
z>pHBpx^LT99U~$?B{hSR6>tq)fSbaBml5+FHZ56FDuu*u4dg?F_f&+Psvf-ekGY|$
z2Vl3>lC8M3Y*OqMP>(j=6~-`P5RplO+}xIM&Y7T?wRYl&0Um%)@BMQwLDMwv0Tb6%
zT9<L+Ksd$*5?lZFDyRe8&Rn#PZma3RX=3M`$*G#+a&F|X#}!T-|Dy)iv@HWX0rv|8
jzkrXe4R{H+rt$v*%+m>{)#Zsv00000NkvXXu0mjft}C=V
--- a/calendar/base/themes/pinstripe/today-pane.css
+++ b/calendar/base/themes/pinstripe/today-pane.css
@@ -277,13 +277,38 @@ agenda-allday-richlist-item {
   width: 15px;
   height: 15px;
   border: 1px solid grey;
   cursor: pointer;
 }
 
 .agenda-calendar-image {
   list-style-image: url("chrome://calendar/skin/calendar-overlay.png");
+  -moz-image-region: rect(0px 10px 10px 0px);
   margin-top: 3px;
   -moz-margin-start: 4px;
   width: 10px;
   height: 10px;
 }
+
+.agenda-multiDayEvent-image {
+  list-style-image: url("chrome://calendar/skin/calendar-overlay.png");
+  -moz-margin-start: 3px;
+  width: 10px;
+  height: 10px;
+  display: none;
+}
+
+.agenda-multiDayEvent-image[type="start"] {
+  -moz-image-region: rect(0px 20px 10px 10px);
+  display: -moz-box;
+}
+
+.agenda-multiDayEvent-image[type="continue"] {
+  -moz-image-region: rect(0px 30px 10px 20px);
+  display: -moz-box;
+}
+
+.agenda-multiDayEvent-image[type="end"] {
+  -moz-image-region: rect(0px 40px 10px 30px);
+  display: -moz-box;
+}
+
--- a/calendar/base/themes/winstripe/today-pane.css
+++ b/calendar/base/themes/winstripe/today-pane.css
@@ -282,13 +282,37 @@ agenda-allday-richlist-item {
   width: 15px;
   height: 15px;
   border: 1px solid grey;
   cursor: pointer;
 }
 
 .agenda-calendar-image {
   list-style-image: url("chrome://calendar/skin/calendar-overlay.png");
+  -moz-image-region: rect(0px 10px 10px 0px);
   margin-top: 3px;
   -moz-margin-start: 4px;
   width: 10px;
   height: 10px;
 }
+
+.agenda-multiDayEvent-image {
+  list-style-image: url("chrome://calendar/skin/calendar-overlay.png");
+  -moz-margin-start: 3px;
+  width: 10px;
+  height: 10px;
+  display: none;
+}
+
+.agenda-multiDayEvent-image[type="start"] {
+  -moz-image-region: rect(0px 20px 10px 10px);
+  display: -moz-box;
+}
+
+.agenda-multiDayEvent-image[type="continue"] {
+  -moz-image-region: rect(0px 30px 10px 20px);
+  display: -moz-box;
+}
+
+.agenda-multiDayEvent-image[type="end"] {
+  -moz-image-region: rect(0px 40px 10px 30px);
+  display: -moz-box;
+}