[gnome-calendar/gbsneto/event-editor: 11/16] utils: Use GDate to compare dates



commit 1114b74ef30abbb0eef3cfac5bd15ac9d9eb16d4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Nov 14 15:27:40 2019 -0300

    utils: Use GDate to compare dates

 src/utils/gcal-date-time-utils.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/src/utils/gcal-date-time-utils.c b/src/utils/gcal-date-time-utils.c
index 11dcb5a8..48da114c 100644
--- a/src/utils/gcal-date-time-utils.c
+++ b/src/utils/gcal-date-time-utils.c
@@ -129,6 +129,8 @@ gint
 gcal_date_time_compare_date (GDateTime *dt1,
                              GDateTime *dt2)
 {
+  GDate d1, d2;
+
   if (!dt1 && !dt2)
     return 0;
   else if (!dt1)
@@ -136,16 +138,17 @@ gcal_date_time_compare_date (GDateTime *dt1,
   else if (!dt2)
     return 1;
 
-  if (g_date_time_get_year (dt1) != g_date_time_get_year (dt2))
-    return (g_date_time_get_year (dt1) - g_date_time_get_year (dt2)) * 360;
-
-  if (g_date_time_get_month (dt1) != g_date_time_get_month (dt2))
-    return (g_date_time_get_month (dt1) - g_date_time_get_month (dt2)) * 30;
+  g_date_set_dmy (&d1,
+                  g_date_time_get_day_of_month (dt1),
+                  g_date_time_get_month (dt1),
+                  g_date_time_get_year (dt1));
 
-  if (g_date_time_get_day_of_month (dt1) != g_date_time_get_day_of_month (dt2))
-    return g_date_time_get_day_of_month (dt1) - g_date_time_get_day_of_month (dt2);
+  g_date_set_dmy (&d2,
+                  g_date_time_get_day_of_month (dt2),
+                  g_date_time_get_month (dt2),
+                  g_date_time_get_year (dt2));
 
-  return 0;
+  return g_date_days_between (&d1, &d2);
 }
 
 /**


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