[gnome-calendar] view: Turn 'active-date' into a GDateTime property



commit 073fc961c1b14aaa4b40a11298d02c804b48b89b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Apr 26 13:04:37 2019 -0300

    view: Turn 'active-date' into a GDateTime property
    
    Drop the bomb!

 src/gcal-application.c       |   21 +-
 src/gcal-utils.c             | 1369 ------------------------------------------
 src/gcal-utils.h             |  140 -----
 src/gcal-window.c            |   30 +-
 src/gcal-window.h            |    2 +-
 src/views/gcal-month-view.c  |  125 ++--
 src/views/gcal-view.c        |   20 +-
 src/views/gcal-view.h        |   16 +-
 src/views/gcal-week-grid.c   |   17 +-
 src/views/gcal-week-grid.h   |    2 +-
 src/views/gcal-week-header.c |   48 +-
 src/views/gcal-week-header.h |    2 +-
 src/views/gcal-week-view.c   |   15 +-
 src/views/gcal-year-view.c   |  266 ++++----
 14 files changed, 292 insertions(+), 1781 deletions(-)
---
diff --git a/src/gcal-application.c b/src/gcal-application.c
index f099498a..559b2a85 100644
--- a/src/gcal-application.c
+++ b/src/gcal-application.c
@@ -44,7 +44,7 @@ struct _GcalApplication
   GtkCssProvider     *colors_provider;
 
   gchar              *uuid;
-  icaltimetype       *initial_date;
+  GDateTime          *initial_date;
 
   GcalShellSearchProvider *search_provider;
 
@@ -196,7 +196,7 @@ gcal_application_finalize (GObject *object)
 
   GCAL_ENTRY;
 
-  g_clear_pointer (&self->initial_date, g_free);
+  gcal_clear_datetime (&self->initial_date);
   g_clear_pointer (&self->uuid, g_free);
   g_clear_object (&self->context);
   g_clear_object (&self->colors_provider);
@@ -257,12 +257,7 @@ gcal_application_activate (GApplication *application)
   if (!self->window)
     {
       if (!self->initial_date)
-        {
-          g_autoptr (GDateTime) now = NULL;
-
-          now = g_date_time_new_now_local ();
-          self->initial_date = datetime_to_icaltime (now);
-        }
+        self->initial_date = g_date_time_new_now (gcal_context_get_timezone (self->context));
 
       self->window =  g_object_new (GCAL_TYPE_WINDOW,
                                     "application", self,
@@ -279,7 +274,7 @@ gcal_application_activate (GApplication *application)
   if (self->initial_date)
     g_object_set (self->window, "active-date", self->initial_date, NULL);
 
-  g_clear_pointer (&self->initial_date, g_free);
+  gcal_clear_datetime (&self->initial_date);
 
   if (self->uuid != NULL)
     {
@@ -369,10 +364,7 @@ gcal_application_command_line (GApplication            *app,
                                           result.tm_min,
                                           0);
 
-          g_clear_pointer (&self->initial_date, g_free);
-
-          if (initial_date)
-            self->initial_date = datetime_to_icaltime (initial_date);
+          gcal_set_date_time (&self->initial_date, initial_date);
         }
       else
         {
@@ -663,6 +655,5 @@ gcal_application_set_initial_date (GcalApplication *self,
 {
   g_return_if_fail (GCAL_IS_APPLICATION (self));
 
-  g_clear_pointer (&self->initial_date, g_free);
-  self->initial_date = datetime_to_icaltime (initial_date);
+  gcal_set_date_time (&self->initial_date, initial_date);
 }
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 3f10f69a..d269ee3c 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -290,7 +290,6 @@ update_active_date (GcalWindow *window,
                     GDateTime  *new_date)
 {
   g_autoptr (GDateTime) previous_date = NULL;
-  g_autofree icaltimetype *new_icaldate = NULL;
   g_autofree gchar *new_date_string = NULL;
   GcalManager *manager;
   GDateTime *date_start, *date_end;
@@ -300,16 +299,15 @@ update_active_date (GcalWindow *window,
   GCAL_ENTRY;
 
   previous_date = window->active_date;
-  window->active_date = new_date;
+  window->active_date = g_date_time_ref (new_date);
   manager = gcal_context_get_manager (window->context);
 
   new_date_string = g_date_time_format (new_date, "%x %X %z");
   g_debug ("Updating active date to %s", new_date_string);
 
-  new_icaldate = datetime_to_icaltime (new_date);
-  gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_WEEK]), new_icaldate);
-  gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_MONTH]), new_icaldate);
-  gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_YEAR]), new_icaldate);
+  gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_WEEK]), new_date);
+  gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_MONTH]), new_date);
+  gcal_view_set_date (GCAL_VIEW (window->views[GCAL_WINDOW_VIEW_YEAR]), new_date);
 
   /* year_view */
   if (g_date_time_get_year (previous_date) != g_date_time_get_year (new_date))
@@ -367,10 +365,10 @@ update_active_date (GcalWindow *window,
       !g_date_valid (&old_week) ||
       g_date_get_iso8601_week_of_year (&old_week) != g_date_get_iso8601_week_of_year (&new_week))
     {
-      date_start = get_start_of_week (new_icaldate);
+      date_start = gcal_date_time_get_start_of_week (new_date);
       range_start = g_date_time_to_unix (date_start);
 
-      date_end = get_end_of_week (new_icaldate);
+      date_end = gcal_date_time_get_end_of_week (new_date);
       range_end = g_date_time_to_unix (date_end);
 
       gcal_manager_set_subscriber (manager, E_CAL_DATA_MODEL_SUBSCRIBER (window->week_view), range_start, 
range_end);
@@ -633,8 +631,8 @@ set_new_event_mode (GcalWindow *window,
 /* new-event interaction: second variant */
 static void
 show_new_event_widget (GcalView   *view,
-                       gpointer    start_span,
-                       gpointer    end_span,
+                       GDateTime  *start_span,
+                       GDateTime  *end_span,
                        gdouble     x,
                        gdouble     y,
                        GcalWindow *window)
@@ -1234,7 +1232,7 @@ gcal_window_finalize (GObject *object)
   g_clear_object (&window->context);
   g_clear_object (&window->views_switcher);
 
-  g_clear_pointer (&window->active_date, g_free);
+  gcal_clear_datetime (&window->active_date);
 
   G_OBJECT_CLASS (gcal_window_parent_class)->finalize (object);
 
@@ -1290,7 +1288,7 @@ gcal_window_set_property (GObject      *object,
       break;
 
     case PROP_ACTIVE_DATE:
-      update_active_date (GCAL_WINDOW (object), icaltime_to_datetime (g_value_get_boxed (value)));
+      update_active_date (GCAL_WINDOW (object), g_value_get_boxed (value));
       break;
 
     case PROP_NEW_EVENT_MODE:
@@ -1349,7 +1347,7 @@ gcal_window_get_property (GObject    *object,
   switch (property_id)
     {
     case PROP_ACTIVE_DATE:
-      g_value_take_boxed (value, datetime_to_icaltime (self->active_date));
+      g_value_set_boxed (value, self->active_date);
       break;
 
     case PROP_ACTIVE_VIEW:
@@ -1420,7 +1418,7 @@ gcal_window_class_init (GcalWindowClass *klass)
   properties[PROP_ACTIVE_DATE] = g_param_spec_boxed ("active-date",
                                                      "Date",
                                                      "The active/selected date",
-                                                     ICAL_TIME_TYPE,
+                                                     G_TYPE_DATE_TIME,
                                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
   properties[PROP_ACTIVE_VIEW] = g_param_spec_enum ("active-view",
@@ -1529,7 +1527,7 @@ gcal_window_init (GcalWindow *self)
                               self,
                               NULL);
 
-  self->active_date = g_date_time_new_now_local ();
+  self->active_date = g_date_time_new_from_unix_local (0);
   self->rtl = gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL;
 
   /* setup accels */
@@ -1554,7 +1552,7 @@ gcal_window_init (GcalWindow *self)
  */
 GtkWidget*
 gcal_window_new_with_date (GcalApplication *app,
-                           icaltimetype    *date)
+                           GDateTime       *date)
 {
   return g_object_new (GCAL_TYPE_WINDOW,
                        "application", GTK_APPLICATION (app),
diff --git a/src/gcal-window.h b/src/gcal-window.h
index 8b7c55f9..4df9faa5 100644
--- a/src/gcal-window.h
+++ b/src/gcal-window.h
@@ -33,7 +33,7 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GcalWindow, gcal_window, GCAL, WINDOW, GtkApplicationWindow)
 
 GtkWidget*           gcal_window_new_with_date                  (GcalApplication     *app,
-                                                                 icaltimetype        *date);
+                                                                 GDateTime           *date);
 
 void                 gcal_window_set_search_mode                (GcalWindow          *self,
                                                                  gboolean             enabled);
diff --git a/src/views/gcal-month-view.c b/src/views/gcal-month-view.c
index 72168f49..e4a51fe7 100644
--- a/src/views/gcal-month-view.c
+++ b/src/views/gcal-month-view.c
@@ -119,7 +119,7 @@ struct _GcalMonthView
   guint               update_grid_id;
 
   /* property */
-  icaltimetype       *date;
+  GDateTime          *date;
   GcalContext        *context;
 
   gboolean            pending_event_allocation;
@@ -308,8 +308,8 @@ calculate_event_cells (GcalMonthView *self,
       start_date = gcal_event_get_date_start (event);
       start_date = all_day ? g_date_time_ref (start_date) : g_date_time_to_local (start_date);
 
-      if (g_date_time_get_year (start_date) == self->date->year &&
-          g_date_time_get_month (start_date) == self->date->month)
+      if (g_date_time_get_year (start_date) == g_date_time_get_year (self->date) &&
+          g_date_time_get_month (start_date) == g_date_time_get_month (self->date))
         {
           first_cell = g_date_time_get_day_of_month (start_date);
         }
@@ -328,12 +328,12 @@ calculate_event_cells (GcalMonthView *self,
       g_autoptr (GDateTime) end_date = NULL;
       gint last_cell;
 
-      last_cell = icaltime_days_in_month (self->date->month, self->date->year);
+      last_cell = gcal_date_time_get_days_in_month (self->date);
       end_date = gcal_event_get_date_end (event);
       end_date = all_day ? g_date_time_ref (end_date) : g_date_time_to_local (end_date);
 
-      if (g_date_time_get_year (end_date) == self->date->year &&
-          g_date_time_get_month (end_date) == self->date->month)
+      if (g_date_time_get_year (end_date) == g_date_time_get_year (self->date) &&
+          g_date_time_get_month (end_date) == g_date_time_get_month (self->date))
         {
           last_cell = g_date_time_get_day_of_month (end_date);
 
@@ -686,8 +686,8 @@ allocate_multiday_events (GcalMonthView *self,
            * some checks and only applies the dates when it's valid.
            */
           dt_start = g_date_time_new (g_date_time_get_timezone (gcal_event_get_date_start (event)),
-                                      self->date->year,
-                                      self->date->month,
+                                      g_date_time_get_year (self->date),
+                                      g_date_time_get_month (self->date),
                                       day,
                                       0, 0, 0);
 
@@ -931,12 +931,14 @@ update_weather (GcalMonthView *self,
 static gboolean
 update_month_cells (GcalMonthView *self)
 {
-  g_autoptr (GDateTime) dt;
+  g_autoptr (GDateTime) dt = NULL;
   gboolean show_last_row;
   guint row, col;
 
-  show_last_row = g_date_get_days_in_month (self->date->month, self->date->year) + self->days_delay > 35;
-  dt = g_date_time_new_local (self->date->year, self->date->month, 1, 0, 0, 0);
+  show_last_row = gcal_date_time_get_days_in_month (self->date) + self->days_delay > 35;
+  dt = g_date_time_new_local (g_date_time_get_year (self->date),
+                              g_date_time_get_month (self->date),
+                              1, 0, 0, 0);
 
   for (row = 0; row < 6; row++)
     {
@@ -963,7 +965,7 @@ update_month_cells (GcalMonthView *self)
 
           /* Different month */
           different_month = day < self->days_delay ||
-                            day - self->days_delay >= icaltime_days_in_month (self->date->month, 
self->date->year);
+                            day - self->days_delay >= gcal_date_time_get_days_in_month (self->date);
 
           gcal_month_cell_set_different_month (cell, different_month);
 
@@ -1029,9 +1031,9 @@ update_header_labels (GcalMonthView *self)
 {
   gchar year_str[10] = { 0, };
 
-  g_snprintf (year_str, 10, "%d", self->date->year);
+  g_snprintf (year_str, 10, "%d", g_date_time_get_year (self->date));
 
-  gtk_label_set_label (GTK_LABEL (self->month_label), gcal_get_month_name (self->date->month - 1));
+  gtk_label_set_label (GTK_LABEL (self->month_label), gcal_get_month_name (g_date_time_get_month 
(self->date) - 1));
   gtk_label_set_label (GTK_LABEL (self->year_label), year_str);
 }
 
@@ -1068,7 +1070,9 @@ add_new_event_button_cb (GtkWidget *button,
   gcal_month_popover_popdown (self->overflow_popover);
 
   day = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (self->overflow_popover), "selected-day"));
-  start_date = g_date_time_new_local (self->date->year, self->date->month, day, 0, 0, 0);
+  start_date = g_date_time_new_local (g_date_time_get_year (self->date),
+                                      g_date_time_get_month (self->date),
+                                      day, 0, 0, 0);
 
   g_signal_emit_by_name (GCAL_VIEW (user_data), "create-event-detailed", start_date, NULL);
 
@@ -1127,7 +1131,7 @@ on_weather_service_weather_changed_cb (GcalWeatherService *weather_service,
  * GcalView interface
  */
 
-static icaltimetype*
+static GDateTime*
 gcal_month_view_get_date (GcalView *view)
 {
   GcalMonthView *self = GCAL_MONTH_VIEW (view);
@@ -1136,22 +1140,23 @@ gcal_month_view_get_date (GcalView *view)
 }
 
 static void
-gcal_month_view_set_date (GcalView     *view,
-                          icaltimetype *date)
+gcal_month_view_set_date (GcalView  *view,
+                          GDateTime *date)
 {
+  g_autofree gchar *new_date_string = NULL;
   GcalMonthView *self;
 
   GCAL_ENTRY;
 
   self = GCAL_MONTH_VIEW (view);
 
-  g_clear_pointer (&self->date, g_free);
+  gcal_set_date_time (&self->date, date);
 
-  self->date = gcal_dup_icaltime (date);
-  self->days_delay = (time_day_of_week (1, self->date->month - 1, self->date->year) - self->first_weekday + 
7) % 7;
-  self->keyboard_cell = self->days_delay + (self->date->day - 1);
+  self->days_delay = (time_day_of_week (1, g_date_time_get_month (self->date) - 1, g_date_time_get_year 
(self->date)) - self->first_weekday + 7) % 7;
+  self->keyboard_cell = self->days_delay + (g_date_time_get_day_of_month (self->date) - 1);
 
-  GCAL_TRACE_MSG ("new date: %s", icaltime_as_ical_string (*date));
+  new_date_string = g_date_time_format (date, "%x %X %z");
+  GCAL_TRACE_MSG ("new date: %s", new_date_string);
 
   update_header_labels (self);
   update_month_cells (self);
@@ -1780,7 +1785,7 @@ gcal_month_view_button_press (GtkWidget      *widget,
   GCAL_ENTRY;
 
   self = GCAL_MONTH_VIEW (widget);
-  days = self->days_delay + icaltime_days_in_month (self->date->month, self->date->year);
+  days = self->days_delay + gcal_date_time_get_days_in_month (self->date);
 
   /* The event may have come from a child widget, so make it relative to the month view */
   if (!gcal_translate_child_window_position (widget, event->window, event->x, event->y, &x, &y))
@@ -1793,7 +1798,8 @@ gcal_month_view_button_press (GtkWidget      *widget,
       g_clear_pointer (&self->start_mark_cell, g_date_time_unref);
 
       self->keyboard_cell = clicked_cell;
-      self->start_mark_cell = g_date_time_new_local (self->date->year, self->date->month,
+      self->start_mark_cell = g_date_time_new_local (g_date_time_get_year (self->date),
+                                                     g_date_time_get_month (self->date),
                                                      self->keyboard_cell - self->days_delay + 1,
                                                      0, 0, 0);
 
@@ -1815,7 +1821,7 @@ gcal_month_view_motion_notify_event (GtkWidget      *widget,
   GCAL_ENTRY;
 
   self = GCAL_MONTH_VIEW (widget);
-  days = self->days_delay + icaltime_days_in_month (self->date->month, self->date->year);
+  days = self->days_delay + gcal_date_time_get_days_in_month (self->date);
 
   if (!gcal_translate_child_window_position (widget, event->window, event->x, event->y, &x, &y))
     GCAL_RETURN (GDK_EVENT_PROPAGATE);
@@ -1834,8 +1840,8 @@ gcal_month_view_motion_notify_event (GtkWidget      *widget,
       self->keyboard_cell = new_end_cell;
 
       g_clear_pointer (&self->end_mark_cell, g_date_time_unref);
-      self->end_mark_cell = g_date_time_new_local (self->date->year,
-                                                   self->date->month,
+      self->end_mark_cell = g_date_time_new_local (g_date_time_get_year (self->date),
+                                                   g_date_time_get_month (self->date),
                                                    new_end_cell - self->days_delay + 1,
                                                    0, 0, 0);
 
@@ -1863,7 +1869,7 @@ gcal_month_view_button_release (GtkWidget      *widget,
   GCAL_ENTRY;
 
   self = GCAL_MONTH_VIEW (widget);
-  days = self->days_delay + icaltime_days_in_month (self->date->month, self->date->year);
+  days = self->days_delay + gcal_date_time_get_days_in_month (self->date);
 
   if (!gcal_translate_child_window_position (widget, event->window, event->x, event->y, &x, &y))
     GCAL_RETURN (GDK_EVENT_PROPAGATE);
@@ -1872,14 +1878,17 @@ gcal_month_view_button_release (GtkWidget      *widget,
 
   if (current_day >= self->days_delay && current_day < days)
     {
+      g_autoptr (GDateTime) new_active_date = NULL;
       gboolean valid;
 
-      g_clear_pointer (&self->end_mark_cell, g_date_time_unref);
-
       self->keyboard_cell = current_day;
-      self->end_mark_cell = g_date_time_new_local (self->date->year, self->date->month, current_day - 
self->days_delay + 1, 0, 0, 0);
+      new_active_date = g_date_time_new_local (g_date_time_get_year (self->date),
+                                               g_date_time_get_month (self->date),
+                                               current_day - self->days_delay + 1,
+                                               0, 0, 0);
 
-      self->date->day = g_date_time_get_day_of_month (self->end_mark_cell);
+      gcal_set_date_time (&self->end_mark_cell, new_active_date);
+      gcal_set_date_time (&self->date, new_active_date);
 
       /* First, make sure to show the popover */
       valid = emit_create_event (self);
@@ -1922,6 +1931,7 @@ gcal_month_view_key_press (GtkWidget   *widget,
   gboolean selection;
   gboolean valid_key;
   gboolean is_ltr;
+  gint days_in_month;
   gint min, max, diff, month_change, current_day;
   gint row, col;
 
@@ -1933,9 +1943,10 @@ gcal_month_view_key_press (GtkWidget   *widget,
   valid_key = FALSE;
   diff = 0;
   month_change = 0;
+  days_in_month = gcal_date_time_get_days_in_month (self->date);
   current_day = self->keyboard_cell - self->days_delay + 1;
   min = self->days_delay;
-  max = self->days_delay + icaltime_days_in_month (self->date->month, self->date->year) - 1;
+  max = self->days_delay + days_in_month - 1;
   is_ltr = gtk_widget_get_direction (widget) != GTK_TEXT_DIR_RTL;
 
   /*
@@ -1944,7 +1955,12 @@ gcal_month_view_key_press (GtkWidget   *widget,
    * focused cell.
    */
   if (selection && self->start_mark_cell == NULL)
-      self->start_mark_cell = g_date_time_new_local (self->date->year, self->date->month, current_day, 0, 0, 
0);
+    {
+      self->start_mark_cell = g_date_time_new_local (g_date_time_get_year (self->date),
+                                                     g_date_time_get_month (self->date),
+                                                     current_day,
+                                                     0, 0, 0);
+    }
 
   switch (event->keyval)
     {
@@ -1974,7 +1990,16 @@ gcal_month_view_key_press (GtkWidget   *widget,
        * simulate it by changing the start & end selected cells = keyboard cell.
        */
       if (!selection && !self->start_mark_cell && !self->end_mark_cell)
-        self->start_mark_cell = self->end_mark_cell = g_date_time_new_local (self->date->year, 
self->date->month, current_day, 0, 0, 0);
+        {
+          g_autoptr (GDateTime) new_mark = NULL;
+
+          new_mark = g_date_time_new_local (g_date_time_get_year (self->date),
+                                            g_date_time_get_month (self->date),
+                                            current_day,
+                                            0, 0, 0);
+          self->start_mark_cell = g_object_ref (new_mark);
+          self->end_mark_cell = g_object_ref (new_mark);
+        }
 
       create_event = TRUE;
       break;
@@ -1993,11 +2018,12 @@ gcal_month_view_key_press (GtkWidget   *widget,
     }
   else
     {
+      g_autoptr (GDateTime) new_month = NULL;
+
       month_change = self->keyboard_cell + diff > max ? 1 : -1;
-      self->date->month += month_change;
-      *self->date = icaltime_normalize (*self->date);
+      new_month = g_date_time_add_months (self->date, month_change);
 
-      self->days_delay = (time_day_of_week (1, self->date->month - 1, self->date->year) - 
self->first_weekday + 7) % 7;
+      self->days_delay = (time_day_of_week (1, g_date_time_get_month (new_month) - 1, g_date_time_get_year 
(new_month)) - self->first_weekday + 7) % 7;
 
       /*
        * Set keyboard cell value to the sum or difference of days delay of successive
@@ -2009,7 +2035,7 @@ gcal_month_view_key_press (GtkWidget   *widget,
       if (month_change == 1)
         self->keyboard_cell = self->days_delay + self->keyboard_cell + diff - max - 1;
       else
-        self->keyboard_cell = self->days_delay + icaltime_days_in_month (self->date->month, 
self->date->year) - min + self->keyboard_cell + diff;
+        self->keyboard_cell = self->days_delay + gcal_date_time_get_days_in_month (new_month) - min + 
self->keyboard_cell + diff;
     }
 
   /* Focus the selected month cell */
@@ -2019,7 +2045,7 @@ gcal_month_view_key_press (GtkWidget   *widget,
   gtk_widget_grab_focus (self->month_cell[row][col]);
 
   current_day = self->keyboard_cell - self->days_delay + 1;
-  self->date->day = current_day;
+  //self->date->day = current_day;
 
   /*
    * We can only emit the :create-event signal ~after~ grabbing the focus, otherwise
@@ -2032,7 +2058,10 @@ gcal_month_view_key_press (GtkWidget   *widget,
 
   if (selection)
     {
-      self->end_mark_cell = g_date_time_new_local (self->date->year, self->date->month, current_day, 0, 0, 
0);
+      self->end_mark_cell = g_date_time_new_local (g_date_time_get_year (self->date),
+                                                   g_date_time_get_month (self->date),
+                                                   current_day,
+                                                   0, 0, 0);
     }
   else if (!selection && valid_key)
     {
@@ -2055,8 +2084,14 @@ gcal_month_view_scroll_event (GtkWidget      *widget,
    */
   if (should_change_date_for_scroll (&self->scroll_value, scroll_event))
     {
-      self->date->month += self->scroll_value > 0 ? 1 : -1;
-      *self->date = icaltime_normalize (*self->date);
+      g_autoptr (GDateTime) new_date = NULL;
+      gint diff;
+
+      diff = self->scroll_value > 0 ? 1 : -1;
+      new_date = g_date_time_add_months (self->date, diff);
+
+      gcal_clear_datetime (&self->date);
+      self->date = g_steal_pointer (&new_date);
       self->scroll_value = 0;
 
       gtk_widget_queue_draw (widget);
@@ -2144,7 +2179,7 @@ gcal_month_view_finalize (GObject *object)
 {
   GcalMonthView *self = GCAL_MONTH_VIEW (object);
 
-  g_clear_pointer (&self->date, g_free);
+  gcal_clear_datetime (&self->date);
   g_clear_pointer (&self->children, g_hash_table_destroy);
   g_clear_pointer (&self->single_cell_children, g_hash_table_destroy);
   g_clear_pointer (&self->overflow_cells, g_hash_table_destroy);
diff --git a/src/views/gcal-view.c b/src/views/gcal-view.c
index 7d50240c..6553fd90 100644
--- a/src/views/gcal-view.c
+++ b/src/views/gcal-view.c
@@ -40,8 +40,8 @@ gcal_view_default_init (GcalViewInterface *iface)
                                        g_param_spec_boxed ("active-date",
                                                            "The active date",
                                                            "The active/selecetd date in the view",
-                                                           ICAL_TIME_TYPE,
-                                                           G_PARAM_READWRITE));
+                                                           G_TYPE_DATE_TIME,
+                                                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   /**
    * GcalView::manager:
@@ -67,8 +67,8 @@ gcal_view_default_init (GcalViewInterface *iface)
                 NULL, NULL, NULL,
                 G_TYPE_NONE,
                 4,
-                G_TYPE_POINTER,
-                G_TYPE_POINTER,
+                G_TYPE_DATE_TIME,
+                G_TYPE_DATE_TIME,
                 G_TYPE_DOUBLE,
                 G_TYPE_DOUBLE);
 
@@ -83,7 +83,9 @@ gcal_view_default_init (GcalViewInterface *iface)
                 G_SIGNAL_RUN_LAST,
                 G_STRUCT_OFFSET (GcalViewInterface, create_event_detailed),
                 NULL, NULL, NULL,
-                G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
+                G_TYPE_NONE, 2,
+                G_TYPE_DATE_TIME,
+                G_TYPE_DATE_TIME);
 
   /**
    * GcalView::event-activated:
@@ -102,13 +104,13 @@ gcal_view_default_init (GcalViewInterface *iface)
 /**
  * gcal_view_set_date:
  * @view: a #GcalView
- * @date: an #icaltimetype
+ * @date: an #GDateTime
  *
  * Sets the date of @view.
  */
 void
 gcal_view_set_date (GcalView     *view,
-                    icaltimetype *date)
+                    GDateTime *date)
 {
   g_return_if_fail (GCAL_IS_VIEW (view));
   g_return_if_fail (GCAL_VIEW_GET_IFACE (view)->set_date);
@@ -143,9 +145,9 @@ gcal_view_get_context (GcalView *self)
  *
  * Retrieves the date of @view.
  *
- * Returns: (transfer none): an #icaltimetype.
+ * Returns: (transfer none): an #GDateTime.
  */
-icaltimetype*
+GDateTime*
 gcal_view_get_date (GcalView *view)
 {
   g_return_val_if_fail (GCAL_IS_VIEW (view), NULL);
diff --git a/src/views/gcal-view.h b/src/views/gcal-view.h
index c8dc0d60..e16c2bd7 100644
--- a/src/views/gcal-view.h
+++ b/src/views/gcal-view.h
@@ -34,19 +34,19 @@ struct _GcalViewInterface
 
   /* signals */
   void               (*create_event)                             (GcalView           *view,
-                                                                  icaltimetype       *start_span,
-                                                                  icaltimetype       *end_span,
+                                                                  GDateTime          *start_span,
+                                                                  GDateTime          *end_span,
                                                                   gdouble             x,
                                                                   gdouble             y);
 
   void               (*create_event_detailed)                    (GcalView           *view,
-                                                                  icaltimetype       *start_span,
-                                                                  icaltimetype       *end_span);
+                                                                  GDateTime          *start_span,
+                                                                  GDateTime          *end_span);
 
-  icaltimetype*      (*get_date)                                 (GcalView           *view);
+  GDateTime*         (*get_date)                                 (GcalView           *view);
 
   void               (*set_date)                                 (GcalView           *view,
-                                                                  icaltimetype       *date);
+                                                                  GDateTime          *date);
 
   /* Marks related API */
   void               (*clear_marks)                              (GcalView           *view);
@@ -57,9 +57,9 @@ struct _GcalViewInterface
 };
 
 void                 gcal_view_set_date                          (GcalView           *view,
-                                                                  icaltimetype       *date);
+                                                                  GDateTime          *date);
 
-icaltimetype*        gcal_view_get_date                          (GcalView           *view);
+GDateTime*           gcal_view_get_date                          (GcalView           *view);
 
 GcalContext*         gcal_view_get_context                       (GcalView           *self);
 
diff --git a/src/views/gcal-week-grid.c b/src/views/gcal-week-grid.c
index d16b718b..d45e12b0 100644
--- a/src/views/gcal-week-grid.c
+++ b/src/views/gcal-week-grid.c
@@ -54,7 +54,7 @@ struct _GcalWeekGrid
   GtkWidget          *hours_sidebar;
   GdkWindow          *event_window;
 
-  icaltimetype       *active_date;
+  GDateTime          *active_date;
 
   GcalRangeTree      *events;
 
@@ -134,7 +134,7 @@ get_event_range (GcalWeekGrid *self,
   if (!self->active_date)
     return;
 
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   week_start_dst = g_date_time_is_daylight_savings (week_start);
 
   if (start)
@@ -273,7 +273,7 @@ gcal_week_grid_finalize (GObject *object)
   GcalWeekGrid *self = GCAL_WEEK_GRID (object);
 
   g_clear_pointer (&self->events, gcal_range_tree_unref);
-  g_clear_pointer (&self->active_date, g_free);
+  gcal_clear_datetime (&self->active_date);
 
   G_OBJECT_CLASS (gcal_week_grid_parent_class)->finalize (object);
 }
@@ -427,7 +427,7 @@ get_today_column (GcalWeekGrid *self)
   gint days_diff;
 
   today = g_date_time_new_now_local ();
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   days_diff = g_date_time_difference (today, week_start) / G_TIME_SPAN_DAY;
 
   /* Today is out of range */
@@ -872,7 +872,7 @@ gcal_week_grid_button_release (GtkWidget      *widget,
 
   /* Fake the week view's event so we can control the X and Y values */
   weekview = gtk_widget_get_ancestor (widget, GCAL_TYPE_WEEK_VIEW);
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
 
   if (ltr)
     {
@@ -1018,7 +1018,7 @@ gcal_week_grid_drag_drop (GtkWidget      *widget,
       goto out;
     }
 
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   dnd_date = g_date_time_add_minutes (week_start, drop_cell * 30);
 
   /*
@@ -1256,10 +1256,9 @@ gcal_week_grid_clear_marks (GcalWeekGrid *self)
 
 void
 gcal_week_grid_set_date (GcalWeekGrid *self,
-                         icaltimetype *date)
+                         GDateTime    *date)
 {
-  g_clear_pointer (&self->active_date, g_free);
-  self->active_date = gcal_dup_icaltime (date);
+  gcal_set_date_time (&self->active_date, date);
 
   gtk_widget_queue_resize (GTK_WIDGET (self));
   gtk_widget_queue_draw (GTK_WIDGET (self));
diff --git a/src/views/gcal-week-grid.h b/src/views/gcal-week-grid.h
index 787b288a..f21487c0 100644
--- a/src/views/gcal-week-grid.h
+++ b/src/views/gcal-week-grid.h
@@ -49,7 +49,7 @@ GList*               gcal_week_grid_get_children_by_uuid         (GcalWeekGrid
 void                 gcal_week_grid_clear_marks                  (GcalWeekGrid       *self);
 
 void                 gcal_week_grid_set_date                     (GcalWeekGrid       *self,
-                                                                  icaltimetype       *date);
+                                                                  GDateTime          *date);
 
 G_END_DECLS
 
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index 6b41e703..c1932d8f 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -89,7 +89,7 @@ struct _GcalWeekHeader
    */
   gboolean            expanded;
 
-  icaltimetype       *active_date;
+  GDateTime          *active_date;
 
   gint                selection_start;
   gint                selection_end;
@@ -150,7 +150,7 @@ add_weather_infos (GcalWeekHeader *self,
   if (!self->active_date)
     return 0;
 
-  week_start_dt = get_start_of_week (self->active_date);
+  week_start_dt = gcal_date_time_get_start_of_week (self->active_date);
   g_date_set_dmy (&week_start,
                   g_date_time_get_day_of_month (week_start_dt),
                   g_date_time_get_month (week_start_dt),
@@ -320,7 +320,7 @@ on_button_released (GcalWeekHeader *self,
       start = start - end;
     }
 
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   selection_start = g_date_time_add_days (week_start, start);
   selection_end = end == start ? g_date_time_ref (selection_start) : g_date_time_add_days (week_start, end + 
1);
 
@@ -385,7 +385,7 @@ get_today_column (GcalWeekHeader *self)
   gint days_diff;
 
   today = g_date_time_new_now_local ();
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   days_diff = g_date_time_difference (today, week_start) / G_TIME_SPAN_DAY;
 
   /* Today is out of range */
@@ -630,7 +630,7 @@ split_event_widget_at_column (GcalWeekHeader *self,
   gint new_width;
   gint old_width;
 
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   column_date = g_date_time_add_days (week_start, column);
   end_column_date = g_date_time_add_days (column_date, 1);
 
@@ -821,8 +821,8 @@ add_event_to_grid (GcalWeekHeader *self,
   if (!gcal_event_is_multiday (event))
     return;
 
-  week_start = get_start_of_week (self->active_date);
-  week_end = get_end_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
+  week_end = gcal_date_time_get_end_of_week (self->active_date);
 
   gcal_event_widget_set_date_start (GCAL_EVENT_WIDGET (widget), week_start);
   gcal_event_widget_set_date_end (GCAL_EVENT_WIDGET (widget), week_end);
@@ -889,7 +889,7 @@ add_event_to_grid (GcalWeekHeader *self,
 
 static void
 update_unchanged_events (GcalWeekHeader *self,
-                         icaltimetype   *new_icaldt)
+                         GDateTime      *new_date)
 {
   g_autoptr (GDateTime) new_week_start, new_week_end;
   g_autoptr (GDateTime) utc_week_start, utc_week_end;
@@ -898,8 +898,8 @@ update_unchanged_events (GcalWeekHeader *self,
 
   events_to_update = NULL;
 
-  new_week_start = get_start_of_week (new_icaldt);
-  new_week_end = get_end_of_week (new_icaldt);
+  new_week_start = gcal_date_time_get_start_of_week (new_date);
+  new_week_end = gcal_date_time_get_end_of_week (new_date);
 
   utc_week_start = g_date_time_new_utc (g_date_time_get_year (new_week_start),
                                         g_date_time_get_month (new_week_start),
@@ -972,7 +972,7 @@ update_title (GcalWeekHeader *self)
   if(!self->active_date)
     return;
 
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   week_end = g_date_time_add_days (week_start, 6);
   week_mid = g_date_time_add_days (week_start, 3);
 
@@ -1157,7 +1157,7 @@ gcal_week_header_finalize (GObject *object)
   GcalWeekHeader *self = GCAL_WEEK_HEADER (object);
   gint i;
 
-  g_clear_pointer (&self->active_date, g_free);
+  gcal_clear_datetime (&self->active_date);
 
   for (i = 0; i < 7; i++)
     g_list_free (self->events[i]);
@@ -1229,9 +1229,9 @@ gcal_week_header_draw (GtkWidget      *widget,
   pango_font_description_set_weight (bold_font, PANGO_WEIGHT_MEDIUM);
   pango_layout_set_font_description (layout, bold_font);
 
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
   week_end = g_date_time_add_days (week_start, 6);
-  current_cell = icaltime_day_of_week (*(self->active_date)) - 1;
+  current_cell = g_date_time_get_day_of_week (self->active_date) - 1;
   current_cell = (7 + current_cell - self->first_weekday) % 7;
   today_column = get_today_column (self);
 
@@ -1562,7 +1562,7 @@ gcal_week_header_drag_drop (GtkWidget      *widget,
   event = gcal_event_widget_get_event (GCAL_EVENT_WIDGET (event_widget));
   start_date = gcal_event_get_date_start (event);
   end_date = gcal_event_get_date_end (event);
-  week_start = get_start_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
 
   turn_all_day = !gcal_event_is_multiday (event) || gcal_event_get_all_day (event);
 
@@ -1736,8 +1736,8 @@ gcal_week_header_add_event (GcalWeekHeader *self,
   g_return_if_fail (GCAL_IS_WEEK_HEADER (self));
 
   all_day = gcal_event_get_all_day (event);
-  week_start = get_start_of_week (self->active_date);
-  week_end = get_end_of_week (self->active_date);
+  week_start = gcal_date_time_get_start_of_week (self->active_date);
+  week_end = gcal_date_time_get_end_of_week (self->active_date);
 
   /* Retrieve the real start and end dates */
   if (all_day)
@@ -1903,22 +1903,22 @@ gcal_week_header_clear_marks (GcalWeekHeader *self)
 
 void
 gcal_week_header_set_date (GcalWeekHeader *self,
-                           icaltimetype   *date)
+                           GDateTime      *date)
 {
-  icaltimetype *old_date, *new_date;
+  GDateTime *old_date, *new_date;
 
   old_date = self->active_date;
-  new_date = gcal_dup_icaltime (date);
+  new_date = g_date_time_ref (date);
 
   /*
    * If the active date changed, but we're still in the same week,
    * there's no need to recalculate visible events.
    */
   if (old_date && new_date &&
-      old_date->year == new_date->year &&
-      icaltime_week_number (*old_date) == icaltime_week_number (*new_date))
+      g_date_time_get_year (old_date) == g_date_time_get_year (new_date) &&
+      g_date_time_get_week_numbering_year (old_date) == g_date_time_get_week_numbering_year (new_date))
     {
-      g_free (new_date);
+      g_date_time_unref (new_date);
       return;
     }
 
@@ -1932,6 +1932,6 @@ gcal_week_header_set_date (GcalWeekHeader *self,
 
   update_weather_infos (self);
 
-  g_clear_pointer (&old_date, g_free);
+  gcal_clear_datetime (&old_date);
 }
 
diff --git a/src/views/gcal-week-header.h b/src/views/gcal-week-header.h
index df86a526..5a37940f 100644
--- a/src/views/gcal-week-header.h
+++ b/src/views/gcal-week-header.h
@@ -50,7 +50,7 @@ GtkSizeGroup*        gcal_week_header_get_sidebar_size_group     (GcalWeekHeader
 void                 gcal_week_header_clear_marks                (GcalWeekHeader     *self);
 
 void                 gcal_week_header_set_date                   (GcalWeekHeader     *self,
-                                                                  icaltimetype       *date);
+                                                                  GDateTime          *date);
 
 G_END_DECLS
 
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 3f168c0e..8b7eb875 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -49,7 +49,7 @@ struct _GcalWeekView
   GtkWidget          *week_grid;
 
   /* property */
-  icaltimetype       *date;
+  GDateTime          *date;
   GcalContext        *context;
 
   guint               scroll_grid_timeout_id;
@@ -129,8 +129,8 @@ update_grid_scroll_position (GcalWeekView *self)
     }
 
   now = g_date_time_new_now_local ();
-  week_start = get_start_of_week (self->date);
-  week_end = get_end_of_week (self->date);
+  week_start = gcal_date_time_get_start_of_week (self->date);
+  week_end = gcal_date_time_get_end_of_week (self->date);
 
   /* Don't animate when not today */
   if (datetime_compare_date (now, week_start) < 0 || datetime_compare_date (now, week_end) >= 0)
@@ -173,7 +173,7 @@ schedule_position_scroll (GcalWeekView *self)
 }
 
 /* GcalView implementation */
-static icaltimetype*
+static GDateTime*
 gcal_week_view_get_date (GcalView *view)
 {
   GcalWeekView *self = GCAL_WEEK_VIEW (view);
@@ -182,15 +182,14 @@ gcal_week_view_get_date (GcalView *view)
 }
 
 static void
-gcal_week_view_set_date (GcalView     *view,
-                         icaltimetype *date)
+gcal_week_view_set_date (GcalView  *view,
+                         GDateTime *date)
 {
   GcalWeekView *self = GCAL_WEEK_VIEW (view);
 
   GCAL_ENTRY;
 
-  g_clear_pointer (&self->date, g_free);
-  self->date = gcal_dup_icaltime (date);
+  gcal_set_date_time (&self->date, date);
 
   /* Propagate the new date */
   gcal_week_grid_set_date (GCAL_WEEK_GRID (self->week_grid), date);
diff --git a/src/views/gcal-year-view.c b/src/views/gcal-year-view.c
index 2edff1cd..9c725a8f 100644
--- a/src/views/gcal-year-view.c
+++ b/src/views/gcal-year-view.c
@@ -70,8 +70,8 @@ struct _GcalYearView
   GcalContext        *context;
 
   /* range shown on the sidebar */
-  icaltimetype       *start_selected_date;
-  icaltimetype       *end_selected_date;
+  GDateTime          *start_selected_date;
+  GDateTime          *end_selected_date;
 
   /* geometry info */
   GridData           *navigator_grid;
@@ -107,7 +107,7 @@ struct _GcalYearView
   gint                k;
 
   /* date property */
-  icaltimetype       *date;
+  GDateTime          *date;
 
   /*
    * Array with the events at every month. Events
@@ -211,71 +211,70 @@ update_selected_dates_from_button_data (GcalYearView *year_view)
   if (year_view->selected_data->start_day != 0)
     {
       ButtonData selected_data = *(year_view->selected_data);
+
       order_selected_data (&selected_data);
 
-      year_view->start_selected_date->day = selected_data.start_day;
-      year_view->start_selected_date->month = selected_data.start_month + 1;
-      year_view->start_selected_date->year = year_view->date->year;
-      year_view->end_selected_date->is_date = TRUE;
-
-      year_view->end_selected_date->day = selected_data.end_day;
-      year_view->end_selected_date->month = selected_data.end_month + 1;
-      year_view->end_selected_date->year = year_view->date->year;
-      year_view->end_selected_date->hour = 23;
-      year_view->end_selected_date->minute = 59;
-      year_view->end_selected_date->is_date = TRUE;
-      *(year_view->end_selected_date) = icaltime_normalize (*(year_view->end_selected_date));
+      gcal_clear_datetime (&year_view->start_selected_date);
+      year_view->start_selected_date = g_date_time_new_local (g_date_time_get_year (year_view->date),
+                                                              selected_data.start_month + 1,
+                                                              selected_data.start_day,
+                                                              0, 0, 0);
+
+      gcal_clear_datetime (&year_view->end_selected_date);
+      year_view->end_selected_date = g_date_time_new_local (g_date_time_get_year (year_view->date),
+                                                            selected_data.start_month + 1,
+                                                            selected_data.start_day,
+                                                            23, 59, 59);
     }
   else
     {
-      g_autofree icaltimetype *current_date;
-      g_autoptr (GDateTime) now;
-
-      now = g_date_time_new_now_local ();
-      current_date = datetime_to_icaltime (now);
+      g_autoptr (GDateTime) start_date = NULL;
 
       if (year_view->date)
-        *(year_view->start_selected_date) = *year_view->date;
+        start_date = g_date_time_ref (year_view->date);
       else
-        *(year_view->start_selected_date) = *current_date;
-
-      year_view->start_selected_date->hour = 0;
-      year_view->start_selected_date->minute = 0;
-      year_view->start_selected_date->second = 0;
-
-      *(year_view->end_selected_date) = *(year_view->start_selected_date);
-      year_view->end_selected_date->hour = 23;
-      year_view->end_selected_date->minute = 59;
-      *(year_view->end_selected_date) = icaltime_normalize (*(year_view->end_selected_date));
-
-      year_view->selected_data->start_day = year_view->start_selected_date->day;
-      year_view->selected_data->start_month = year_view->start_selected_date->month - 1;
-      year_view->selected_data->end_day = year_view->end_selected_date->day;
-      year_view->selected_data->end_month = year_view->end_selected_date->month -1;
+        start_date = g_date_time_new_now_local ();
+
+      gcal_clear_datetime (&year_view->start_selected_date);
+      year_view->start_selected_date = g_date_time_new (gcal_context_get_timezone (year_view->context),
+                                                        g_date_time_get_year (start_date),
+                                                        g_date_time_get_month (start_date),
+                                                        g_date_time_get_day_of_month (start_date),
+                                                        0, 0, 0);
+
+      gcal_clear_datetime (&year_view->end_selected_date);
+      year_view->end_selected_date = g_date_time_add_days (year_view->start_selected_date, 1);
+
+      year_view->selected_data->start_day = g_date_time_get_day_of_month (year_view->start_selected_date);
+      year_view->selected_data->start_month = g_date_time_get_month (year_view->start_selected_date) - 1;
+      year_view->selected_data->end_day = g_date_time_get_day_of_month (year_view->end_selected_date);
+      year_view->selected_data->end_month = g_date_time_get_month (year_view->end_selected_date)-1;
     }
 
-  if (year_view->end_selected_date->year != year_view->start_selected_date->year)
+  if (g_date_time_get_year (year_view->end_selected_date) != g_date_time_get_year 
(year_view->start_selected_date))
     {
-      year_view->end_selected_date->day = 31;
-      year_view->end_selected_date->month = 12;
-      year_view->end_selected_date->year = year_view->start_selected_date->year;
+      g_autoptr (GDateTime) end_of_year = NULL;
+
+      end_of_year = g_date_time_new (gcal_context_get_timezone (year_view->context),
+                                     g_date_time_get_year (year_view->start_selected_date),
+                                     G_DATE_DECEMBER,
+                                     31,
+                                     0, 0, 0);
+      gcal_set_date_time (&year_view->end_selected_date, end_of_year);
     }
 }
 
 static void
 update_no_events_page (GcalYearView *year_view)
 {
-  g_autoptr (GDateTime) start_selected_date, now;
+  g_autoptr (GDateTime) now = NULL;
   gboolean has_range;
   gchar *title;
 
   now = g_date_time_new_now_local ();
-  start_selected_date = icaltime_to_datetime (year_view->start_selected_date);
+  has_range = datetime_compare_date (year_view->start_selected_date, year_view->end_selected_date);
 
-  has_range = (year_view->start_selected_date->day != year_view->end_selected_date->day ||
-               year_view->start_selected_date->month != year_view->end_selected_date->month);
-
-  if (datetime_compare_date (now, start_selected_date) == 0)
+  if (datetime_compare_date (now, year_view->start_selected_date) == 0)
     {
       title = g_strdup_printf ("%s%s", _("Today"), has_range ? "…" : "");
     }
@@ -286,13 +285,13 @@ update_no_events_page (GcalYearView *year_view)
           /* Translators: This is a date format in the sidebar of the year
            * view when the selection starts at the specified day and the
            * end is unspecified.  */
-          title = g_date_time_format (start_selected_date, _("%B %d…"));
+          title = g_date_time_format (year_view->start_selected_date, _("%B %d…"));
         }
       else
         {
           /* Translators: This is a date format in the sidebar of the year
            * view when there is only one specified day selected.  */
-          title = g_date_time_format (start_selected_date, _("%B %d"));
+          title = g_date_time_format (year_view->start_selected_date, _("%B %d"));
         }
     }
 
@@ -307,10 +306,11 @@ add_event_to_day_array (GcalYearView  *year_view,
                         GList        **days_widgets_array,
                         gint           days_span)
 {
+  g_autoptr (GDateTime) second_date = NULL;
+  g_autoptr (GDateTime) date = NULL;
   GcalManager *manager;
   GtkWidget *child_widget;
   GDateTime *dt_start, *dt_end;
-  GDateTime *date, *second_date;
   gboolean is_readonly;
   gint i;
 
@@ -324,7 +324,7 @@ add_event_to_day_array (GcalYearView  *year_view,
   dt_end = gcal_event_get_date_end (event);
 
   /* normalize date on each new event */
-  date = icaltime_to_datetime (year_view->start_selected_date);
+  date = g_date_time_ref (year_view->start_selected_date);
   second_date = g_date_time_add_days (date, 1);
 
   /* marking and cloning */
@@ -402,14 +402,13 @@ add_event_to_day_array (GcalYearView  *year_view,
       second_date = g_date_time_add_days (second_date, 1);
       g_clear_pointer (&aux, g_date_time_unref);
     }
-
-  g_clear_pointer (&second_date, g_date_time_unref);
-  g_clear_pointer (&date, g_date_time_unref);
 }
 
 static void
 update_sidebar (GcalYearView *year_view)
 {
+  g_autofree icaltimetype *start_icaldatetime = NULL;
+  g_autofree icaltimetype *end_icaldatetime = NULL;
   GcalManager *manager;
   GtkWidget *child_widget;
   GList *events, *l;
@@ -420,11 +419,16 @@ update_sidebar (GcalYearView *year_view)
 
   gtk_container_foreach (GTK_CONTAINER (year_view->events_sidebar), (GtkCallback) gtk_widget_destroy, NULL);
 
-  days_span = icaltime_day_of_year(*(year_view->end_selected_date)) - 
icaltime_day_of_year(*(year_view->start_selected_date)) + 1;
+  if (!year_view->start_selected_date || !year_view->end_selected_date)
+    return;
+
+  days_span = g_date_time_get_day_of_year (year_view->end_selected_date) - g_date_time_get_day_of_year 
(year_view->start_selected_date) + 1;
   days_widgets_array = g_new0 (GList*, days_span);
 
   manager = gcal_context_get_manager (year_view->context);
-  events = gcal_manager_get_events (manager, year_view->start_selected_date, year_view->end_selected_date);
+  start_icaldatetime = datetime_to_icaltime (year_view->start_selected_date);
+  end_icaldatetime = datetime_to_icaltime (year_view->end_selected_date);
+  events = gcal_manager_get_events (manager, start_icaldatetime, end_icaldatetime);
   if (events == NULL)
     {
       days_span = 0;
@@ -478,7 +482,6 @@ update_sidebar_headers (GtkListBoxRow *row,
   GtkWidget *row_child, *before_child = NULL, *row_header = NULL;
   GcalEvent *row_event, *before_event;
   GDateTime *row_date, *before_date = NULL;
-  icaltimetype date;
   gint row_shift, before_shift =-1;
 
   year_view = GCAL_YEAR_VIEW (user_data);
@@ -503,23 +506,18 @@ update_sidebar_headers (GtkListBoxRow *row,
 
   if (before_shift == -1 || before_shift != row_shift)
     {
-      g_autoptr (GDateTime) now, dt;
+      g_autoptr (GDateTime) now = NULL;
       GtkWidget *label;
       gchar *label_str;
 
       row_header = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
       now = g_date_time_new_now_local ();
 
-      date = *(year_view->start_selected_date);
-      icaltime_adjust (&date, row_shift, 0, 0, 0);
-
-      dt = icaltime_to_datetime (&date);
-
-      if (datetime_compare_date (dt, now) == 0)
+      if (datetime_compare_date (year_view->start_selected_date, now) == 0)
         label_str = g_strdup (_("Today"));
       else
         /* Translators: This is a date format in the sidebar of the year view. */
-        label_str = g_date_time_format (dt, _("%B %d"));
+        label_str = g_date_time_format (year_view->start_selected_date, _("%B %d"));
 
       label = gtk_label_new (label_str);
       gtk_style_context_add_class (gtk_widget_get_style_context (label), "sidebar-header");
@@ -539,19 +537,25 @@ update_sidebar_headers (GtkListBoxRow *row,
 
 static void
 update_date (GcalYearView *year_view,
-             icaltimetype *new_date)
+             GDateTime    *new_date)
 {
   gboolean needs_reset = FALSE;
-  if (year_view->date != NULL && icaltime_compare_date (year_view->date, new_date) && 
year_view->start_selected_date->day != 0)
-    needs_reset = TRUE;
 
-  g_clear_pointer (&year_view->date, g_free);
-  year_view->date = gcal_dup_icaltime (new_date);
+  if (year_view->date &&
+      year_view->start_selected_date &&
+      !g_date_time_equal (year_view->date, new_date))
+    {
+      needs_reset = TRUE;
+    }
+
+  gcal_set_date_time (&year_view->date, new_date);
 
   year_view->first_week_of_year = get_last_week_of_year_dmy (year_view->first_weekday,
-                                                             1, G_DATE_JANUARY,  year_view->date->year);;
+                                                             1, G_DATE_JANUARY,
+                                                             g_date_time_get_year (year_view->date));;
   year_view->last_week_of_year = get_last_week_of_year_dmy (year_view->first_weekday,
-                                                            31, G_DATE_DECEMBER, year_view->date->year);
+                                                            31, G_DATE_DECEMBER,
+                                                            g_date_time_get_year (year_view->date));
 
   if (needs_reset)
     reset_sidebar (year_view);
@@ -580,7 +584,7 @@ calculate_coord_for_date (GcalYearView *year_view,
 
   /* else */
   sw = 1 - 2 * year_view->k;
-  clicked_cell = day + ((time_day_of_week (1, month, year_view->date->year) - year_view->first_weekday + 7) 
% 7) - 1;
+  clicked_cell = day + ((time_day_of_week (1, month, g_date_time_get_year (year_view->date)) - 
year_view->first_weekday + 7) % 7) - 1;
 
   cell_x = (clicked_cell % 7 + year_view->k + year_view->show_week_numbers) * 
year_view->navigator_grid->box_side * sw;
   cell_x += (year_view->k * year_view->navigator_grid->box_side * (7 + year_view->show_week_numbers));
@@ -670,9 +674,9 @@ calculate_day_month_for_coord (GcalYearView *year_view,
   column = (x - (year_view->navigator_grid->coordinates[month].x + box_side * year_view->show_week_numbers * 
(1 - year_view->k))) / box_side;
   clicked_cell = row * 7 + column;
   day = 7 * ((clicked_cell + 7 * year_view->k) / 7) + sw * (clicked_cell % 7) + (1 - year_view->k);
-  day -= ((time_day_of_week (1, month, year_view->date->year) - year_view->first_weekday + 7) % 7);
+  day -= ((time_day_of_week (1, month, g_date_time_get_year (year_view->date)) - year_view->first_weekday + 
7) % 7);
 
-  if (day < 1 || day > time_days_in_month (year_view->date->year, month))
+  if (day < 1 || day > time_days_in_month (g_date_time_get_year (year_view->date), month))
     return FALSE;
 
   *out_day = day;
@@ -680,16 +684,15 @@ calculate_day_month_for_coord (GcalYearView *year_view,
 }
 static guint
 count_events_at_day (GcalYearView *self,
-                     icaltimetype *today)
+                     GDateTime    *today)
 {
-  g_autoptr (GDateTime) today_start, today_end;
+  g_autoptr (GDateTime) today_end = NULL;
   GPtrArray *events;
   guint i, n_events;
 
-  events = self->events[today->month - 1];
+  events = self->events[g_date_time_get_month (today) - 1];
   n_events = 0;
-  today_start = icaltime_to_datetime (today);
-  today_end = g_date_time_add_days (today_start, 1);
+  today_end = g_date_time_add_days (today, 1);
 
   for (i = 0; i < events->len; i++)
     {
@@ -707,7 +710,7 @@ count_events_at_day (GcalYearView *self,
 
 
       if (datetime_compare_date (event_start, today_end) >= 0 ||
-          datetime_compare_date (event_end, today_start) < 0)
+          datetime_compare_date (event_end, today) < 0)
         {
           continue;
         }
@@ -731,7 +734,8 @@ draw_month_grid (GcalYearView *year_view,
   PangoLayout *layout, *slayout;
   PangoFontDescription *font_desc, *sfont_desc;
 
-  g_autoptr (GDateTime) now;
+  g_autoptr (GDateTime) day = NULL;
+  g_autoptr (GDateTime) now = NULL;
 
   GdkRGBA color;
   gint layout_width, layout_height, i, j, sw;
@@ -741,7 +745,6 @@ draw_month_grid (GcalYearView *year_view,
   gint days_delay, days, shown_rows;
   gchar *str, *nr_day, *nr_week;
   gboolean selected_day;
-  icaltimetype today;
 
   now = g_date_time_new_now_local ();
 
@@ -804,21 +807,19 @@ draw_month_grid (GcalYearView *year_view,
   gtk_style_context_get (context, state_flags, "font", &font_desc, NULL);
   pango_layout_set_font_description (layout, font_desc);
 
-  days_delay = (time_day_of_week (1, month_nr, year_view->date->year) - year_view->first_weekday + 7) % 7;
-  days = days_delay + icaltime_days_in_month (month_nr + 1, year_view->date->year);
+  days_delay = (time_day_of_week (1, month_nr, g_date_time_get_year (year_view->date)) - 
year_view->first_weekday + 7) % 7;
+  days = days_delay + g_date_get_days_in_month (month_nr + 1, g_date_time_get_year (year_view->date));
   shown_rows = ceil (days / 7.0);
 
-  today = icaltime_today ();
-  today.year = year_view->date->year;
-  today.month = month_nr + 1;
-  today.day = 1;
-  today.hour = 0;
-  today.minute = 0;
-  today.second = 0;
-  today.zone = gcal_manager_get_system_timezone (gcal_context_get_manager (year_view->context));
+  day = g_date_time_new (gcal_context_get_timezone (year_view->context),
+                         g_date_time_get_year (year_view->date),
+                         month_nr + 1,
+                         1, 0, 0, 0);
 
   for (i = 0; i < 7 * shown_rows; i++)
     {
+      g_autoptr (GDateTime) next_day = NULL;
+
       column = (i % 7) + (year_view->k || year_view->show_week_numbers);
       column_is_workday = is_workday ((7 * year_view->k + sw * (column - (year_view->show_week_numbers * 
!year_view->k) + (sw * year_view->first_weekday))) % 7);
       row = i / 7;
@@ -902,7 +903,7 @@ draw_month_grid (GcalYearView *year_view,
             }
         }
 
-      if (year_view->date->year == g_date_time_get_year (now) &&
+      if (g_date_time_get_year (year_view->date) == g_date_time_get_year (now) &&
           month_nr + 1 == g_date_time_get_month (now) &&
           j == g_date_time_get_day_of_month (now))
         {
@@ -967,10 +968,7 @@ draw_month_grid (GcalYearView *year_view,
                              layout);
         }
 
-      /* Update the current day, so we can count the events at this day */
-      today.day = j;
-
-      if (count_events_at_day (year_view, &today) > 0)
+      if (count_events_at_day (year_view, day) > 0)
         {
           gtk_style_context_save (context);
           gtk_style_context_add_class (context, "with-events");
@@ -988,6 +986,10 @@ draw_month_grid (GcalYearView *year_view,
           gtk_style_context_restore (context);
         }
 
+      /* Update the current day, so we can count the events at this day */
+      next_day = g_date_time_add_days (day, 1);
+      gcal_set_date_time (&day, next_day);
+
       g_free (nr_day);
     }
   pango_font_description_free (font_desc);
@@ -1076,7 +1078,7 @@ draw_navigator (GcalYearView *year_view,
   gtk_style_context_save (context);
   gtk_style_context_add_class (context, "primary-label");
 
-  header_str = g_strdup_printf ("%d", year_view->date->year);
+  header_str = g_strdup_printf ("%d", g_date_time_get_year (year_view->date));
   gtk_style_context_get (context, state_flags, "font", &font_desc, NULL);
   gtk_style_context_get_padding (context, state_flags, &padding);
 
@@ -1145,8 +1147,9 @@ navigator_button_release_cb (GcalYearView   *year_view,
                              GdkEventButton *event,
                              GtkWidget      *widget)
 {
-  gint day, month;
+  g_autoptr (GDateTime) new_date = NULL;
   gboolean is_title = FALSE;
+  gint day, month;
 
   if (!year_view->button_pressed)
     return FALSE;
@@ -1155,15 +1158,18 @@ navigator_button_release_cb (GcalYearView   *year_view,
     goto fail;
 
   if (is_title)
-    day = g_date_get_days_in_month (month + 1, year_view->date->year);
+    day = g_date_get_days_in_month (month + 1, g_date_time_get_year (year_view->date));
 
   year_view->button_pressed = FALSE;
   year_view->selected_data->end_day = day;
   year_view->selected_data->end_month = month;
 
   /* update date and notify */
-  year_view->date->day = day;
-  year_view->date->month = month + 1;
+  new_date = g_date_time_new_local (g_date_time_get_year (year_view->date),
+                                    month + 1,
+                                    day,
+                                    0, 0, 0);
+  gcal_set_date_time (&year_view->date, new_date);
   g_object_notify (G_OBJECT (year_view), "active-date");
 
   gtk_widget_queue_draw (widget);
@@ -1211,7 +1217,7 @@ navigator_motion_notify_cb (GcalYearView   *year_view,
       if (year_view->button_pressed)
         {
           if (is_title)
-            day = g_date_get_days_in_month (month + 1, year_view->date->year);
+            day = g_date_get_days_in_month (month + 1, g_date_time_get_year (year_view->date));
 
           year_view->selected_data->end_day = day;
           year_view->selected_data->end_month = month;
@@ -1239,6 +1245,7 @@ static void
 navigator_edge_overshot_cb (GcalYearView    *self,
                             GtkPositionType  position_type)
 {
+  g_autoptr (GDateTime) new_date = NULL;
   GtkAdjustment *adjustment;
 
   /* Ignore horizontal scrolling (and the year view never scrolls horizontally anyway) */
@@ -1247,8 +1254,8 @@ navigator_edge_overshot_cb (GcalYearView    *self,
 
   adjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (self->scrolled_window));
 
-  self->date->year += position_type == GTK_POS_BOTTOM ? 1 : -1;
-  *self->date = icaltime_normalize (*self->date);
+  new_date = g_date_time_add_years (self->date, position_type == GTK_POS_BOTTOM ? 1 : -1);
+  gcal_set_date_time (&self->date, new_date);
 
   gtk_adjustment_set_value (adjustment, 0.0);
   gtk_widget_queue_draw (self->navigator);
@@ -1277,8 +1284,10 @@ navigator_scroll_event_cb (GcalYearView   *self,
    */
   if (should_change_date_for_scroll (&self->scroll_value, scroll_event))
     {
-      self->date->year += self->scroll_value > 0 ? 1 : -1;
-      *self->date = icaltime_normalize (*self->date);
+      g_autoptr (GDateTime) new_date = NULL;
+
+      new_date = g_date_time_add_years (self->date, self->scroll_value > 0 ? 1 : -1);
+      gcal_set_date_time (&self->date, new_date);
       self->scroll_value = 0;
 
       gtk_widget_queue_draw (self->navigator);
@@ -1293,34 +1302,23 @@ static void
 add_event_clicked_cb (GcalYearView *year_view,
                       GtkButton    *button)
 {
-  GDateTime *start_date, *end_date = NULL;
+  g_autoptr (GDateTime) start_date = NULL;
+  g_autoptr (GDateTime) end_date = NULL;
 
-  if (year_view->start_selected_date->day == 0)
+  if (year_view->start_selected_date)
     {
       start_date = g_date_time_new_now_local ();
     }
   else
     {
-      icaltimetype *dtstart, *dtend;
-      GDateTime *tmp_date;
-
-      dtstart = year_view->start_selected_date;
-      dtend = year_view->end_selected_date;
-
-      start_date = g_date_time_new_local (dtstart->year, dtstart->month, dtstart->day, 0, 0, 0);
-      tmp_date = g_date_time_new_local (dtend->year, dtend->month, dtend->day, 0, 0, 0);
-      end_date = g_date_time_add_days (tmp_date, 1);
-
-      g_clear_pointer (&tmp_date, g_date_time_unref);
+      start_date = g_date_time_ref (year_view->start_selected_date);
+      end_date = g_date_time_add_days (year_view->end_selected_date, 1);
     }
 
   if (year_view->popover_mode)
     gtk_widget_hide (year_view->popover);
 
   g_signal_emit_by_name (GCAL_VIEW (year_view), "create-event-detailed", start_date, end_date);
-
-  g_clear_pointer (&start_date, g_date_time_unref);
-  g_clear_pointer (&end_date, g_date_time_unref);
 }
 
 static void
@@ -1492,7 +1490,7 @@ navigator_drag_drop_cb (GcalYearView   *self,
           end_dt = gcal_event_get_date_end (event);
 
           drop_date = g_date_time_add_full (start_dt,
-                                            self->date->year - g_date_time_get_year (start_dt),
+                                            g_date_time_get_year (self->date) - g_date_time_get_year 
(start_dt),
                                             (month + 1) - g_date_time_get_month (start_dt),
                                             day - g_date_time_get_day_of_month (start_dt),
                                             0, 0, 0);
@@ -1551,7 +1549,7 @@ navigator_drag_leave_cb (GcalYearView   *self,
 }
 
 /* GcalView implementation */
-static icaltimetype*
+static GDateTime*
 gcal_year_view_get_date (GcalView *view)
 {
   GcalYearView *self = GCAL_YEAR_VIEW (view);
@@ -1560,8 +1558,8 @@ gcal_year_view_get_date (GcalView *view)
 }
 
 static void
-gcal_year_view_set_date (GcalView     *view,
-                         icaltimetype *date)
+gcal_year_view_set_date (GcalView  *view,
+                         GDateTime *date)
 {
   GCAL_ENTRY;
 
@@ -1828,10 +1826,10 @@ gcal_year_view_component_added (ECalDataModelSubscriber *subscriber,
   start_month = g_date_time_get_month (event_start) - 1;
   end_month = g_date_time_get_month (event_end) - 1;
 
-  if (g_date_time_get_year (event_start) < self->date->year)
+  if (g_date_time_get_year (event_start) < g_date_time_get_year (self->date))
     start_month = 0;
 
-  if (g_date_time_get_year (event_end) > self->date->year)
+  if (g_date_time_get_year (event_end) > g_date_time_get_year (self->date))
     end_month = 11;
 
   /* Add the event to the cache */
@@ -2027,11 +2025,6 @@ gcal_year_view_init (GcalYearView *self)
   self->navigator_grid = g_new0 (GridData, 1);
   self->selected_data = g_new0 (ButtonData, 1);
 
-  self->start_selected_date = g_new0 (icaltimetype, 1);
-  self->start_selected_date->zone = e_cal_util_get_system_timezone ();
-  self->end_selected_date = g_new0 (icaltimetype, 1);
-  self->end_selected_date->zone = e_cal_util_get_system_timezone ();
-
   /* bind GNOME Shell' show week numbers property to GNOME Calendar's one */
   self->calendar_settings = g_settings_new ("org.gnome.desktop.calendar");
   g_settings_bind (self->calendar_settings, "show-weekdate", self, "show-week-numbers", 
G_SETTINGS_BIND_DEFAULT);
@@ -2078,7 +2071,10 @@ update_weather (GcalYearView *self)
       GDate date;
       guint i;
 
-      g_date_set_dmy (&date, self->date->day, self->date->month, self->date->year);
+      g_date_set_dmy (&date,
+                      g_date_time_get_day_of_month (self->date),
+                      g_date_time_get_month (self->date),
+                      g_date_time_get_year (self->date));
 
       weather_infos = gcal_weather_service_get_weather_infos (weather_service);
 


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