Sometimes the day of week displays incorrectly for timezone settings

Kruzya

Well-known member
Affected version
2.2.2
Few notices:
  • The default timezone for all users (include guests) on forum - GMT+3 (Moscow).
  • I live in Izhevsk, where timezone - GMT+4 (Samara).
  • On my PC in OS options, the timezone is GMT+4. On forum - GMT+3 (Moscow) for comfort performing moderator duties.
Sometimes in different parts of the forum, i can see "incorrect" day of week:
firefox_nsfPj5WzOZ.png
For example, on this screen you can see "Wednesday" as "01.12.2021" day of week. This is wrong: the right day of week for this date - Tuesday, but by unknown reason, forum displays Wednesday. It looks like JS uses OS settings for formatting day of week, because 11:15PM in my timezone - 12:15AM (next day, 01.13.2021).
If i refresh the page, first second after page refresh, i can see the right day of week ("Tuesday"), but it replaces to wrong ("Wednesday"). JS recalculates the date?..

I can reproduce this in any browser: Firefox, Chrome and even in Safari!
 
We use JS for displaying dates, and JS date/timezone handling is historically a nightmare. The good news is this is changing (slowly), so maybe we'll have an easier time with it in the future. As it is now, we rely on the OS timezone to calculate how dates appear so we generally expect them to match the account timezone, and if they don't then dates will be displayed in the OS timezone anyway.

https://developer.mozilla.org/en-US/blog/javascript-temporal-is-coming/#what_is_javascript_temporal
The major issues with JavaScript's Date object are that it only supports the user's local time and UTC, and there's no time zone support. Additionally, its parsing behavior is very unreliable, and Date itself is mutable, which can introduce hard-to-trace bugs. There are other problems like calculations across Daylight Saving Time (DST) and historical calendar changes, which are notoriously difficult to work with.
 
Just so you know there can be issues with nginx not pulling the right time zone, its not configured by default. So if whatever server you are on is using an ntp time service it will get the time of GMT +0 and not the time zone set in in the OS unless you enable it in the main nginx.conf.

Code:
autoindex_localtime on

I think you can also set it in your directives if you are using cpanel or similar.


As it is now, we rely on the OS timezone to calculate how dates appear so we generally expect them to match the account timezone
Do you know you are getting a true read from the OS? Or is it possible the issue above is passing the incorrect zone?
 
Last edited:
Back
Top Bottom