[gnome-calendar/gnome-3-26] Revert "event: correctly store timezones"



commit 6701e665fa89b2fb1fc5770087b4671a3dfed27d
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Tue Dec 5 17:26:39 2017 -0600

    Revert "event: correctly store timezones"
    
    This reverts commit ce2c9552693bf549a232a9681692b5fbd2cd3560.
    
    This commit is not right. Lots of code in Calendar relies on being able
    to set the timezone of a GcalEvent, and this results in us always
    ignoring the timezone set by Calendar in preference to whatever happened
    to be in the ECalComponentDateTime previously. That might not be so bad,
    but additionally, the time is not adjusted accordingly, so this actually
    results in the time of events changing unexpectedly from what Calendar
    is trying to set.
    
    The code to explicitly store UTC times for all day events is OK (I
    guess) and will be restored in a subsequent commit.

 src/gcal-event.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)
---
diff --git a/src/gcal-event.c b/src/gcal-event.c
index e7e2889a..57326777 100644
--- a/src/gcal-event.c
+++ b/src/gcal-event.c
@@ -221,11 +221,11 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
 }
 
 static ECalComponentDateTime*
-build_component_from_datetime (GcalEvent    *self,
-                               icaltimezone *current_tz,
-                               GDateTime    *dt)
+build_component_from_datetime (GcalEvent *self,
+                               GDateTime *dt)
 {
   ECalComponentDateTime *comp_dt;
+  gchar *tzid;
 
   if (!dt)
     return NULL;
@@ -234,12 +234,15 @@ build_component_from_datetime (GcalEvent    *self,
   comp_dt->value = NULL;
   comp_dt->tzid = NULL;
 
+  tzid = g_date_time_format (dt, "%Z");
+
   comp_dt->value = datetime_to_icaltime (dt);
-  comp_dt->value->zone = self->all_day ? icaltimezone_get_utc_timezone () : current_tz;
+  comp_dt->value->zone = icaltimezone_get_builtin_timezone_from_tzid (tzid);
   comp_dt->value->is_date = self->all_day;
 
-  /* All day events have UTC timezone */
-  comp_dt->tzid = g_strdup (self->all_day ? "UTC" : icaltimezone_get_tzid (current_tz));
+  /* All day events have no timezone */
+  if (!self->all_day)
+    comp_dt->tzid = tzid;
 
   return comp_dt;
 }
@@ -987,25 +990,19 @@ gcal_event_set_date_end (GcalEvent *self,
 
   if (self->dt_end != dt)
     {
-      ECalComponentDateTime *component_dt, current;
+      ECalComponentDateTime *component_dt;
 
       g_clear_pointer (&self->dt_end, g_date_time_unref);
       self->dt_end = g_date_time_ref (dt);
 
-      /* Retrieve the current timezone */
-      e_cal_component_get_dtstart (self->component, &current);
-
       /* Setup the ECalComponent's datetime value */
-      component_dt = build_component_from_datetime (self,
-                                                    icaltimezone_get_builtin_timezone_from_tzid 
(current.tzid),
-                                                    dt);
+      component_dt = build_component_from_datetime (self, dt);
 
       e_cal_component_set_dtend (self->component, component_dt);
       e_cal_component_commit_sequence (self->component);
 
       g_object_notify (G_OBJECT (self), "date-end");
 
-      e_cal_component_free_datetime (&current);
       e_cal_component_free_datetime (component_dt);
       g_free (component_dt);
     }
@@ -1042,25 +1039,19 @@ gcal_event_set_date_start (GcalEvent *self,
 
   if (self->dt_start != dt)
     {
-      ECalComponentDateTime *component_dt, current;
+      ECalComponentDateTime *component_dt;
 
       g_clear_pointer (&self->dt_start, g_date_time_unref);
       self->dt_start = g_date_time_ref (dt);
 
-      /* Retrieve the current timezone */
-      e_cal_component_get_dtstart (self->component, &current);
-
       /* Setup the ECalComponent's datetime value */
-      component_dt = build_component_from_datetime (self,
-                                                    icaltimezone_get_builtin_timezone_from_tzid 
(current.tzid),
-                                                    dt);
+      component_dt = build_component_from_datetime (self, dt);
 
       e_cal_component_set_dtstart (self->component, component_dt);
       e_cal_component_commit_sequence (self->component);
 
       g_object_notify (G_OBJECT (self), "date-start");
 
-      e_cal_component_free_datetime (&current);
       e_cal_component_free_datetime (component_dt);
       g_free (component_dt);
     }


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