[gnome-calendar/wip/gbsneto/gdatetime] event-widget: use GDateTime internally



commit 59370bba3c43a5288819e71a83d690e5aec5023b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Jan 4 02:10:54 2016 -0200

    event-widget: use GDateTime internally
    
    This will probably break something, but as far as
    my (rather small, I fear) set of test show, things
    are work as expected.

 src/gcal-event-widget.c |  135 ++++++++++++++++++++++++++---------------------
 src/gcal-event-widget.h |   14 ++---
 src/gcal-month-view.c   |   68 ++++++++++++++---------
 src/gcal-year-view.c    |   93 ++++++++++++++++++++++++--------
 4 files changed, 192 insertions(+), 118 deletions(-)
---
diff --git a/src/gcal-event-widget.c b/src/gcal-event-widget.c
index de7b839..f757d6a 100644
--- a/src/gcal-event-widget.c
+++ b/src/gcal-event-widget.c
@@ -30,8 +30,8 @@ struct _GcalEventWidget
   gchar         *uuid;
   gchar         *summary;
   GdkRGBA       *color;
-  icaltimetype  *dt_start;
-  icaltimetype  *dt_end; /* could be NULL, meaning dt_end is the same as start_date */
+  GDateTime     *dt_start;
+  GDateTime     *dt_end; /* could be NULL, meaning dt_end is the same as start_date */
   gboolean       all_day;
   gboolean       has_reminders;
 
@@ -164,7 +164,7 @@ gcal_event_widget_class_init(GcalEventWidgetClass *klass)
                                    g_param_spec_boxed ("date-start",
                                                        "Date Start",
                                                        "The starting date of the event",
-                                                       ICAL_TIME_TYPE,
+                                                       G_TYPE_DATE_TIME,
                                                        G_PARAM_CONSTRUCT |
                                                        G_PARAM_READWRITE));
 
@@ -173,7 +173,7 @@ gcal_event_widget_class_init(GcalEventWidgetClass *klass)
                                    g_param_spec_boxed ("date-end",
                                                        "Date End",
                                                        "The end date of the event",
-                                                       ICAL_TIME_TYPE,
+                                                       G_TYPE_DATE_TIME,
                                                        G_PARAM_CONSTRUCT |
                                                        G_PARAM_READWRITE));
 
@@ -288,7 +288,7 @@ gcal_event_widget_set_property (GObject      *object,
       if (self->has_reminders != g_value_get_boolean (value))
         {
           self->has_reminders = g_value_get_boolean (value);
-          g_object_notify (object, "has-reminder");
+          g_object_notify (object, "has-reminders");
         }
       break;
 
@@ -343,8 +343,8 @@ gcal_event_widget_finalize (GObject *object)
   /* releasing properties */
   g_clear_pointer (&self->uuid, g_free);
   g_clear_pointer (&self->summary, g_free);
-  g_clear_pointer (&self->dt_start, g_free);
-  g_clear_pointer (&self->dt_end, g_free);
+  g_clear_pointer (&self->dt_start, g_date_time_unref);
+  g_clear_pointer (&self->dt_end, g_date_time_unref);
   g_clear_pointer (&self->color, gdk_rgba_free);
 
   G_OBJECT_CLASS (gcal_event_widget_parent_class)->finalize (object);
@@ -678,7 +678,7 @@ gcal_event_widget_new_from_data (GcalEventData *data)
   gchar *color_str, *custom_css_class;
 
   ECalComponentDateTime dt;
-  icaltimetype *date;
+  GDateTime *date;
   gboolean start_is_date, end_is_date;
 
   id = e_cal_component_get_id (data->event_component);
@@ -720,39 +720,49 @@ gcal_event_widget_new_from_data (GcalEventData *data)
 
   /* start date */
   e_cal_component_get_dtstart (event->component, &dt);
-  date = gcal_dup_icaltime (dt.value);
+  date = icaltimetype_to_datetime (dt.value);
 
-  start_is_date = date->is_date == 1;
+  start_is_date = datetime_is_date (date);
   if (!start_is_date)
     {
-      if (dt.tzid != NULL)
-        dt.value->zone = icaltimezone_get_builtin_timezone_from_tzid (dt.tzid);
-      *date = icaltime_convert_to_zone (*(dt.value),
-                                        e_cal_util_get_system_timezone ());
+      GTimeZone *tz;
+      GDateTime *tz_date;
+
+      tz = g_time_zone_new (dt.tzid);
+      tz_date = g_date_time_to_timezone (date, tz);
+
+      g_clear_pointer (&date, g_date_time_unref);
+
+      date = tz_date;
     }
 
   gcal_event_widget_set_date (event, date);
   e_cal_component_free_datetime (&dt);
-  g_free (date);
+  g_clear_pointer (&date, g_date_time_unref);
 
   /* end date */
   e_cal_component_get_dtend (event->component, &dt);
   if (dt.value != NULL)
     {
-      date = gcal_dup_icaltime (dt.value);
+      date = icaltimetype_to_datetime (dt.value);
 
-      end_is_date = date->is_date == 1;
+      end_is_date = datetime_is_date (date);
       if (!end_is_date)
         {
-          if (dt.tzid != NULL)
-            dt.value->zone = icaltimezone_get_builtin_timezone_from_tzid (dt.tzid);
-          *date = icaltime_convert_to_zone (*(dt.value),
-                                            e_cal_util_get_system_timezone ());
+          GTimeZone *tz;
+          GDateTime *tz_date;
+
+          tz = g_time_zone_new (dt.tzid);
+          tz_date = g_date_time_to_timezone (date, tz);
+
+          g_clear_pointer (&date, g_date_time_unref);
+
+          date = tz_date;
         }
 
       gcal_event_widget_set_end_date (event, date);
       e_cal_component_free_datetime (&dt);
-      g_free (date);
+      g_clear_pointer (&date, g_date_time_unref);
 
       /* set_all_day */
       gcal_event_widget_set_all_day (event, start_is_date && end_is_date);
@@ -822,13 +832,13 @@ gcal_event_widget_get_read_only (GcalEventWidget *event)
 /**
  * gcal_event_widget_set_date:
  * @event: a #GcalEventWidget
- * @date: a #icaltimetype object with the date
+ * @date: a #GDateTime object with the date
  *
  * Set the start-date of the event
  **/
 void
-gcal_event_widget_set_date (GcalEventWidget    *event,
-                            const icaltimetype *date)
+gcal_event_widget_set_date (GcalEventWidget *event,
+                            GDateTime       *date)
 {
   g_object_set (event, "date-start", date, NULL);
 }
@@ -841,10 +851,10 @@ gcal_event_widget_set_date (GcalEventWidget    *event,
  *
  * Returns: (transfer full): Release with g_free()
  **/
-icaltimetype*
+GDateTime*
 gcal_event_widget_get_date (GcalEventWidget *event)
 {
-  icaltimetype *dt;
+  GDateTime *dt;
 
   g_object_get (event, "date-start", &dt, NULL);
   return dt;
@@ -856,9 +866,9 @@ gcal_event_widget_get_date (GcalEventWidget *event)
  *
  * Return the starting date of the event.
  *
- * Returns: (Transfer none): An { link icaltimetype} instance
+ * Returns: (Transfer none): An #GDateTimeinstance
  **/
-const icaltimetype*
+GDateTime*
 gcal_event_widget_peek_start_date (GcalEventWidget *event)
 {
   g_return_val_if_fail (GCAL_IS_EVENT_WIDGET (event), NULL);
@@ -869,13 +879,13 @@ gcal_event_widget_peek_start_date (GcalEventWidget *event)
 /**
  * gcal_event_widget_set_end_date:
  * @event: a #GcalEventWidget
- * @date: a #icaltimetype object with the date
+ * @date: a #GDateTime object with the date
  *
  * Set the end date of the event
  **/
 void
-gcal_event_widget_set_end_date (GcalEventWidget    *event,
-                                const icaltimetype *date)
+gcal_event_widget_set_end_date (GcalEventWidget *event,
+                                GDateTime       *date)
 {
   g_object_set (event, "date-end", date, NULL);
 }
@@ -889,10 +899,10 @@ gcal_event_widget_set_end_date (GcalEventWidget    *event,
  *
  * Returns: (transfer full): Release with g_free()
  **/
-icaltimetype*
+GDateTime*
 gcal_event_widget_get_end_date (GcalEventWidget *event)
 {
-  icaltimetype *dt;
+  GDateTime *dt;
 
   g_object_get (event, "date-end", &dt, NULL);
   return dt;
@@ -904,9 +914,9 @@ gcal_event_widget_get_end_date (GcalEventWidget *event)
  *
  * Return the end date of the event.
  *
- * Returns: (Transfer none): An { link icaltimetype} instance
+ * Returns: (Transfer none): A #GDateTime instance
  **/
-const icaltimetype*
+GDateTime*
 gcal_event_widget_peek_end_date (GcalEventWidget *event)
 {
   g_return_val_if_fail (GCAL_IS_EVENT_WIDGET (event), NULL);
@@ -973,20 +983,31 @@ gcal_event_widget_get_all_day (GcalEventWidget *event)
 gboolean
 gcal_event_widget_is_multiday (GcalEventWidget *event)
 {
+  GDateTime *year_forward;
+  guint days_in_year;
   gint start_day_of_year, end_day_of_year;
 
   if (event->dt_end == NULL)
     return FALSE;
 
-  start_day_of_year = icaltime_day_of_year (*(event->dt_start));
-  end_day_of_year = icaltime_day_of_year (*(event->dt_end));
+  /* Calculates the number of days in the event's start date year */
+  year_forward = g_date_time_add_years (event->dt_start, 1);
+  days_in_year = g_date_time_difference (event->dt_start, year_forward) / G_TIME_SPAN_DAY;
+  g_clear_pointer (&year_forward, g_date_time_unref);
+
+  start_day_of_year = g_date_time_get_day_of_year (event->dt_start);
+  end_day_of_year = g_date_time_get_day_of_year (event->dt_end);
 
   if (event->all_day && start_day_of_year + 1 == end_day_of_year)
     return FALSE;
 
-  if (event->all_day && start_day_of_year == icaltime_days_in_year (event->dt_start->year) && 
end_day_of_year == 1 &&
-      event->dt_start->year + 1 == event->dt_end->year)
-    return FALSE;
+  if (event->all_day &&
+      start_day_of_year == days_in_year &&
+      end_day_of_year == 1 &&
+      g_date_time_get_year (event->dt_start) + 1 == g_date_time_get_year (event->dt_end))
+    {
+      return FALSE;
+    }
 
   return start_day_of_year != end_day_of_year;
 }
@@ -1078,25 +1099,25 @@ gint
 gcal_event_widget_compare_by_length (GcalEventWidget *widget1,
                                      GcalEventWidget *widget2)
 {
-  time_t time_s1, time_s2;
-  time_t time_e1, time_e2;
+  GDateTime *start1, *start2;
+  GDateTime *end1, *end2;
 
-  time_e1 = time_s1 = icaltime_as_timet (*(widget1->dt_start));
-  time_e2 = time_s2 = icaltime_as_timet (*(widget2->dt_start));
+  start1 = end1 = widget1->dt_start;
+  start2 = end2 = widget2->dt_start;
 
-  if (widget1->dt_end != NULL)
-    time_e1 = icaltime_as_timet (*(widget1->dt_end));
+  if (widget1->dt_end)
+    end1 = widget1->dt_end;
   if (widget2->dt_end)
-    time_e2 = icaltime_as_timet (*(widget2->dt_end));
+    end2 = widget2->dt_end;
 
-  return (time_e2 - time_s2) - (time_e1 - time_s1);
+  return g_date_time_difference (start2, end2) - g_date_time_difference (start1, end1);
 }
 
 gint
 gcal_event_widget_compare_by_start_date (GcalEventWidget *widget1,
                                          GcalEventWidget *widget2)
 {
-  return icaltime_compare (*(widget1->dt_start), *(widget2->dt_start));
+  return g_date_time_compare (widget1->dt_start, widget2->dt_start);
 }
 
 /**
@@ -1115,20 +1136,14 @@ gcal_event_widget_compare_for_single_day (GcalEventWidget *widget1,
 {
   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;
+      gint result;
 
-      time_s1 = icaltime_as_timet (*(widget1->dt_start));
-      time_s2 = icaltime_as_timet (*(widget2->dt_start));
-      time_e1 = icaltime_as_timet (*(widget1->dt_end));
-      time_e2 = icaltime_as_timet (*(widget2->dt_end));
+      result = gcal_event_widget_compare_by_length (widget1, widget2);
 
-      result = (time_e2 - time_s2) - (time_e1 - time_s1);
       if (result != 0)
         return result;
       else
-        return icaltime_compare (*(widget1->dt_start), *(widget2->dt_start));
+        return g_date_time_compare (widget1->dt_start, widget2->dt_start);
     }
   else
     {
@@ -1145,7 +1160,7 @@ gcal_event_widget_compare_for_single_day (GcalEventWidget *widget1,
           else if (widget2->all_day)
             return 1;
           else
-            return icaltime_compare (*(widget1->dt_start), *(widget2->dt_start));
+            return g_date_time_compare (widget1->dt_start, widget2->dt_start);
         }
     }
 }
diff --git a/src/gcal-event-widget.h b/src/gcal-event-widget.h
index 112cc2c..c0324a1 100644
--- a/src/gcal-event-widget.h
+++ b/src/gcal-event-widget.h
@@ -24,8 +24,6 @@
 
 #include <gtk/gtk.h>
 
-#include <libical/icaltime.h>
-
 G_BEGIN_DECLS
 
 
@@ -50,18 +48,18 @@ void          gcal_event_widget_set_read_only              (GcalEventWidget    *
 gboolean      gcal_event_widget_get_read_only              (GcalEventWidget    *event);
 
 void          gcal_event_widget_set_date                   (GcalEventWidget    *event,
-                                                            const icaltimetype *date);
+                                                            GDateTime          *date);
 
-icaltimetype* gcal_event_widget_get_date                   (GcalEventWidget    *event);
+GDateTime*    gcal_event_widget_get_date                   (GcalEventWidget    *event);
 
-const icaltimetype* gcal_event_widget_peek_start_date            (GcalEventWidget    *event);
+GDateTime*    gcal_event_widget_peek_start_date            (GcalEventWidget    *event);
 
 void          gcal_event_widget_set_end_date               (GcalEventWidget    *event,
-                                                            const icaltimetype *date);
+                                                            GDateTime          *date);
 
-icaltimetype* gcal_event_widget_get_end_date               (GcalEventWidget    *event);
+GDateTime*    gcal_event_widget_get_end_date               (GcalEventWidget    *event);
 
-const icaltimetype* gcal_event_widget_peek_end_date              (GcalEventWidget    *event);
+GDateTime*    gcal_event_widget_peek_end_date              (GcalEventWidget    *event);
 
 void          gcal_event_widget_set_summary                (GcalEventWidget    *event,
                                                             gchar              *summary);
diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c
index 299326d..083d4a4 100644
--- a/src/gcal-month-view.c
+++ b/src/gcal-month-view.c
@@ -476,8 +476,8 @@ rebuild_popover_for_day (GcalMonthView *view,
 
   gchar *label_title;
 
-  icaltimetype date, second_date;
-  const icaltimetype *dt_start, *dt_end;
+  GDateTime *date, *second_date;
+  GDateTime *dt_start, *dt_end;
   gint start_comparison, end_comparison;
 
   /* placement helpers */
@@ -495,6 +495,7 @@ rebuild_popover_for_day (GcalMonthView *view,
 
   priv = gcal_month_view_get_instance_private (view);
   ppriv = GCAL_SUBSCRIBER_VIEW (view)->priv;
+  date = second_date = NULL;
 
   label_title = g_strdup_printf ("%s %d", gcal_get_month_name (priv->date->month - 1), day);
   gtk_label_set_text (GTK_LABEL (priv->popover_title), label_title);
@@ -506,15 +507,23 @@ rebuild_popover_for_day (GcalMonthView *view,
   l = g_hash_table_lookup (ppriv->overflow_cells, GINT_TO_POINTER (priv->pressed_overflow_indicator));
   if (l != NULL)
     {
-      date = *(priv->date);
-      date.day = day;
-
-      second_date = date;
-
-      date.hour = 0;
-      date.minute = 0;
-      second_date.hour = 23;
-      second_date.minute =59;
+      icaltimetype dt;
+
+      dt = *(priv->date);
+
+      date = g_date_time_new_local (dt.year,
+                                    dt.month,
+                                    day,
+                                    0,
+                                    0,
+                                    0);
+
+      second_date = g_date_time_new_local (dt.year,
+                                           dt.month,
+                                           day,
+                                           23,
+                                           59,
+                                           59);
     }
   for (; l != NULL; l = g_list_next (l))
     {
@@ -525,9 +534,9 @@ rebuild_popover_for_day (GcalMonthView *view,
       dt_start = gcal_event_widget_peek_start_date (GCAL_EVENT_WIDGET (child_widget));
       dt_end = gcal_event_widget_peek_end_date (GCAL_EVENT_WIDGET (child_widget));
 
-      date.is_date = dt_start->is_date;
-      start_comparison = icaltime_compare (*dt_start, date);
-      end_comparison = icaltime_compare (second_date, *dt_end);
+      start_comparison = g_date_time_compare (dt_start, date);
+      end_comparison = g_date_time_compare (second_date, dt_end);
+
       if (start_comparison == -1 && end_comparison == -1)
         gtk_style_context_add_class (gtk_widget_get_style_context (child_widget), "slanted");
       else if (start_comparison == -1)
@@ -584,6 +593,9 @@ rebuild_popover_for_day (GcalMonthView *view,
   gtk_widget_set_size_request (child_widget, 200, -1);
 
   g_object_set_data (G_OBJECT (priv->overflow_popover), "selected-day", GINT_TO_POINTER (day));
+
+  g_clear_pointer (&second_date, g_date_time_unref);
+  g_clear_pointer (&date, g_date_time_unref);
 }
 
 static void
@@ -605,11 +617,14 @@ update_list_box_headers (GtkListBoxRow *row,
 {
   GcalMonthViewPrivate *priv;
   GtkWidget *row_child, *before_child = NULL;
-  const icaltimetype *row_date, *before_date = NULL;
+  GDateTime *row_date, *before_date = NULL;
+  gint row_date_hour;
 
   priv = gcal_month_view_get_instance_private (GCAL_MONTH_VIEW (user_data));
   row_child = gtk_bin_get_child (GTK_BIN (row));
   row_date = gcal_event_widget_peek_start_date (GCAL_EVENT_WIDGET (row_child));
+  row_date_hour = g_date_time_get_hour (row_date);
+
   if (before != NULL)
     {
       before_child = gtk_bin_get_child (GTK_BIN (before));
@@ -618,15 +633,15 @@ update_list_box_headers (GtkListBoxRow *row,
 
   if (!gcal_event_widget_is_multiday (GCAL_EVENT_WIDGET (row_child)) &&
       !gcal_event_widget_get_all_day (GCAL_EVENT_WIDGET (row_child)) &&
-      (before_date == NULL || before_date->hour != row_date->hour))
+      (before_date == NULL || g_date_time_get_hour (before_date) != row_date_hour))
     {
       gchar *time;
       GtkWidget *label, *vbox;
 
       if (priv->use_24h_format)
-        time = g_strdup_printf ("%.2d:00", row_date->hour);
+        time = g_strdup_printf ("%.2d:00", row_date_hour);
       else
-        time = g_strdup_printf ("%.2d:00 %s", row_date->hour % 12, row_date->hour < 12 ? "AM" : "PM");
+        time = g_strdup_printf ("%.2d:00 %s", row_date_hour % 12, row_date_hour < 12 ? "AM" : "PM");
 
       label = gtk_label_new (time);
       gtk_style_context_add_class (gtk_widget_get_style_context (label), GTK_STYLE_CLASS_DIM_LABEL);
@@ -1064,7 +1079,7 @@ gcal_month_view_size_allocate (GtkWidget     *widget,
       gint first_cell, last_cell, first_row, last_row, start, end;
       gboolean visible, start_before = TRUE, end_after = TRUE;
 
-      const icaltimetype *date;
+      GDateTime *date;
       GArray *cells, *lengths;
 
       child_widget = (GtkWidget*) l->data;
@@ -1077,9 +1092,9 @@ gcal_month_view_size_allocate (GtkWidget     *widget,
 
       j = 1;
       date = gcal_event_widget_peek_start_date (GCAL_EVENT_WIDGET (child_widget));
-      if (date->month == priv->date->month)
+      if (g_date_time_get_month (date) == priv->date->month)
         {
-          j = date->day;
+          j = g_date_time_get_day_of_month (date);
           start_before = FALSE;
         }
       j += priv->days_delay;
@@ -1089,17 +1104,17 @@ gcal_month_view_size_allocate (GtkWidget     *widget,
       date = gcal_event_widget_peek_end_date (GCAL_EVENT_WIDGET (child_widget));
       if (gcal_event_widget_get_all_day (GCAL_EVENT_WIDGET (child_widget)))
         {
-          if (date->month == priv->date->month)
+          if (g_date_time_get_month (date) == priv->date->month)
             {
-              j = date->day - 1;
+              j = g_date_time_get_day_of_month (date) - 1;
               end_after = FALSE;
             }
         }
       else
         {
-          if (date->month == priv->date->month)
+          if (g_date_time_get_month (date) == priv->date->month)
             {
-              j = date->day;
+              j = g_date_time_get_day_of_month (date);
               end_after = FALSE;
             }
         }
@@ -1794,8 +1809,7 @@ static guint
 gcal_month_view_get_child_cell (GcalSubscriberView *subscriber,
                                 GcalEventWidget    *child)
 {
-  const icaltimetype *dt_start = gcal_event_widget_peek_start_date (child);
-  return dt_start->day;
+  return g_date_time_get_day_of_month (gcal_event_widget_peek_start_date (child));
 }
 
 static void
diff --git a/src/gcal-year-view.c b/src/gcal-year-view.c
index 695ca79..0646d5e 100644
--- a/src/gcal-year-view.c
+++ b/src/gcal-year-view.c
@@ -24,6 +24,7 @@
 #include <glib/gi18n.h>
 #include <math.h>
 #include <string.h>
+#include <libical/icaltime.h>
 
 #define NAVIGATOR_CELL_WIDTH (210 + 15)
 #define NAVIGATOR_CELL_HEIGHT 210
@@ -205,6 +206,7 @@ static void
 update_no_events_page (GcalYearView *year_view)
 {
   GcalYearViewPrivate *priv;
+  GDateTime *current_date, *start_selected_date;
 
   gchar *title;
   gboolean has_range;
@@ -213,7 +215,10 @@ update_no_events_page (GcalYearView *year_view)
   has_range = (priv->start_selected_date->day != priv->end_selected_date->day ||
                priv->start_selected_date->month != priv->end_selected_date->month);
 
-  if (icaltime_compare_date (priv->current_date, priv->start_selected_date) == 0)
+  current_date = icaltimetype_to_datetime (priv->current_date);
+  start_selected_date = icaltimetype_to_datetime (priv->start_selected_date);
+
+  if (datetime_compare_date (current_date, start_selected_date) == 0)
     {
       title = g_strdup_printf ("%s%s", _("Today"), has_range ? "…" : "");
     }
@@ -226,6 +231,8 @@ update_no_events_page (GcalYearView *year_view)
     }
 
   gtk_label_set_text (GTK_LABEL (priv->no_events_title), title);
+  g_clear_pointer (&start_selected_date, g_date_time_unref);
+  g_clear_pointer (&current_date, g_date_time_unref);
   g_free (title);
 }
 
@@ -238,8 +245,8 @@ add_event_to_day_array (GcalYearView  *year_view,
   GcalYearViewPrivate *priv;
   GtkWidget *child_widget;
 
-  const icaltimetype *dt_start, *dt_end;
-  icaltimetype date, second_date;
+  GDateTime *dt_start, *dt_end;
+  GDateTime *date, *second_date;
 
   gint i;
   gboolean child_widget_used = FALSE;
@@ -253,10 +260,13 @@ add_event_to_day_array (GcalYearView  *year_view,
   dt_end = gcal_event_widget_peek_end_date (GCAL_EVENT_WIDGET (child_widget));
 
   /* normalize date on each new event */
-  date = *(priv->start_selected_date);
-  second_date = *(priv->start_selected_date);
-  second_date.hour = 23;
-  second_date.minute = 59;
+  date = icaltimetype_to_datetime (priv->start_selected_date);
+  second_date = g_date_time_new_local (g_date_time_get_year (date),
+                                       g_date_time_get_month (date),
+                                       g_date_time_get_day_of_month (date),
+                                       23,
+                                       59,
+                                       0);
 
   /* marking and cloning */
   for (i = 0; i < days_span; i++)
@@ -266,11 +276,22 @@ add_event_to_day_array (GcalYearView  *year_view,
 
       if (i != 0)
         {
-          icaltime_adjust (&date, 1, 0, 0, 0);
-          icaltime_adjust (&second_date, 1, 0, 0, 0);
+          GDateTime *new_date;
+
+          /* Increase date */
+          new_date = g_date_time_add_days (date, 1);
+          g_clear_pointer (&date, g_date_time_unref);
+
+          date = new_date;
+
+          /* Increase second_date */
+          new_date = g_date_time_add_days (second_date, 1);
+          g_clear_pointer (&second_date, g_date_time_unref);
+
+          second_date = new_date;
         }
 
-      start_comparison = icaltime_compare_date (dt_start, &date);
+      start_comparison = datetime_compare_date (dt_start, date);
       if (start_comparison <= 0)
         {
           if (child_widget_used)
@@ -289,10 +310,14 @@ add_event_to_day_array (GcalYearView  *year_view,
                                                         cloned_child,
                                                         (GCompareFunc) 
gcal_event_widget_compare_for_single_day);
 
-          end_comparison = icaltime_compare_date (&second_date, dt_end);
+          end_comparison = datetime_compare_date (second_date, dt_end);
           /* XXX: hack ensuring allday events with end_date a day after */
-          if (end_comparison == -1 && second_date.year == dt_end->year && dt_end->is_date == 1)
-            end_comparison = 0;
+          if (end_comparison == -1 &&
+              g_date_time_get_year (second_date) == g_date_time_get_year (dt_end) &&
+              datetime_is_date (dt_end))
+            {
+              end_comparison = 0;
+            }
 
           if (start_comparison < 0 && end_comparison < 0)
             gtk_style_context_add_class (gtk_widget_get_style_context (cloned_child), "slanted");
@@ -305,6 +330,9 @@ add_event_to_day_array (GcalYearView  *year_view,
             break;
         }
     }
+
+  g_clear_pointer (&second_date, g_date_time_unref);
+  g_clear_pointer (&date, g_date_time_unref);
 }
 
 static void
@@ -374,8 +402,8 @@ update_sidebar_headers (GtkListBoxRow *row,
 {
   GcalYearViewPrivate *priv;
   GtkWidget *row_child, *before_child = NULL, *row_header = NULL;
-  const icaltimetype *row_date, *before_date = NULL;
-  icaltimetype date;
+  GDateTime *row_date, *before_date = NULL;
+  GDateTime *date;
   gint row_shift, before_shift =-1;
 
   priv = GCAL_YEAR_VIEW (user_data)->priv;
@@ -393,17 +421,31 @@ update_sidebar_headers (GtkListBoxRow *row,
 
   if (before_shift == -1 || before_shift != row_shift)
     {
+      GDateTime *current_date;
+      GDateTime *new_date;
       GtkWidget *label;
       gchar *label_str;
 
       row_header = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-      date = *(priv->start_selected_date);
-      icaltime_adjust (&date, row_shift, 0, 0, 0);
+      date = icaltimetype_to_datetime (priv->start_selected_date);
+      current_date = icaltimetype_to_datetime (priv->current_date);
 
-      if (icaltime_compare_date (&date, priv->current_date) == 0)
-        label_str = g_strdup (_("Today"));
+      /* Adjust date */
+      new_date = g_date_time_add_days (date, row_shift);
+      g_clear_pointer (&date, g_date_time_unref);
+
+      date = new_date;
+
+      if (datetime_compare_date (date, current_date) == 0)
+        {
+          label_str = g_strdup (_("Today"));
+        }
       else
-        label_str = g_strdup_printf ("%s %d", gcal_get_month_name (date.month  - 1), date.day);
+        {
+          label_str = g_strdup_printf ("%s %d",
+                                       gcal_get_month_name (g_date_time_get_month (date) - 1),
+                                       g_date_time_get_day_of_month (date));
+        }
 
       label = gtk_label_new (label_str);
       gtk_style_context_add_class (gtk_widget_get_style_context (label), "sidebar-header");
@@ -411,19 +453,24 @@ update_sidebar_headers (GtkListBoxRow *row,
       g_free (label_str);
 
       gtk_container_add (GTK_CONTAINER (row_header), label);
+
+      g_clear_pointer (&current_date, g_date_time_unref);
+      g_clear_pointer (&date, g_date_time_unref);
     }
 
   if (!gcal_event_widget_is_multiday (GCAL_EVENT_WIDGET (row_child)) &&
       !gcal_event_widget_get_all_day (GCAL_EVENT_WIDGET (row_child)) &&
-      (before_date == NULL || before_date->hour != row_date->hour))
+      (before_date == NULL || g_date_time_get_hour (before_date) != g_date_time_get_hour (row_date)))
     {
       gchar *time;
       GtkWidget *label;
 
       if (priv->use_24h_format)
-        time = g_strdup_printf ("%.2d:00", row_date->hour);
+        time = g_strdup_printf ("%.2d:00", g_date_time_get_hour (row_date));
       else
-        time = g_strdup_printf ("%.2d:00 %s", row_date->hour % 12, row_date->hour < 12 ? "AM" : "PM");
+        time = g_strdup_printf ("%.2d:00 %s",
+                                g_date_time_get_hour (row_date) % 12,
+                                g_date_time_get_hour (row_date) < 12 ? "AM" : "PM");
 
       label = gtk_label_new (time);
       gtk_style_context_add_class (gtk_widget_get_style_context (label), GTK_STYLE_CLASS_DIM_LABEL);


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