[gnome-calendar] event-widget: fix compare function



commit 0dd6458ae8dc068628b4ed27f5b986e54556733f
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Mon Jan 19 15:34:45 2015 -0500

    event-widget: fix compare function

 src/gcal-event-widget.c |   50 +++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index 094a7c9..83c8d19 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -1182,24 +1182,42 @@ gcal_event_widget_compare_for_single_day (GcalEventWidget *widget1,
   GcalEventWidgetPrivate *priv1;
   GcalEventWidgetPrivate *priv2;
 
-  time_t time_s1, time_s2;
-  time_t time_e1, time_e2;
-  time_t result;
-
   priv1 = gcal_event_widget_get_instance_private (widget1);
   priv2 = gcal_event_widget_get_instance_private (widget2);
 
-  time_e1 = time_s1 = icaltime_as_timet (*(priv1->dt_start));
-  time_e2 = time_s2 = icaltime_as_timet (*(priv2->dt_start));
-
-  if (priv1->dt_end != NULL)
-    time_e1 = icaltime_as_timet (*(priv1->dt_end));
-  if (priv2->dt_end)
-    time_e2 = icaltime_as_timet (*(priv2->dt_end));
-
-  result = (time_e2 - time_s2) - (time_e1 - time_s1);
-  if (result != 0)
-    return result;
+  if (gcal_event_widget_is_multiday (widget1) && gcal_event_widget_is_multiday (widget2))
+    {
+      time_t time_s1, time_s2;
+      time_t time_e1, time_e2;
+      time_t result;
+
+      time_s1 = icaltime_as_timet (*(priv1->dt_start));
+      time_s2 = icaltime_as_timet (*(priv2->dt_start));
+      time_e1 = icaltime_as_timet (*(priv1->dt_end));
+      time_e2 = icaltime_as_timet (*(priv2->dt_end));
+
+      result = (time_e2 - time_s2) - (time_e1 - time_s1);
+      if (result != 0)
+        return result;
+      else
+        return icaltime_compare (*(priv1->dt_start), *(priv2->dt_start));
+    }
   else
-    return icaltime_compare (*(priv1->dt_start), *(priv2->dt_start));
+    {
+      if (gcal_event_widget_is_multiday (widget1))
+        return -1;
+      else if (gcal_event_widget_is_multiday (widget2))
+        return 1;
+      else
+        {
+          if (priv1->all_day && priv2->all_day)
+            return 0;
+          else if (priv1->all_day)
+            return -1;
+          else if (priv2->all_day)
+            return 1;
+          else
+            return icaltime_compare (*(priv1->dt_start), *(priv2->dt_start));
+        }
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]