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
This commit is contained in:
Jonas Dreßler 2020-03-19 20:48:12 +01:00 committed by Florian Müllner
parent f8886468ce
commit 13ef33ae0a

View File

@ -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;