4 ms·
Timezones in computing are an annoyance to solve properly, once, and then always use that code. Use a library of timezones maintained by someone else (in the O
by jtheory 12y ago
Timezones in computing are an annoyance to solve properly, once, and then always use that code.
Use a library of timezones maintained by someone else (in the OS, the VM, or similar), because these need to include the history of timezone changes to be complete, and countries continue to change their timezones, daylight savings rules, etc.. I'd dearly appreciate it if everyone got rid of daylight savings time, but it's abstracted away for almost all applications now.
For most purposes, you can store all times in UTC in the database, and let people choose the timezone they want to use for data entry and display. Sometimes you also need to store the "local time" -- e.g., imagine you'll need to generate reports on some stat between 9am and 10am local time, for locations in many timezones -- but always store UTC first.
Building the dropdown list people will use to choose their timezone is probably the most annoying part of it. It's hard to come with something that's complete without having terrible usability.
- manicdee 12y agoEven then, you can make a good approximation to their actual timezone using IP geolocation. Then there are the pseudo-dropdowns where the user starts typing their city name (or a prominent city in their timezone) and you look it up on the fly. And then you package that control up as a module to share with other projects that you write :)