[Xfce4-commits] <xfce4-weather-plugin:master> Add function for comparing xml_time structs.
Harald Judt
noreply at xfce.org
Sun Dec 9 23:44:32 CET 2012
Updating branch refs/heads/master
to 4eec4c7d19b113ecf422139ab0c5877b2df471a9 (commit)
from d3c97d0e4de01fc13c451346b5a3d5ba4f74f1b7 (commit)
commit 4eec4c7d19b113ecf422139ab0c5877b2df471a9
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Dec 9 19:25:05 2012 +0100
Add function for comparing xml_time structs.
panel-plugin/weather-data.c | 34 ++++++++++++++++++++++++++++++++++
panel-plugin/weather-data.h | 3 +++
2 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 48ed0c4..bcc7e92 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -697,6 +697,40 @@ find_shortest_timeslice(xml_weather *wd,
}
+/*
+ * Compare two xml_time structs using their start and end times,
+ * returning the result as a qsort()-style comparison function (less
+ * than zero for first arg is less than second arg, zero for equal,
+ * greater zero if first arg is greater than second arg).
+ */
+gint
+xml_time_compare(gpointer a,
+ gpointer b)
+{
+ xml_time *ts1 = (xml_time *) a;
+ xml_time *ts2 = (xml_time *) b;
+ gdouble diff;
+
+ if (G_UNLIKELY(a == NULL && b == NULL))
+ return 0;
+
+ if (G_UNLIKELY(a == NULL))
+ return -1;
+
+ if (G_UNLIKELY(b == NULL))
+ return 1;
+
+ diff = difftime(ts2->start, ts1->start);
+ if (diff > 0)
+ return -1;
+ if (diff < 0)
+ return 1;
+
+ /* start time is equal, now it's easy to check end time ;-) */
+ return (gint) difftime(ts2->end, ts1->end);
+}
+
+
xml_time *
make_current_conditions(xml_weather *wd,
time_t now_t)
diff --git a/panel-plugin/weather-data.h b/panel-plugin/weather-data.h
index 2197940..e2c4eb4 100644
--- a/panel-plugin/weather-data.h
+++ b/panel-plugin/weather-data.h
@@ -113,6 +113,9 @@ 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);
+
void merge_timeslice(xml_weather *wd,
const xml_time *timeslice);
More information about the Xfce4-commits
mailing list