<story><title>Storing UTC is not a silver bullet (2019)</title><url>https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a-silver-bullet/</url></story><parent_chain><item><author>Joeri</author><text>There are basically three types of time: coordinated time, based on atomic clocks, zoned time, derived from coordinated time by applying a time zone rule to calculate an offset, and wall clock time. The latter two are often lumped together as local time but are not in practice the same thing.&lt;p&gt;TZ rules are one way, you can derive zoned time reliably from utc, but not the other way around unless you already know the offset. That’s why seemingly storing utc is best, because you can apply whatever tz rule you want. But, because tz rules are decided by politicians (dst, ramadan, date line shifts, it gets pretty weird, …) and often with little advance notice, tz rule databases are often wrong in practice, which means storing only utc and getting zoned time back out of it reliably is hard. That’s why storing iso timestamps with offsets is best. It preserves both utc and intended local (zoned) time at the time of storing, even if the tz database then changes.&lt;p&gt;But this is not the author’s problem. They’re dealing with wall clock time. They want to store 9 am and have it always be 9 am, no matter what happens with time zones. That is easy: store the timestamp without tz info. But, the hard part is knowing the instant in time (in coordinated time). Wall clock times may occur twice, so there is no single reliable way to get utc out of it, and even when calculating utc the result can be wrong or become wrong due to the political insanity that is zoned time so it is dangerous to store it and rely on it. You see this problem with anything that schedules people or resources. Something scheduled at 9 am is always 9 am, but if the system needs to send a reminder at 9 am, when do you schedule it? There are no solutions I’m aware of without edge cases.&lt;p&gt;I solved this for a reservation system by storing wall clock time without offsets and the time zone (id) of the resource separately, and then calculating zoned time for that zone and comparing it with the stored wall clock time every time the instant in time mattered. It worked but was tricky to code.</text></item><item><author>samwillis</author><text>I think summary here is that if you are storing an exact moment in time then UTC does the job. If however you are storing a future date and time in a certain location, due to the uncertainty about future daylight saving time changes you have to save it with time zone information in order to adjust for future changes to that system.&lt;p&gt;I suppose it’s the difference between exact time and social&amp;#x2F;political time (there is probably a better term for that).</text></item></parent_chain><comment><author>wpietri</author><text>I think it&amp;#x27;s even more complicated than that. Human time is much richer even than wall-clock time. E.g., if I go out for a dawn run every day, to me that&amp;#x27;s the same time. Or think of the Jewish Sabbath, which runs from sundown Friday to after dark on Saturday.  Lunchtime. Teatime. Lunar calendars. Whatever people will do when they live on Mars. Or the way wall-clock time existed before railroads changed it.&lt;p&gt;It&amp;#x27;s often our job to cram human concepts into a small number of bits, so I get why we do what we do. But I think it&amp;#x27;s sometimes worth being explicit that the anthropological concepts we are dealing with are very complex, and we may leave a lot out when we simplify them enough to make sense to the sort of machine that can be cheaply built in its era.</text></comment>
<story><title>Storing UTC is not a silver bullet (2019)</title><url>https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a-silver-bullet/</url></story><parent_chain><item><author>Joeri</author><text>There are basically three types of time: coordinated time, based on atomic clocks, zoned time, derived from coordinated time by applying a time zone rule to calculate an offset, and wall clock time. The latter two are often lumped together as local time but are not in practice the same thing.&lt;p&gt;TZ rules are one way, you can derive zoned time reliably from utc, but not the other way around unless you already know the offset. That’s why seemingly storing utc is best, because you can apply whatever tz rule you want. But, because tz rules are decided by politicians (dst, ramadan, date line shifts, it gets pretty weird, …) and often with little advance notice, tz rule databases are often wrong in practice, which means storing only utc and getting zoned time back out of it reliably is hard. That’s why storing iso timestamps with offsets is best. It preserves both utc and intended local (zoned) time at the time of storing, even if the tz database then changes.&lt;p&gt;But this is not the author’s problem. They’re dealing with wall clock time. They want to store 9 am and have it always be 9 am, no matter what happens with time zones. That is easy: store the timestamp without tz info. But, the hard part is knowing the instant in time (in coordinated time). Wall clock times may occur twice, so there is no single reliable way to get utc out of it, and even when calculating utc the result can be wrong or become wrong due to the political insanity that is zoned time so it is dangerous to store it and rely on it. You see this problem with anything that schedules people or resources. Something scheduled at 9 am is always 9 am, but if the system needs to send a reminder at 9 am, when do you schedule it? There are no solutions I’m aware of without edge cases.&lt;p&gt;I solved this for a reservation system by storing wall clock time without offsets and the time zone (id) of the resource separately, and then calculating zoned time for that zone and comparing it with the stored wall clock time every time the instant in time mattered. It worked but was tricky to code.</text></item><item><author>samwillis</author><text>I think summary here is that if you are storing an exact moment in time then UTC does the job. If however you are storing a future date and time in a certain location, due to the uncertainty about future daylight saving time changes you have to save it with time zone information in order to adjust for future changes to that system.&lt;p&gt;I suppose it’s the difference between exact time and social&amp;#x2F;political time (there is probably a better term for that).</text></item></parent_chain><comment><author>WinterMount223</author><text>Wall clock is solved by having a camera pointed at local live news where local time is shown, and having your system updated periodically where this period is arbitrarily short.</text></comment>