-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong System Time in overview #20710
Comments
I can reproduce this, ouch! Thanks! I don't know (or at least remember) the history around the |
Agree, that makes sense in my opinion. And that's why I examined the code, as I thought I had something misconfigured on my side.
I stumbled upon this option while trying to figure out where the problem was. I'm not entirely sure if it solves the problem, but it looks promising. |
In commit 8465522 I got rid of the `ServerTime.format()` wrapper, and missed the `timeZone: "UTC"` option. This resulted in the Overview's "System time:" being wrong. Bring this back, but as that is generally useful, introduce a `timeformat.dateTimeUTC()` helper and add a unit test. Fixes cockpit-project#20710
Fixed in #20724 . This regression happened in the latest release 320, it'll get fixed in Wednesday's 321. Thanks for the report! |
In the overview page, the displayed System Time is wrong.
e.g. if the time zone is CEST (+2) and the correct time is 18:00, the displayed time is 20:00.
I took a quick look at the code, I see that time is retrieved using
date +%s:%z
.Running this in a shell, this indeed shows the correct time in epoch format (
+%s
), plus the time zone offset (%z
).The problem is that the
utc_fake_now
property is returned as anew Date(...)
object.cockpit/pkg/lib/serverTime.js
Lines 85 to 91 in 23701a5
JavaScript's Date object tracks time in UTC internally, but typically accepts input and produces output in the local time of the computer it's running on.
For example:
Using the online epoch converter, it shows that
1720088745200
equals to:Which shows that
new Date()
's output is indeed in the local time zone.The problem is that later on, the Date object is formatted without taking into account the local time zone:
cockpit/pkg/lib/timeformat.ts
Line 28 in 23701a5
Which eventually results in the wrong format.
I see various ways to solve this:
utc_fake_now
property as UTC epoch time (i.e. using.valueOf()
) and adjust the formatterutc_fake_now
as a UTC Date object stripped of the time zoneThe text was updated successfully, but these errors were encountered: