esp-rfid icon indicating copy to clipboard operation
esp-rfid copied to clipboard

Refine Timezones

Open proddy opened this issue 6 years ago • 11 comments

The timezone pull-down selection doesn't work for me so I started to look into the code. The timezone selected from the Web UI and stored in the SPIFFS config file is never used in the code, so device time will always be 1 hour + UTC. Is this intentional or is the implementation not finished?

proddy avatar Aug 02 '19 14:08 proddy

Hmm, this sounds completely not intentional, on the other hand I remember debugging a Browser issue, I might be forgot to revert code after testing.

Good finding, I will check it. Thanks

omersiar avatar Aug 02 '19 14:08 omersiar

ok! thought it was me. Thanks and let me know if I can help out with testing or coding.

proddy avatar Aug 02 '19 15:08 proddy

Looking at the code again the timezone is taken from the browser (in the JS) so you don't really need to explicitly set a timezone. I think the whole section in the html and config can be removed. Do you agree?

proddy avatar Aug 16 '19 19:08 proddy

Internally, time is being tracked as Unix Time which is then adjusted to User's timezone on Web UI. You need to set timezone in order to list entries in the log correctly.

omersiar avatar Aug 18 '19 09:08 omersiar

Yes, time from NTP is in UTC and when viewed in the event log it's adjusted on the fly to the web browsers's timezone with the code:

var comp = new Date();
value = Math.floor(value + ((comp.getTimezoneOffset() * 60) * -1));

So you don't need to explicitly set a timezone. In fact it's not even used anywhere in the code so can be removed from the web interface and config file.

proddy avatar Aug 18 '19 09:08 proddy

You are right for the frontend, on firmware level timezone setting is used.

https://github.com/esprfid/esp-rfid/blob/162a7fff662833154172f9defcf382c4be0b0336/src/Ntp.cpp#L23

omersiar avatar Aug 18 '19 09:08 omersiar

https://github.com/esprfid/esp-rfid/issues/116

omersiar avatar Aug 18 '19 09:08 omersiar

yes it's set in ntp.cpp but never used - that's my point. Sorry if I wasn't clear in the beginning. The time is always saved in UTC.

However if you do want to convert the UTC to the correct timezone and handle DST (daylight saving times) in the firmware, I have extended the NTP code to use this library which works. But now I'm thinking its not really necessary since the only time the Date is ever displayed is in the web interface and JavaScript can do the real-time conversions quite nicely.

proddy avatar Aug 18 '19 10:08 proddy

Oh, now I understand, sorry for the inconvenience. I just need to refactor these functions and libraries.

omersiar avatar Aug 26 '19 11:08 omersiar

Time also does not persist during reboot, see images device_date

peteshoard avatar Sep 06 '19 16:09 peteshoard

Fixed by #604

matjack1 avatar Oct 27 '23 10:10 matjack1