You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
"Automatic TZ discovery" sounds like an overly specific issue VS a manually set user setting (which should be offered anyway to cover all user cases, especially if time has such a critical context). The daylight savings part is just a per-request implementation detail from say a cookie or a param, I can' really see what this would add to the docs.
Yeah it's actually not all the complicated, it just seems so because I'm now getting back into the swing of using SvelteKit. Go ahead and close but I might make a simple HOWTO on this at some point, for external to the docs like a blog post.
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 callnew 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
The text was updated successfully, but these errors were encountered: