Live data from Hacker News

UTC Is Enough for Everyone, Right?

zachholman.com

141–150 of 321 posts

Re: UTC Is Enough for Everyone, Right?

#141
post #138
post #33

So the article seems to imply you should store all timestamps as UTC (with an additional timezone string ID). But for events in the future that needs to happen on a specific "wall clock point in time", it might be better to actually store the yyyy-mm-dd hh:mm:ss as a string with a timezone next to it, because timezones can and do change often unpredictably. If you pre-calculate what "4.00pm next August 1st" is as a U…

There is a solution for this, Unix timestamps.

That fails for the case that you have an appointment at 3pm in 30 days, and 15 days later the timezone's offset changed.

Re: UTC Is Enough for Everyone, Right?

#142
post #38

Earlier quoted context omitted.

Right? And that that 37 second offset will change from year to year? I was waiting for the bombshell, that some minutes actually have 61 seconds in them, and some have 59 seconds (though it occurs to me that I don't know if astronomers ever add or subtract more than a second for any given clock adjustment).

The goal is to always keep UTC within one second of UT1. Short of very drastic events I don't think it will ever be neccessary to introduce more than one leapseconds in a fairly long time interval. And even if it was, I would think that they would do seperate leapseconds events some time apart.

The Earth's rotation is slowing down. In a few hundred years with the current system, we will need more than 1 leap second per 6 months. How many centuries is hard to tell, since it is affected by many things, including global warming.

Re: UTC Is Enough for Everyone, Right?

#143
post #122
post #33

So the article seems to imply you should store all timestamps as UTC (with an additional timezone string ID). But for events in the future that needs to happen on a specific "wall clock point in time", it might be better to actually store the yyyy-mm-dd hh:mm:ss as a string with a timezone next to it, because timezones can and do change often unpredictably. If you pre-calculate what "4.00pm next August 1st" is as a U…

IMO the biggest problem isn't the how you store information or even do the date-math. The most frustrating thing is drawing out user-intent, distinguishing between two use-cases which are so similar that most users won't even know what they want. Specifically, future events which aren't tied to a geographical location, and ones which are. And in the latter case, determining which single location it should be pegged t…

Exactly that. It's like when people ask the difference between crond and atd, one fires events at a defined date/time in the future and the other fires events at a count of date/time from the present.

Re: UTC Is Enough for Everyone, Right?

#144
post #138
post #33

So the article seems to imply you should store all timestamps as UTC (with an additional timezone string ID). But for events in the future that needs to happen on a specific "wall clock point in time", it might be better to actually store the yyyy-mm-dd hh:mm:ss as a string with a timezone next to it, because timezones can and do change often unpredictably. If you pre-calculate what "4.00pm next August 1st" is as a U…

There is a solution for this, Unix timestamps.

This is exactly wrong I think:

If the timezone changes under my feet the unix timestamp might suddenly not refer to my birtday anymore.

Watching people struggle with this is frustrating.

Also I currently work with frontend and while it is no surprise that JavaScript has messed this up badly [0] it surprised me when I realised that a certain large UI framework had a) messed it up b) didn't realize it and tried to close it down when people tried to help.

[0]: they copied Javas first broken Date handling and suddenly they were stuck with it IIRC.

Edit: heh, double-ninjaed

Re: UTC Is Enough for Everyone, Right?

#146

> Properly storing timezone-aware times I'd just like to point out that a lot of RDBMSs support storing date and time alongside timezone information directly without using two separate fields. SQL Server has datetimeoffset, PostgreSQL has timestamp with time zone, and Oracle has timestamp with time zone. I think MySQL does as well, but I seem to recall something strange about it. Or maybe that's just me expecting MyS…

> Similarly, most programming languages have support for datetimes with time zones

They do, but in many languages they're easy to misuse, and I think this is an underappreciated part of the problem. I'd even argue that timezones really aren't that hard, they're hard when you use the wrong abstractions or try to tack them on as an afterthought. Ultimately there's a big lookup table that someone else manages for you (the Olsen database) that gives the current definitions of timezones and how they relate to UTC at various times of the year due to daylight savings changes. Given a local wall-clock time and a timezone name you can use this to unambiguously get the global instant in time it corresponds to.

But a lot of libraries let you ignore or mix up these underlying types, or implicitly convert between them in a way that you may not realize is happening. The biggest problem I've seen by far is that a timezone like America/Los_Angeles is not the same as an offset like -07:00 or a named offset like PDT (the latter is the most confusing and really just needs to stop being used. It has the definition of a static offset in that it means 7 hours behind UTC, but also corresponds to a place which is sometimes on PDT and sometimes PST, and also is usually referred to as just a timezone with nothing to distinguish it from timezones from the Olson database like America/Los_Angeles. And I think it also has a name collision with a timezone in Asia).

As an example of the problems this can cause, say you start with a time like 0:00 March 11 2018 in America/Los_Angeles. If you call the "to_iso861" method in any given time library you may or may not be implicitly converting the timezone to an offset as it'll return "-07:00" or maybe PST (ISO8601 doesn't have anything to say about what a timezone should be, so these are all valid). But now when you parse that again and add 4 hours to it, you'll still have a time with -7 hour offset even though the place you were originally referring to has changed and now has a -8 hour offset.

The javascript Date type is notoriously bad on its own as well, since it implicitly converts everything to the browser's local timezone offset. And moment isn't a whole lot better, the timezone support is tacked on as a separate library and it will happily let you mix up offsets and timezones as well, or let you go back and forth to a Date object which can have that same implicit conversion problem.

The only library I've seen that actually requires you to treat these concepts separately is Joda, which has port as js-joda. The syntax can be a little confusing and the js port is missing good builtin support for locale-aware formatting though, but those are all minor annoyances and well worth it for the better abstractions it gives you. The good news is there's a new builtin time library on the horizon for JS as well which seems to be borrowing from both joda and moment, as well as browser support for Olsen timezones and locale-aware time formatting, so I'm hopeful it will be easier to just "do the right thing" by default in the not too distant future.

Re: UTC Is Enough for Everyone, Right?

#147
> Definitely check it out if you get really excited about reading whitepapers. Also get yourself checked out if that’s actually the case.

Highlight of the article! Even though I disagree with certain bits, the article in itself helps explain how to think about programming time in a project.

Re: UTC Is Enough for Everyone, Right?

#148
post #31
post #28

> Base ten is lit and doing everything in twelve feels so uncivilized … It's actually the reverse: base twelve is more elegant than base ten[0]. The only reason we think otherwise is that we're used to using base ten. 0: ½ in base twelve is .6; ⅓ in base twelve is .4, not .333333…; ¼ is .3; 1/6 is .2, not .166667

I actually had something similar to this in my notes but didn't get around to adding it. Basically, 60 minutes seems kind of arbitrary for an entire system of time (at least to me!) and then I realized that once you split it down into half, thirds, quarters, etc., it's basically the best numbers to use for informal conversations about time. That was pretty illuminating when I read about that; thanks for pointing it o…

They're called Highly Composite Numbers (or anti-primes) [1], meaning they have more divisors than any smaller number.

[1] https://en.wikipedia.org/wiki/Highly_composite_number

Re: UTC Is Enough for Everyone, Right?

#149
post #33

So the article seems to imply you should store all timestamps as UTC (with an additional timezone string ID). But for events in the future that needs to happen on a specific "wall clock point in time", it might be better to actually store the yyyy-mm-dd hh:mm:ss as a string with a timezone next to it, because timezones can and do change often unpredictably. If you pre-calculate what "4.00pm next August 1st" is as a U…

Depends. Some things need to happen N seconds from now. Other things (usually things involving humans) need to happen on a day that those humans will look at their calendars and say "oh, it's [that day]! Better do [that thing]!"

Re: UTC Is Enough for Everyone, Right?

#150

My favorite date quirk not mentioned in the article or here yet is the month of September 1752. If you're on a *nix/Mac machine, try this command: $ cal 9 1752 What you'll see is: September 1752 Su Mo Tu We Th Fr Sa 1 2 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 No, there's not a bug in `cal`, this is correct ;)

That was fun. So what happened in 1752?

edit: I should have searched (http://mentalfloss.com/article/51370/why-our-calendars-skipp...)

Post reply on HN