3 ms·
Why not just display it in the viewers' timezone?
by Karellen 3y ago
Why not just display it in the viewers' timezone?
- whirlwin 3y agoHow do you determine the viewer's timezone? A lot of apps try to find your timezone and it works fine until you travel abroad to a country with a different timezone.
- Karellen 3y agoIf your own user-agent or OS is working on the wrong timezone, that's your fault. A website/app shouldn't have to find your timezone. It should use whatever one you've set. If you've set your timezone to one you didn't want, I'm not sure what you'd expect other software is meant to do about that. Fix your config.
- cratermoon 3y agoMostly because the browser Javascript API for Date is kind of crap for dealing with timezone info. There are some efforts to standardize on a better API, but it's going to take time to migrate.
- solardev 3y agoHow do you know what time zone to convert it FROM? Unlike epoch time (Unix time in milliseconds or seconds), "2021-11-21T15:10:35" doesn't automatically mean UTC without a "Z" or "+0" at the end. Without the time offset, that timestamp could be in any of the world's timezones. There's no way to know what moment in time was actually stored/meant. Even if the user set it in one time zone, if we store it without a proper offset (and preferably a locale), we cannot properly account for the user traveling to another place, daylight savings time, government time adjustments, leap time, etc. These complexities compound off each other and make proper scheduling and debugging time issues really, REALLY hard later on. In the twenty years or so that I've been doing web dev, datetime is probably the single biggest gotcha I've seen developers (including myself) stumble into. Part of this is because the standard JS datetime handling is atrocious compared to any other language I've worked in. It doesn't really natively handle time zones well, and well carelessly cast them back and forth if you're not careful. Moment and Luxon can help with this, lighter libs like date-fns can too with the right extensions, but out of the box JS is going to fuck it up. I promise. Another choice is to just use milliseconds to store everything, and convert that to the user's timezone only at the time of display. Every timestamp is stored as an epoch, and every user has their time zone (not just offset, because of daylight savings) recorded with their profile. Doing those two simple things can avoid most of the landmines.
- Karellen 3y agoSurely when someone posts content, that date/time that happens is captured by the server in epoch time. And javascript natively converts epoch time to whatever timezone the client has set. If your user-agent (aka browser) is working on New York time, but you're in Tokyo, well, I'm not sure who else you have to blame but yourself if it shows you New York time when you didn't want that.