From 42fa8c9f0a0673835a9c63ede5bdf20e8bb86c4f Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Tue, 6 Apr 2021 12:36:46 +1000 Subject: [PATCH] engine: Fix GLib.Timezone deprecation warning in GLib 2.68 --- meson.build | 2 +- .../imap/message/imap-internal-date.vala | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index ae8a84c7..1be205e3 100644 --- a/meson.build +++ b/meson.build @@ -53,7 +53,7 @@ valac = meson.get_compiler('vala') # Required libraries and other dependencies # -target_glib = '2.66' +target_glib = '2.68' target_gtk = '3.24.23' target_vala = '0.48.18' target_webkit = '2.30' diff --git a/src/engine/imap/message/imap-internal-date.vala b/src/engine/imap/message/imap-internal-date.vala index e90e23d0..e89b99c0 100644 --- a/src/engine/imap/message/imap-internal-date.vala +++ b/src/engine/imap/message/imap-internal-date.vala @@ -79,14 +79,26 @@ public class Geary.Imap.InternalDate : Geary.MessageData.AbstractMessageData, Ge if (month < 0) throw new ImapError.PARSE_ERROR("Invalid INTERNALDATE \"%s\": bad month", internaldate); - // TODO: verify timezone + GLib.TimeZone? timezone = null; + if (tz[0] != '\0') { + string tz_string = (string) tz; + try { + timezone = new GLib.TimeZone.identifier(tz_string); + } catch (GLib.Error err) { + warning("Invalid INTERNALDATE timezone \"%s\", %s", tz_string, err.message); + } + } + if (timezone == null) { + // If no timezone listed, ISO 8601 says to use local time. + timezone = new GLib.TimeZone.local(); + } - // if no timezone listed, ISO 8601 says to use local time - TimeZone timezone = (tz[0] != '\0') ? new TimeZone((string) tz) : new TimeZone.local(); - - // assemble into DateTime, which validates the time as well (this is why we want to keep - // original around, for other reasons) ... month is 1-based in DateTime - DateTime datetime = new DateTime(timezone, year, month + 1, day, hour, min, sec); + // assemble into DateTime, which validates the time as well + // (this is why we want to keep original around, for other + // reasons) ... month is 1-based in DateTime + var datetime = new GLib.DateTime( + timezone, year, month + 1, day, hour, min, sec + ); return new InternalDate(internaldate, datetime); }