[gnome-shell] dateMenu: Clean up timezone offset calculation a bit



commit 13ef33ae0a82167000351969c5c05388a0ff412a
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Thu Mar 19 20:48:12 2020 +0100

    dateMenu: Clean up timezone offset calculation a bit
    
    Use const variables and change some names to make showing minute-offsets
    in the next commit a bit more straightforward.
    
    https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1107

 js/ui/dateMenu.js | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index cdbe0ac415..14a0ef48d6 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -180,14 +180,19 @@ class WorldClocksSection extends St.Button {
 
             let time = new St.Label({ style_class: 'world-clocks-time' });
 
-            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',
-                                    text: fmt.format(prefix, Math.abs(offset)),
-                                    x_align: Clutter.ActorAlign.END,
-                                    y_align: Clutter.ActorAlign.CENTER });
+            const utcOffset = this._getTimeAtLocation(l).get_utc_offset();
+            const offsetCurrentTz = utcOffset - localOffset;
+            const offsetHours = offsetCurrentTz / GLib.TIME_SPAN_HOUR;
+
+            const fmt = Math.trunc(offsetHours) == offsetHours ? '%s%.0f' : '%s%.1f';
+            const prefix = offsetCurrentTz >= 0 ? '+' : '-';
+
+            const tz = new St.Label({
+                style_class: 'world-clocks-timezone',
+                text: fmt.format(prefix, Math.abs(offsetHours)),
+                x_align: Clutter.ActorAlign.END,
+                y_align: Clutter.ActorAlign.CENTER,
+            });
 
             time.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
             tz.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;


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