Skip to content

Commit

Permalink
InternetTimeApplet@stefan: Fix timezone for accurate Beat Time calcul…
Browse files Browse the repository at this point in the history
…ation (#5004)

* Fix timezone
Change the hour/minute/second variable assignments to explicitly be in UTC format. Also, add one hour to the "getUTCHours()" call, as the "Biel Mean Time" (BMT) which Beat Time is based upon, is defined by Swatch as UTC+1.

Previously this was calling Date's getHours/getMinutes/getSeconds functions, which returns LOCAL time. This had the effect of meaning the Beat time returned by this desklet was always incorrect unless your computer's time is set to the UTC+1 timezone.

This commit fixes that and ensures that the correct universal Beat Time will be displayed regardless of the user's timezone.

* Fix formatting
Change formatting to match original applet
  • Loading branch information
christopher-conley authored Aug 16, 2023
1 parent 5668592 commit 6610260
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ NetBeatApplet.prototype = {

refresh: function() {
let d = new Date();
let h = d.getHours();
let m = d.getMinutes();
let s = d.getSeconds();
let tzoff = 60 + d.getTimezoneOffset();
let beats = ('000' + Math.floor((s + (m + tzoff) * 60 + h * 3600) / 86.4) % 1000).slice(-3);
let h = d.getUTCHours() + 1;
let m = d.getUTCMinutes();
let s = d.getUTCSeconds();
//let tzoff = 60 + d.getTimezoneOffset();
//let beats = ('000' + Math.floor((s + (m + tzoff) * 60 + h * 3600) / 86.4) % 1000).slice(-3);

// calculation fix
let beatSecs = (s + m * 60 + h * 3600);
let netBeats = beatSecs / 86.4;
let beats = ("000" + parseInt(netBeats)).slice(-3);

this.set_applet_label(_("@" + beats));
// only update, if the applet is running
return this.keepUpdating;
Expand Down

0 comments on commit 6610260

Please sign in to comment.