[geary/mjog/fix-timezone-deprecation: 139/140] engine: Fix GLib.Timezone deprecation warning in GLib 2.68




commit d230ff4b42ec7f4f71b213f895a0bbf50cb545c7
Author: Michael Gratton <mike vee net>
Date:   Tue Apr 6 12:36:46 2021 +1000

    engine: Fix GLib.Timezone deprecation warning in GLib 2.68

 meson.build                                     |  2 +-
 src/engine/imap/message/imap-internal-date.vala | 25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/meson.build b/meson.build
index 92b987925..6a8cc952a 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 e90e23d0c..d2aa96e4b 100644
--- a/src/engine/imap/message/imap-internal-date.vala
+++ b/src/engine/imap/message/imap-internal-date.vala
@@ -79,14 +79,25 @@ 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
-
-        // if no timezone listed, ISO 8601 says to use local time
-        TimeZone timezone = (tz[0] != '\0') ? new TimeZone((string) tz) : new TimeZone.local();
+        GLib.TimeZone? timezone = null;
+        if (tz[0] != '\0') {
+            string tz_string = (string) tz;
+            timezone = new GLib.TimeZone.identifier(tz_string);
+            if (timezone == null) {
+                warning("Invalid INTERNALDATE timezone \"%s\"", tz_string);
+            }
+        }
+        if (timezone == null) {
+            // If no timezone listed, ISO 8601 says to use local time.
+            timezone = new GLib.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);
     }


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