[gnome-calendar/gbsneto/timezone-fixes: 1/3] event: Query client timezone on failure




commit eba09e0b7c71138830a2dc1119ed24582babe84d
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Dec 7 12:25:37 2021 -0300

    event: Query client timezone on failure
    
    If we can't find an appropriate timezone, query the ECalClient
    for it and give it an extra chance of finding the right timezone.
    
    Thanks to Milan Crha for proposing this fix.

 src/core/gcal-event.c | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)
---
diff --git a/src/core/gcal-event.c b/src/core/gcal-event.c
index e752abfe..717b4e23 100644
--- a/src/core/gcal-event.c
+++ b/src/core/gcal-event.c
@@ -148,11 +148,12 @@ clear_range (GcalEvent *self)
 }
 
 static GTimeZone*
-get_timezone_from_ical (ECalComponentDateTime *comp)
+get_timezone_from_ical (GcalEvent             *self,
+                        ECalComponentDateTime *comp)
 {
+  g_autoptr (GTimeZone) tz = NULL;
   ICalTimezone *zone;
   ICalTime *itt;
-  GTimeZone *tz;
 
   itt = e_cal_component_datetime_get_value (comp);
   zone = i_cal_time_get_timezone (itt);
@@ -168,16 +169,29 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
     }
   else if (e_cal_component_datetime_get_tzid (comp))
     {
-      const gchar *real_tzid;
+      const gchar *original_tzid, *tzid;
+
+      tzid = e_cal_component_datetime_get_tzid (comp);
+      original_tzid = tzid;
+
+      if (g_str_has_prefix (tzid, LIBICAL_TZID_PREFIX))
+        tzid += strlen (LIBICAL_TZID_PREFIX);
 
-      real_tzid = e_cal_component_datetime_get_tzid (comp);
+      tz = g_time_zone_new_identifier (tzid);
+
+      if (!tz && self->calendar)
+        {
+          ICalTimezone *tzone = NULL;
+          ECalClient *client;
 
-      if (g_str_has_prefix (real_tzid, LIBICAL_TZID_PREFIX))
-        real_tzid += strlen (LIBICAL_TZID_PREFIX);
+          client = gcal_calendar_get_client (self->calendar);
 
-      tz = g_time_zone_new_identifier (real_tzid);
+          if (client && e_cal_client_get_timezone_sync (client, original_tzid, &tzone, NULL, NULL))
+            zone = tzone;
+        }
     }
-  else if (zone)
+
+  if (!tz && zone)
     {
       g_autofree gchar *tzid = NULL;
       gint offset;
@@ -186,10 +200,6 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
       tzid = format_utc_offset (offset);
       tz = g_time_zone_new_identifier (tzid);
     }
-  else
-    {
-      tz = g_time_zone_new_utc ();
-    }
 
   /*
    * If tz is NULL, the timezone identifier is invalid. Fallback to UTC
@@ -200,7 +210,7 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
 
   GCAL_TRACE_MSG ("%s (%p)", g_time_zone_get_identifier (tz), tz);
 
-  return tz;
+  return g_steal_pointer (&tz);
 }
 
 static ECalComponentDateTime*
@@ -340,7 +350,7 @@ gcal_event_set_component_internal (GcalEvent     *self,
   GCAL_TRACE_MSG ("Retrieving start timezone");
 
   date = i_cal_time_normalize (e_cal_component_datetime_get_value (start));
-  zone_start = get_timezone_from_ical (start);
+  zone_start = get_timezone_from_ical (self, start);
   date_start = g_date_time_new (zone_start,
                                 i_cal_time_get_year (date),
                                 i_cal_time_get_month (date),
@@ -366,7 +376,7 @@ gcal_event_set_component_internal (GcalEvent     *self,
       GCAL_TRACE_MSG ("Retrieving end timezone");
 
       date = i_cal_time_normalize (e_cal_component_datetime_get_value (end));
-      zone_end = get_timezone_from_ical (end);
+      zone_end = get_timezone_from_ical (self, end);
       date_end = g_date_time_new (zone_end,
                                   i_cal_time_get_year (date),
                                   i_cal_time_get_month (date),


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