logoalt Hacker News

jedbergyesterday at 9:09 PM4 repliesview on HN

I would contend that you shouldn't store anything but current unix timestamps in UTC in your database. If you must store time in some other way, then the two column method in the post will work, but leave it up to your software library to do it.

I prefer to leave all the time conversions to software, wherein you only use battle tested libraries, and never do it by hand.

Timezones are just too fraught with peril to try and do it on your own.

Edit: changed some words to make clearer what I was saying.


Replies

ppchainyesterday at 9:21 PM

The issue described in the post is an example of when you cannot just rely on Unix timestamps. Specifically it comes down to which date is authoritative.

A appointment with your dentist at 2pm Pacific Time in December 2026 has changed Unix timestamps in British Columbia. The dentist doesn't care about the Unix timestamp, she cares about the wall clock local time when you arrive for the appointment.

show 4 replies
ivan_gammelyesterday at 10:15 PM

It‘s a common mistake to store everything as UTC timestamps and shows lack of understanding of time domain. Local time exists and it is neither UTC or timezone-dependent. Doctor office opens at 8 a.m. regardless of whether it is DST or not. Appointments are made in local time. Store them in local time.

show 1 reply
merbyesterday at 9:11 PM

In that case only storing utc did not work when you created a date in the future before you updated tzdata

show 1 reply
rini17yesterday at 9:56 PM

If you don't understand what the library is doing, and blindly put in local time without any consideration, you will get bitten someday. And all libraries use the same timezone database/logic anyway and run into same issues the author describes.