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.

Related: https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/444
This commit is contained in:
Georges Basile Stavracas Neto
2021-12-07 12:39:15 -03:00
parent d26f3fe01b
commit 0811242180
+25 -15
View File
@@ -148,11 +148,12 @@ clear_range (GcalEvent *self)
} }
static GTimeZone* static GTimeZone*
get_timezone_from_ical (ECalComponentDateTime *comp) get_timezone_from_ical (GcalEvent *self,
ECalComponentDateTime *comp)
{ {
g_autoptr (GTimeZone) tz = NULL;
ICalTimezone *zone; ICalTimezone *zone;
ICalTime *itt; ICalTime *itt;
GTimeZone *tz;
itt = e_cal_component_datetime_get_value (comp); itt = e_cal_component_datetime_get_value (comp);
zone = i_cal_time_get_timezone (itt); 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)) else if (e_cal_component_datetime_get_tzid (comp))
{ {
const gchar *real_tzid; const gchar *original_tzid, *tzid;
real_tzid = e_cal_component_datetime_get_tzid (comp); tzid = e_cal_component_datetime_get_tzid (comp);
original_tzid = tzid;
if (g_str_has_prefix (real_tzid, LIBICAL_TZID_PREFIX)) if (g_str_has_prefix (tzid, LIBICAL_TZID_PREFIX))
real_tzid += strlen (LIBICAL_TZID_PREFIX); tzid += strlen (LIBICAL_TZID_PREFIX);
tz = g_time_zone_new_identifier (real_tzid); tz = g_time_zone_new_identifier (tzid);
if (!tz && self->calendar)
{
ICalTimezone *tzone = NULL;
ECalClient *client;
client = gcal_calendar_get_client (self->calendar);
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; g_autofree gchar *tzid = NULL;
gint offset; gint offset;
@@ -186,10 +200,6 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
tzid = format_utc_offset (offset); tzid = format_utc_offset (offset);
tz = g_time_zone_new_identifier (tzid); 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 * 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); GCAL_TRACE_MSG ("%s (%p)", g_time_zone_get_identifier (tz), tz);
return tz; return g_steal_pointer (&tz);
} }
static ECalComponentDateTime* static ECalComponentDateTime*
@@ -340,7 +350,7 @@ gcal_event_set_component_internal (GcalEvent *self,
GCAL_TRACE_MSG ("Retrieving start timezone"); GCAL_TRACE_MSG ("Retrieving start timezone");
date = i_cal_time_normalize (e_cal_component_datetime_get_value (start)); 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, date_start = g_date_time_new (zone_start,
i_cal_time_get_year (date), i_cal_time_get_year (date),
i_cal_time_get_month (date), i_cal_time_get_month (date),
@@ -366,7 +376,7 @@ gcal_event_set_component_internal (GcalEvent *self,
GCAL_TRACE_MSG ("Retrieving end timezone"); GCAL_TRACE_MSG ("Retrieving end timezone");
date = i_cal_time_normalize (e_cal_component_datetime_get_value (end)); 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, date_end = g_date_time_new (zone_end,
i_cal_time_get_year (date), i_cal_time_get_year (date),
i_cal_time_get_month (date), i_cal_time_get_month (date),