apps
apps copied to clipboard
fix: calculate the local timezone offset when generating the heatmap
Changes
Describe what this PR does
- Adds local timezone offset when generating heat map
The heatmap generator does not take into account the users timezone, so when they have read a post today, it looks like it was yesterday.
I set my local timezone to GMT-8 (Vancouver, Canada), and ran the following line, which assumes GMT+0 time, and then it outputs it as local time.
> new Date("2024-02-22")
Wed Feb 21 2024 16:00:00 GMT-0800
{
"data": {
"userReadingRankHistory": [
{
"rank": 1,
"count": 1
}
],
"userReadHistory": [
{
"date": "2024-02-22",
"reads": 1
}
],
"userMostReadTags": []
}
}
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
daily-webapp | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Feb 22, 2024 4:57pm |
1 Ignored Deployment
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
storybook | ⬜️ Ignored (Inspect) | Feb 22, 2024 4:57pm |
Marking as draft, might need a bit more thinking
To me this looks like we are fixing it in a wrong spot. Because even if you fix the dates, the calculation is still inherently wrong, since it will count posts that you read on one day into either tomorrow, yesterday or tomorrow depending on the actual timezone you are in.
So I think a better solution would be to change the heatmap generator to take the timezone of the user into account...
Working with time is 💩.
On the API side, each view is stored as UTC, and when we get the reads for the user, we take their saved timezone into account. So if you read at 2023-12-31 23:00 GMT-1
, your read is saved as 2024-01-01 00:00 UTC
, the API response would be 2023-12-31
.
But because JS parses date strings with no time as being at midnight, it would be shown in the heat map on the 30th, because 2023-12-31 00:00 GMT
is 2023-12-30 23:00 GMT-1
Time 😢
I like the way that GitHub has solved it. It shows the heat map entries with the visitors timezone taken into account