gnmyt / myspeed

A speed test analysis software that shows your internet speed for up to 30 days
https://myspeed.dev
MIT License
676 stars 30 forks source link

[Bug] Time zone in cron job and Test Statistics page use UTC time. Test Overview uses local time. #464

Closed radbasa closed 5 months ago

radbasa commented 11 months ago

General

The Bug

The "Test Overview" page shows local time correctly.

The "Test Statistics" page shows UTC time.

The cron job uses UTC time. I use 17 */3 * * *

The MySpeed storage.db contains:

sqlite> SELECT * FROM speedtests;
3|2|626.27|626.38||auto|20|2023-11-18T15:17:22.150Z
4|2|623.86|626.49||auto|20|2023-11-18T18:17:22.092Z
5|2|626.37|626.38||auto|20|2023-11-18T21:17:22.039Z
6|2|626.61|626.39||auto|20|2023-11-19T00:17:22.462Z
7|2|626.28|626.37||auto|20|2023-11-19T03:17:22.571Z
8|2|625.12|626.25||custom|20|2023-11-19T04:27:43.841Z
sqlite> 

Which confirms that the cronjob runs on UTC.

The last result was started manually. The "Test Overview" page shows the local time of "12:27". But, the "Test Statistics" shows the result as "04:27" which is UTC.

The following are from the host OS (Debian 12):

$ date
Sunday, 19 November, 2023 12:27:47 PM PST
$ timedatectl 
               Local time: Sun 2023-11-19 12:27:48 PST
           Universal time: Sun 2023-11-19 04:27:48 UTC
                 RTC time: Sun 2023-11-19 04:27:48
                Time zone: Asia/Manila (PST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
$ sudo hwclock
2023-11-19 12:27:50.874289+08:00

I am running MySpeed using the germannewsmaker/myspeed 1.0.8 Docker container.

What device are you using to access the page?

In the browser

Which operating system is your MySpeed instance running on?

Linux

gnmyt commented 11 months ago

Sorry for the delay. I'm gonna take a look into that :)

LouwMarais commented 9 months ago

Seeing this same issue. typically in a docker running environment, an environment variable is supported so that for example we can add a timezone

"docker run -d -p 5216:5216 -v myspeed:/myspeed/data -e TZ=Australia/Brisbane --restart=unless-stopped --name MySpeed germannewsmaker/myspeed"

the fix would be to support this variable in your docker file ENV TZ=Etc/UTC https://github.com/gnmyt/myspeed/blob/development/Dockerfile

anyone can then override it to the timezone they want the application to run in.

gnmyt commented 5 months ago

I've created a PR to fix this issue. To make sure cronjobs run at the correct time, I've added support for the TZ variable. The Test Overview also now runs on browser-time instead of server time to make sure users from other time zones can see the test times correctly