[evolution-ews] Microsoft365: Correct task Due and Completed date read
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Microsoft365: Correct task Due and Completed date read
- Date: Thu, 6 Oct 2022 08:00:35 +0000 (UTC)
commit 4b618674c7f69783288e789c16d5a1f56a04d0bf
Author: Milan Crha <mcrha redhat com>
Date: Thu Oct 6 09:58:19 2022 +0200
Microsoft365: Correct task Due and Completed date read
They are stored as date/time in UTC, which needs to be converted
to the user time zone and then to a date, to show the right value.
.../calendar/e-cal-backend-m365-utils.c | 37 +++++++++++++++-------
src/Microsoft365/common/e-m365-tz-utils.c | 26 +++++++++++++++
src/Microsoft365/common/e-m365-tz-utils.h | 2 ++
3 files changed, 54 insertions(+), 11 deletions(-)
---
diff --git a/src/Microsoft365/calendar/e-cal-backend-m365-utils.c
b/src/Microsoft365/calendar/e-cal-backend-m365-utils.c
index 6829a656..373fa277 100644
--- a/src/Microsoft365/calendar/e-cal-backend-m365-utils.c
+++ b/src/Microsoft365/calendar/e-cal-backend-m365-utils.c
@@ -116,6 +116,7 @@ ecb_m365_get_date_time_zone (EM365Connection *cnc,
ICalTime *itt;
time_t tt;
const gchar *tzid, *zone;
+ gboolean use_user_timezone = FALSE;
gboolean is_date;
if (prop_kind == I_CAL_DTSTART_PROPERTY) {
@@ -129,6 +130,7 @@ ecb_m365_get_date_time_zone (EM365Connection *cnc,
value = e_m365_task_get_start_date_time (m365_object);
tzid = "UTC";
is_date = TRUE;
+ use_user_timezone = TRUE;
break;
default:
g_warn_if_reached ();
@@ -142,10 +144,12 @@ ecb_m365_get_date_time_zone (EM365Connection *cnc,
value = e_m365_task_get_completed_date_time (m365_object);
tzid = "UTC";
is_date = TRUE;
+ use_user_timezone = TRUE;
} else if (prop_kind == I_CAL_DUE_PROPERTY) {
value = e_m365_task_get_due_date_time (m365_object);
tzid = "UTC";
is_date = TRUE;
+ use_user_timezone = TRUE;
} else {
g_warn_if_reached ();
return;
@@ -155,27 +159,38 @@ ecb_m365_get_date_time_zone (EM365Connection *cnc,
return;
tt = e_m365_date_time_get_date_time (value);
- zone = e_m365_date_time_get_time_zone (value);
+ if (use_user_timezone) {
+ tz = e_m365_tz_utils_get_user_timezone ();
+ } else {
+ zone = e_m365_date_time_get_time_zone (value);
- if (zone && *zone)
- zone = e_m365_tz_utils_get_ical_equivalent (zone);
+ if (zone && *zone)
+ zone = e_m365_tz_utils_get_ical_equivalent (zone);
- tz = zone && *zone ? e_timezone_cache_get_timezone (timezone_cache, zone) : NULL;
+ tz = zone && *zone ? e_timezone_cache_get_timezone (timezone_cache, zone) : NULL;
+ }
if (!tz)
tz = i_cal_timezone_get_utc_timezone ();
- itt = i_cal_time_new_from_timet_with_zone (tt, is_date, tz);
+ itt = i_cal_time_new_from_timet_with_zone (tt, is_date && !use_user_timezone, tz);
- tzid = e_m365_tz_utils_get_ical_equivalent (tzid);
+ if (is_date && use_user_timezone)
+ i_cal_time_set_is_date (itt, TRUE);
- if (!tzid)
- tzid = "UTC";
+ i_cal_time_set_timezone (itt, tz);
- tz = e_timezone_cache_get_timezone (timezone_cache, tzid);
+ if (!is_date) {
+ tzid = e_m365_tz_utils_get_ical_equivalent (tzid);
- if (tz && !is_date)
- i_cal_time_convert_to_zone_inplace (itt, tz);
+ if (!tzid)
+ tzid = "UTC";
+
+ tz = e_timezone_cache_get_timezone (timezone_cache, tzid);
+
+ if (tz && !is_date)
+ i_cal_time_convert_to_zone_inplace (itt, tz);
+ }
if (prop_kind == I_CAL_DTSTART_PROPERTY)
i_cal_component_set_dtstart (inout_comp, itt);
diff --git a/src/Microsoft365/common/e-m365-tz-utils.c b/src/Microsoft365/common/e-m365-tz-utils.c
index bc0cf6bd..7a1d7f40 100644
--- a/src/Microsoft365/common/e-m365-tz-utils.c
+++ b/src/Microsoft365/common/e-m365-tz-utils.c
@@ -11,6 +11,8 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
+#include <gio/gio.h>
+
#include "e-m365-tz-utils.h"
/*
@@ -182,3 +184,27 @@ e_m365_tz_utils_get_ical_equivalent (const gchar *msdn_tz_location)
return ical_tz_location;
}
+
+ICalTimezone *
+e_m365_tz_utils_get_user_timezone (void)
+{
+ GSettings *settings;
+ gchar *location;
+ ICalTimezone *zone = NULL;
+
+ settings = g_settings_new ("org.gnome.evolution.calendar");
+
+ if (g_settings_get_boolean (settings, "use-system-timezone"))
+ location = e_cal_util_get_system_timezone_location ();
+ else
+ location = g_settings_get_string (settings, "timezone");
+
+ g_object_unref (settings);
+
+ if (location)
+ zone = i_cal_timezone_get_builtin_timezone (location);
+
+ g_free (location);
+
+ return zone;
+}
diff --git a/src/Microsoft365/common/e-m365-tz-utils.h b/src/Microsoft365/common/e-m365-tz-utils.h
index 0aa6002c..c6351800 100644
--- a/src/Microsoft365/common/e-m365-tz-utils.h
+++ b/src/Microsoft365/common/e-m365-tz-utils.h
@@ -8,6 +8,7 @@
#define E_M365_TZ_UTILS_H
#include <glib.h>
+#include <libecal/libecal.h>
G_BEGIN_DECLS
@@ -15,6 +16,7 @@ void e_m365_tz_utils_ref_windows_zones (void);
void e_m365_tz_utils_unref_windows_zones (void);
const gchar * e_m365_tz_utils_get_msdn_equivalent (const gchar *ical_tz_location);
const gchar * e_m365_tz_utils_get_ical_equivalent (const gchar *msdn_tz_location);
+ICalTimezone * e_m365_tz_utils_get_user_timezone (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]