[gnome-clocks] Port GWeatherTimezone to GTimeZone



commit c618e46cb942224e1e37fc9ddd8187bc5e2b5b34
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Mon Dec 13 14:45:43 2021 +0100

    Port GWeatherTimezone to GTimeZone

 src/geocoding.vala                 | 15 +++++++--------
 src/world-face.vala                | 15 ++++++++-------
 src/world-location-dialog-row.vala | 27 +++++++++++++--------------
 src/world-location-dialog.vala     |  9 ++++-----
 4 files changed, 32 insertions(+), 34 deletions(-)
---
diff --git a/src/geocoding.vala b/src/geocoding.vala
index ba6d6a92..c2b38200 100644
--- a/src/geocoding.vala
+++ b/src/geocoding.vala
@@ -134,14 +134,13 @@ public class Info : Object {
                 var timezone = location.get_timezone ();
                 var found_timezone = ((GWeather.Location) found_location).get_timezone ();
 
-                // TODO GTK 4
-                // if (timezone != null && found_timezone != null) {
-                //     var tzid = ((GWeather.Timezone) timezone).get_tzid ();
-                //     var found_tzid = ((GWeather.Timezone) found_timezone).get_tzid ();
-                //     if (tzid == found_tzid) {
-                //         return true;
-                //     }
-                // }
+                if (timezone != null && found_timezone != null) {
+                    var tzid = timezone.get_identifier ();
+                    var found_tzid = found_timezone.get_identifier ();
+                    if (tzid == found_tzid) {
+                        return true;
+                    }
+                }
             }
         }
 
diff --git a/src/world-face.vala b/src/world-face.vala
index 2701bd93..409655a5 100644
--- a/src/world-face.vala
+++ b/src/world-face.vala
@@ -47,13 +47,14 @@ public class Face : Adw.Bin, Clocks.Clock {
         settings = new GLib.Settings ("org.gnome.clocks");
 
         locations.set_sorting ((item1, item2) => {
-            // TODO GTK 4
-            // var offset1 = ((GWeather.Timezone) ((Item) item1).location.get_timezone ()).get_offset ();
-            // var offset2 = ((GWeather.Timezone) ((Item) item2).location.get_timezone ()).get_offset ();
-            // if (offset1 < offset2)
-            //     return -1;
-            // if (offset1 > offset2)
-            //     return 1;
+            var interval1 = ((Item) item1).location.get_timezone ().find_interval (GLib.TimeType.UNIVERSAL, 
Gdk.CURRENT_TIME);
+            var offset1 = ((Item) item1).location.get_timezone ().get_offset (interval1);
+            var interval2 = ((Item) item2).location.get_timezone ().find_interval (GLib.TimeType.UNIVERSAL, 
Gdk.CURRENT_TIME);
+            var offset2 = ((Item) item2).location.get_timezone ().get_offset (interval2);
+            if (offset1 < offset2)
+                return -1;
+            if (offset1 > offset2)
+                return 1;
             return 0;
         });
 
diff --git a/src/world-location-dialog-row.vala b/src/world-location-dialog-row.vala
index 47dd8686..b01b35b0 100644
--- a/src/world-location-dialog-row.vala
+++ b/src/world-location-dialog-row.vala
@@ -36,20 +36,19 @@ private class LocationDialogRow : Gtk.ListBoxRow {
 
         var wallclock = Utils.WallClock.get_default ();
         var local_time = wallclock.date_time;
-        var weather_time_zone = data.location.get_timezone ();
-        if (weather_time_zone != null) {
-            // TODO GTK 4
-            // var time_zone = new TimeZone.identifier (((GWeather.Timezone) weather_time_zone).get_tzid ());
-            // var date_time = local_time.to_timezone (time_zone);
-            // var local_offset = local_time.get_utc_offset () - date_time.get_utc_offset ();
-            // var time_diff_message = Utils.get_time_difference_message (local_offset);
-            // var time_zone_name = ((GWeather.Timezone) weather_time_zone).get_name ();
-            //
-            // if ((string?) time_zone_name != null) {
-            //     clock_description = "%s • %s".printf (time_zone_name, time_diff_message);
-            // } else {
-            //     clock_description = "%s".printf (time_diff_message);
-            // }
+        var time_zone = data.location.get_timezone ();
+        if (time_zone != null) {
+            var date_time = local_time.to_timezone (time_zone);
+            var local_offset = local_time.get_utc_offset () - date_time.get_utc_offset ();
+            var time_diff_message = Utils.get_time_difference_message (local_offset);
+            // The time zone uses underscore instead of spaces.
+            var time_zone_name = time_zone.get_identifier ().replace ("_", " ");
+
+            if ((string?) time_zone_name != null) {
+                clock_description = "%s • %s".printf (time_zone_name, time_diff_message);
+            } else {
+                clock_description = "%s".printf (time_diff_message);
+            }
         } else {
             clock_description = null;
         }
diff --git a/src/world-location-dialog.vala b/src/world-location-dialog.vala
index f90dd128..b4859918 100644
--- a/src/world-location-dialog.vala
+++ b/src/world-location-dialog.vala
@@ -153,11 +153,10 @@ private class LocationDialog : Gtk.Window {
                 string? timezone_name = null;
                 var timezone = location.get_timezone ();
                 if (timezone != null) {
-                    // TODO GTK 4
-                    // timezone_name = ((GWeather.Timezone) timezone).get_name ();
-                    // if (timezone_name != null) {
-                    //     timezone_name = ((string) timezone_name).normalize ().casefold ();
-                    // }
+                    timezone_name = timezone.get_identifier ();
+                    if (timezone_name != null) {
+                        timezone_name = ((string) timezone_name).normalize ().casefold ();
+                    }
                 }
                 var contains_timezone_name = timezone_name != null && ((string) timezone_name).contains 
(search);
 


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