3 ms·
That's a can of hairy worms right there. Check out "Falsehoods programmers believe about time": https://infiniteundo.com/post/25326999628/falsehoods-programmer
by carapace 7y ago
That's a can of hairy worms right there.
Check out "Falsehoods programmers believe about time": https://infiniteundo.com/post/25326999628/falsehoods-programmers-believe-about-time https://infiniteundo.com/post/25326999628/falsehoods-program...
- gombosg 7y agoHairy indeed. I just spent 2 days programming a timezone selector in a React form that changes the displayed date/time as you switch timezones but the underlying UTC representation wouldn't change. All this without loading 500k JS timezone libraries. I only used Intl API and tz.js [1]. The trick simply was to temporarily shift the date by the difference between the local time and the edited time zone. :) [1] https://github.com/dynasty-com/tzjs https://github.com/dynasty-com/tzjs
- daurnimator 7y ago> The trick simply was to temporarily shift the date by the difference between the local time and the edited time zone. :) If you're near a change in daylight savings then that will go wrong.
- carapace 7y agoYeah, not to be rude (we've all been there) but that hack is bound to be borken somehow. Really this time & timezone stuff should be handled by the OS, system calls or libs should be more sophisticated so we aren't "solving" these problems over and over again. But I'm about to start ranting about Unicode, so I'll shut up now... ;-)