[gnome-calendar] utils: added date comparison method



commit f2d84231a418236d33c30a798949dc5b07e3e68c
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Tue Jan 27 17:42:16 2015 -0500

    utils: added date comparison method
    
    icaltime_compare_date_only() has some problems when one of the dates
    passed are marked as is_date and the other not.

 src/gcal-utils.c |   24 ++++++++++++++++++++++++
 src/gcal-utils.h |    3 +++
 2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-utils.c b/src/gcal-utils.c
index 849454f..40779b0 100644
--- a/src/gcal-utils.c
+++ b/src/gcal-utils.c
@@ -503,6 +503,30 @@ build_component_from_details (const gchar        *summary,
   return event;
 }
 
+/**
+ * icaltime_compare_date:
+ * @date1:
+ * @date2:
+ *
+ * Compare date parts of { link icaltimetype} objects. Return negative value, 0 or positive value
+ * accordingly if date1 is before, same day of after date2.
+ * As a bonus it returns the amount of days passed between two days on the same year.
+ *
+ * Returns: negative, 0 or positive
+ **/
+gint
+icaltime_compare_date (const icaltimetype *date1,
+                       const icaltimetype *date2)
+{
+  if (date1->year < date2->year)
+    return -1;
+  else if (date1->year > date2->year)
+    return 1;
+  else
+    return time_day_of_year (date1->day, date1->month - 1, date1->year) -
+           time_day_of_year (date2->day, date2->month - 1, date2->year);
+}
+
 /* Function to do a last minute fixup of the AM/PM stuff if the locale
  * and gettext haven't done it right. Most English speaking countries
  * except the USA use the 24 hour clock (UK, Australia etc). However
diff --git a/src/gcal-utils.h b/src/gcal-utils.h
index ad4c7a4..5042a3f 100644
--- a/src/gcal-utils.h
+++ b/src/gcal-utils.h
@@ -90,6 +90,9 @@ ECalComponent*  build_component_from_details                    (const gchar
                                                                  const icaltimetype    *initial_date,
                                                                  const icaltimetype    *final_date);
 
+gint            icaltime_compare_date                           (const icaltimetype    *date1,
+                                                                 const icaltimetype    *date2);
+
 /* code brought from evolution */
 gsize           e_strftime_fix_am_pm                            (gchar                 *str,
                                                                  gsize                  max,


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