mumblebaj / MMM-SweepClock

Sweep Clock for MagicMirror²
MIT License
4 stars 1 forks source link

Support for displaying time in a specified timezone #5

Closed RaymondJSpigot closed 3 weeks ago

RaymondJSpigot commented 3 weeks ago

I've tried out the MMM-SweepClock module and really like the clean look. Would it be possible to add support for timezones? Maybe just Europe/Zurich to begin with, since it's modelled on a Swiss Railway clock : )

I don't have much coding experience but had a go at adjusting the module a bit myself in the meantime. For a SweepClock with config: showDate = true I could get it to display the correct date in Zurich (my local time is Auckland, New Zealand, so this morning it showed yesterday's date) by adding a new config item in config/config.js

timeZone: "Europe/Zurich"

and then going

if (this.config.showDate) {
                        const dateWrapper = document.createElement("div")

                        const now = moment(); // adjust for timezone here if specified in config
                        if (this.config.timezone) {
            now.tz(this.config.timezone);
        }

So that seemed to work ok. Then I got stuck trying to update the time displayed on the clock itself though. Any updates would be great!

mumblebaj commented 3 weeks ago

Hi,

Thanks for the request. I have a solution for it. Just busy testing with or without timezone setting, Will push once I have completed testing.

mumblebaj commented 3 weeks ago

Hi @RaymondJSpigot

I have pushed the changes for the timezone. You can pull the latest changes v1.1.2 and this should work for what you would like to do.

Thanks BM

RaymondJSpigot commented 3 weeks ago

Hi @mumblebaj thanks very much for the quick update - I've pulled the latest version tried it out : )

On my test sweepclock I have showDate = true with a dateFormat: "ddd MMM D HH:mm" and it looks like the timezone is being applied to this line correctly when the sweepclock is displayed.

e.g. with a timezone: "Australia/Brisbane" (2 hours behind New Zealand) I can see that the showDate row displays 17:05 when it's 19:05 in NZ, so that looks good.

On start-up of the MagicMirror, the analogue sweepclock shows the time in Brisbane too (i.e. 5:05) but only until the second hand gets back to the 12 o'clock position - when the clock hands jump to show 7:06 (i.e. local time). The showDate row remains correct though.