[Xfce4-commits] <xfce4-weather-plugin:master> Fix xml_time_compare function.

Harald Judt noreply at xfce.org
Tue Dec 11 21:56:03 CET 2012


Updating branch refs/heads/master
         to 1b65eeab5dda56c5af0535989c41136aaebf688c (commit)
       from 4b69e72f96725c351fa5da435c5797dcbdc02ee3 (commit)

commit 1b65eeab5dda56c5af0535989c41136aaebf688c
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Dec 11 21:23:25 2012 +0100

    Fix xml_time_compare function.

 panel-plugin/weather-data.c |   24 ++++++++++--------------
 panel-plugin/weather-data.h |    4 ++--
 2 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index b93f6cd..e17d836 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -590,30 +590,26 @@ time_calc_day(const struct tm time_tm,
  * greater zero if first arg is greater than second arg).
  */
 gint
-xml_time_compare(gpointer a,
-                 gpointer b)
+xml_time_compare(gconstpointer a,
+                 gconstpointer b)
 {
-    xml_time *ts1 = (xml_time *) a;
-    xml_time *ts2 = (xml_time *) b;
+    xml_time *ts1 = *(xml_time **) a;
+    xml_time *ts2 = *(xml_time **) b;
     gdouble diff;
 
-    if (G_UNLIKELY(a == NULL && b == NULL))
+    if (G_UNLIKELY(ts1 == NULL && ts2 == NULL))
         return 0;
-
-    if (G_UNLIKELY(a == NULL))
+    if (G_UNLIKELY(ts1 == NULL))
         return -1;
-
-    if (G_UNLIKELY(b == NULL))
+    if (G_UNLIKELY(ts2 == NULL))
         return 1;
 
     diff = difftime(ts2->start, ts1->start);
-    if (diff > 0)
-        return -1;
-    if (diff < 0)
-        return 1;
+    if (diff != 0)
+        return (gint) (diff * -1);
 
     /* start time is equal, now it's easy to check end time ;-) */
-    return (gint) difftime(ts2->end, ts1->end);
+    return (gint) (difftime(ts2->end, ts1->end) * -1);
 }
 
 
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index 12fbb6e..be1cc2c 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -115,8 +115,8 @@ time_t time_calc_hour(struct tm time_tm,
 time_t time_calc_day(struct tm time_tm,
                      gint days);
 
-gint xml_time_compare(gpointer a,
-                      gpointer b);
+gint xml_time_compare(gconstpointer a,
+                      gconstpointer b);
 
 void merge_timeslice(xml_weather *wd,
                      const xml_time *timeslice);


More information about the Xfce4-commits mailing list