From 13ef33ae0a82167000351969c5c05388a0ff412a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Thu, 19 Mar 2020 20:48:12 +0100 Subject: [PATCH] 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 cdbe0ac41..14a0ef48d 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;