openhab-core icon indicating copy to clipboard operation
openhab-core copied to clipboard

Timezone setting not always applied

Open TheNinth7 opened this issue 2 years ago • 5 comments

I am running openHAB 3.4.0 in a Docker container on my Synology NAS, a DS420+ with DSM 7.1.1-42962 Update 1.

My timezone is GMT+1 (Vienna).

Time and timezone on the NAS is set correctly. I also set the timezone to GMT+1 Europe/Vienna in openHAB‘s regional settings.

Still, openHAB uses UTC/GMT as timezone. I noticed that on several places, the log file entries, the time returned by time.toZDT() in Javascripts, the last update time of my Shelly H&T sensors and the Karaf console, where “date” shows the UTC time.

When setting the timezone via EXTRA_JAVA_OPTS="-Duser.timezone=Europe/Vienna" for the Docker contajner it works and then times in all the above-mentioned places are correct.

TheNinth7 avatar Jan 22 '23 04:01 TheNinth7

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-running-in-docker-system-time-is-one-hour-behind/143637/4

openhab-bot avatar Jan 22 '23 04:01 openhab-bot

The Docker Container is isolated from the host. In short, it doesn't know what timezone your Syonlogy has. You need to tell the container what timezone to use. Often this is done by simply mounting /etc/timezone into the container. Or alternatively, you can set the timezone for the JRE using the EXTRA_JAVA_OPTS like you discovered.

This isn't an OH issue, it's a Docker issue. And if you look at https://www.openhab.org/docs/installation/docker.html and https://hub.docker.com/r/openhab/openhab/ you will notice that all the examples mount this file into the container and the first link discusses why.

At a minimum this needs to be moved to the openhab-docker repo but I believe this is already solved.

rkoshak avatar Jan 23 '23 18:01 rkoshak

Understood, but should not the timezone settings in the OH regional settings be applied?

TheNinth7 avatar Jan 25 '23 07:01 TheNinth7

That's used by some bindings but it does not override the OS nor the JRE timezone so those parts of OH which rely on third party stuff like log4j2 and karaf do not know nor would not know anything about the OH setting. And I'm sure if there were a way to have OH update the timezone for the JRE and OS from that setting, it would do so.

rkoshak avatar Jan 25 '23 15:01 rkoshak

Which APIs are the bindings supposed to use to get correct handling here?

(Given that java.util.TimeZone.getDefault() is not “it”?)

nagisa avatar Sep 25 '23 12:09 nagisa