TASVideos / tasvideos

The code for the live TASVideos website
https://tasvideos.org/
GNU General Public License v3.0
62 stars 29 forks source link

Timezone differences appear to be calculated incorrectly #1225

Closed Noxxaa closed 2 years ago

Noxxaa commented 2 years ago

When displaying timestamps of e.g. forum posts, it is converted to the user's local time following the timezone set in their profile settings. However, this seems to be done incorrectly.

For example, this post was made on 10:22 UTC:

image

And if I'm logged in and my local time is set to Asia/Kathmandu (UTC+05:45), it should display as 17:37, but it displays as 21:52 instead:

image

I went through various timezone settings to see what times I would get, and here's what I got:

Based on these tests, it seems that the UTC time difference is applied twice, and DST is not applied. This means that reported dates/times are incorrect for every timezone except UTC (and UTC+1 timezones during DST, if they observe it).

This was tested on forum post timestamps but it seems to apply to any case where a timestamp is posted.

meshuggahtas commented 2 years ago

Yes it looks like there is no handling of DST in the code @ https://github.com/TASVideos/tasvideos/blob/0a0f01854d92fdb914c43af679acdfecae20d456/TASVideos/TagHelpers/TimeZoneConvert.cs

Time zone overview at MS docs https://docs.microsoft.com/en-us/dotnet/standard/datetime/time-zone-overview

Invariel commented 2 years ago

The code should never explicitly handle DST. The timezone library that is being used handles it, and we should all be thankful that it does.

The issue is more likely that somewhere in the pipeline we're converting a UTC time to a local time, and then elsewhere in the code we're taking that local time, treating it as if that were a UTC time, and converting it again to a local time.