3 ms·
Only using UTC makes sense if you are recording exact moments in time - when a log line was generated for example - but it falls over when you start interacting
by simonw 7y ago
Only using UTC makes sense if you are recording exact moments in time - when a log line was generated for example - but it falls over when you start interacting with actual human times.
If I say an event is happening at 7pm, I mean 7pm in my local timezone. If I record that upcoming datetime in UTC but I forgot about a daylight savings time change between now and then that doesn't mean the event will happen at 6pm - it's still happening at 7.
I've done some projects where I've stored dates as a localtime, a timezone AND a denormalized, calculated UTC datetime (for lookup/sorting).
- simonw 7y agohttps://technicalsourcery.net/posts/time/ https://technicalsourcery.net/posts/time/ says this better than I did.
- treis 7y ago>If I record that upcoming datetime in UTC but I forgot about a daylight savings time change between now and then that doesn't mean the event will happen at 6pm - it's still happening at 7. This breaks down when you start having to deal with multiple timezones. Then whenever you do sorting or availability checks you have to account for DST/timezones. You will pretty quickly make a method that converts your timezone stored data to UTC. Better to just store it all as UTC so that your DB queries are much simpler.
- ubercow13 7y ago>If I record that upcoming datetime in UTC but I forgot about a daylight savings time change between now and then There are good reasons for not storing in UTC but this doesn't seem to be one of them. Surely the problem in this case is just that you incorrectly converted to UTC? It's just a bug.
- mbreese 7y agoDaylight saving time rules can change... Just because you stored it correctly now doesn't mean it is correct in the future (when it's needed).
- ubercow13 7y agoSure but that is a separate issue - in that case you didn't 'forget' about it
- aeorgnoieang 7y ago> Daylight saving time rules can change Which is why all of the good date-time libraries come with the standard timezone database, which contains a full history of timezone changes. So, (carefully) using one of those libraries, you should be handle to handle any date-time ever.
- mixmastamyk 7y agoTimezone dbs lag, so do not solve every problem.