Description
Describe the problem
Dealing with timezones in a Universal SvelteKit app isn't that obvious. The user's timezone is only known clientside so I stumbled my way through a solution that:
a) First visit, the page server-side renders with a default timezone of say Los Angeles
b) Then a cookie gets set with the minutes of offset, in a cookie called 'TZ'
c) Subsequent visits confirm that the TZ there matches the current one (it'll change if you move across the world or if daylight savings time toggles)
This gives you a "flash of incorrect timezone" on the first visit, which is unavoidable, but fixed as soon as the page hydrates.
I think a reference solution for this would involve loaders in +layout.server.js
to read the cookie, +layout.js
to call new Date()
, and some code somewhere to set the cookie if not set yet, and also possibly code to put it in context to make available to all components in the tree.
Bonus points if it's reactive and the minutes of offset update when Daylight Savings Time becomes active or inactive.
Any interest?
Describe the proposed solution
See above.
Alternatives considered
No response
Importance
nice to have
Additional Information
No response