Open NikolayKash opened 2 years ago
This is indeed a problem.
The persistence endpoint returns epoch-based timestamps which are not fixed to a timezone. Cf. https://github.com/openhab/openhab-core/blob/2bceba69549c6017485e5089c64d6131889aa76a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java#L340 Example:
... {"time":1667834340000,"state":"590"},{"time":1667834400000,"state":"600"} ...
So they are sent as local time by the server and interpreted as local time by the client (the UI).
It's a bit convoluted to figure out if the timezones are different and perform the conversion (the server's timezone isn't always accessible).
ECharts has an open issue about this: https://github.com/apache/echarts/issues/14453
Alternatively, one of these could be sent along with the request to the persistence endpoint to make the server aware of the client's timezone:
so it could take it into account and return timestamps converted to the client's timezone. There is no HTTP request header automatically sent by browsers which includes the local timezone so it would have to be in the request body's payload.
Of course, ideally proper timezone-aware date strings could be returned in these time
fields instead of the UNIX timestamps (ECharts would interpret them properly I think) but this is API-breaking and potentially performance-hitting.
Also note that charts without a fixed period - so-called "dynamic" periods - always end by default to the current date & time, in the local timezone, in this case it might not match the end of the historical data.
@openhab/core-maintainers wdyt?
@ghys
the server's timezone isn't always accessible
I think we have to relay on time zone set here settings/services/org.openhab.i18n and use this time zone to show datetime, as well to show 12/24 hours this api http://xxxxx:8080/rest/services/org.openhab.i18n/config
This is not only related to analyzer view, also schedule (/settings/schedule/) view affected by this issue
this api http://xxxxx:8080/rest/services/org.openhab.i18n/config
This is what I meant by "not always accessible"; /rest/services
is an admin endpoint. That's why it makes sense to let the server do the conversions (either to the requesting client's local timezone or to UTC).
The persistence endpoint returns epoch-based timestamps which are not fixed to a timezone. Cf. https://github.com/openhab/openhab-core/blob/2bceba69549c6017485e5089c64d6131889aa76a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/persistence/PersistenceResource.java#L340 Example:
... {"time":1667834340000,"state":"590"},{"time":1667834400000,"state":"600"} ...
So they are sent as local time by the server and interpreted as local time by the client (the UI).
I don't think this is correct. If I understand the code the timestamps are always epoch timestamps which denote a certain point in time (relative to 1970-01-01 00:00:00 UTC). So the client can always convert them to the timezone that is needed, without knowing the server timestamp.
Also the /persistence
endpoints of the REST API allow transmitting a timezone together with begin/end values (e.g. 2023-05-20T20:00:00.000+02:00
).
Also note that charts without a fixed period - so-called "dynamic" periods - always end by default to the current date & time, in the local timezone, in this case it might not match the end of the historical data.
For charts we should probably transmit a timezone that shall be used.
The problem
See topic here https://community.openhab.org/t/oh3-main-ui-taking-into-account-server-time-zone-not-browser-time-zone/140177
Expected behavior
Shows all graphs in home's location time zone and do not take into account the computer timezone
Steps to reproduce
Your environment
Browser console
Browser network traffic
Additional information