su-fit-vut / kachna-online

Students' Club U Kachničky: Member's portal
MIT License
5 stars 5 forks source link

Handle time zones properly #55

Closed ondryaso closed 7 months ago

ondryaso commented 2 years ago

The system currently does not care about time zones at all. In the backend, all dates and times are handled as if they were in the current timezone (there's even a Npgsql override that ensures this).

The .toISOString() method of JS Date objects returns the date in UTC without timezone (suffixed with 'Z'), which is, frankly, not incorrect. However, in the backend, we work with such dates as if they were in the backend's timezone. When serializing dates, they carry no time zone information.

In the frontend, this leads to a mess where dates sent to the API must be adjusted using something like this:

dateObj?.setTime(dateObj?.getTime() - dateObj?.getTimezoneOffset() * 60000);

Necessary steps: