Issue #27: Use client timezone when OWM API is not used

This commit is contained in:
Dale Davies
2022-04-20 09:26:51 +01:00
parent 7eb7a6b973
commit 0e2982b18d
3 changed files with 15 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -14,11 +14,12 @@ export default class Clock {
* @param boolean ampm Return 12 hour format if true.
* @param number utcshift Number of seconds to shift time from UTC.
*/
constructor(eventemitter, ampm = false) {
constructor(eventemitter, ampm = false, forcelocaltime = false) {
this.set_utc_shift();
this.contentintervalid = null;
this.eventemitter = eventemitter;
this.ampm = ampm;
this.forcelocaltime = forcelocaltime;
}
set_utc_shift(newutcshift = 0) {
@@ -37,7 +38,14 @@ export default class Clock {
// the Date() object adjusting the returned time relative to the
// browser's local timezone.
let hour = this.shifteddate.getUTCHours();
const minutes = String(this.shifteddate.getUTCMinutes()).padStart(2, '0');
let minutes = String(this.shifteddate.getUTCMinutes()).padStart(2, '0');
// Completely ignore the shifted date and just return whatever happens to be
// in the local timezone.
if (this.forcelocaltime) {
hour = new Date().getHours();
minutes = String(new Date().getMinutes()).padStart(2, '0');
}
if (!this.ampm) {
return String(hour).padStart(2, '0') + ":" + minutes;
@@ -54,6 +62,9 @@ export default class Clock {
* @returns number The hour.
*/
get_hour() {
if (this.forcelocaltime) {
return new Date().getHours();
}
return this.shifteddate.getUTCHours();
}

View File

@@ -30,7 +30,7 @@ export default class Main {
}
// Finally create instances of the classes we'll be using.
this.eventemitter = new EventEmitter();
this.clock = new Clock(this.eventemitter, !!JUMP.ampmclock);
this.clock = new Clock(this.eventemitter, !!JUMP.ampmclock, !JUMP.owmapikey);
this.weather = new Weather(this.eventemitter);
}