[gnome-shell] dateMenu: Make clock offsets relative to local time



commit 2fab75f44871bb30c2dfec7ed49989db85ef0759
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Apr 11 11:36:33 2019 +0200

    dateMenu: Make clock offsets relative to local time
    
    We recently added offsets to world clocks that represent the location's
    timezone as UTC offset. However for most users, that representation is
    overly technical and less helpful than the difference to their local time.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/issues/1157

 js/ui/dateMenu.js | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index f46ed2d3a..fb32fbb2f 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -136,6 +136,8 @@ var WorldClocksSection = class WorldClocksSection {
         layout.attach(header, 0, 0, 2, 1);
         this.actor.label_actor = header;
 
+        let localOffset = GLib.DateTime.new_now_local().get_utc_offset();
+
         for (let i = 0; i < this._locations.length; i++) {
             let l = this._locations[i].location;
 
@@ -148,7 +150,8 @@ var WorldClocksSection = class WorldClocksSection {
 
             let time = new St.Label({ style_class: 'world-clocks-time' });
 
-            let offset = l.get_timezone().get_offset() / 60.;
+            let otherOffset = this._getTimeAtLocation(l).get_utc_offset();
+            let offset = (otherOffset - localOffset) / GLib.TIME_SPAN_HOUR;
             let fmt = (Math.trunc(offset) == offset) ? '%s%.0f' : '%s%.1f';
             let prefix = (offset >= 0) ? '+' : '-';
             let tz = new St.Label({ style_class: 'world-clocks-timezone',
@@ -181,11 +184,15 @@ var WorldClocksSection = class WorldClocksSection {
         }
     }
 
+    _getTimeAtLocation(location) {
+        let tz = GLib.TimeZone.new(location.get_timezone().get_tzid());
+        return GLib.DateTime.new_now(tz);
+    }
+
     _updateLabels() {
         for (let i = 0; i < this._locations.length; i++) {
             let l = this._locations[i];
-            let tz = GLib.TimeZone.new(l.location.get_timezone().get_tzid());
-            let now = GLib.DateTime.new_now(tz);
+            let now = this._getTimeAtLocation(l.location);
             l.actor.text = Util.formatTime(now, { timeOnly: true });
         }
     }


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