297 points · by sirwitti · 14y ago · 83 comments
59.50 59.75 60.00 60.25 60.50 60.75 60.00
Or, if your clock implementation is not POSIX-compliant but follows Mills' paper instead:
59.50 59.75 60.00 59.25 59.50 59.75 60.00
It gets weird, though: since this information was only made available recently, your computer may not know the leap second exists. In that case, its upstream NTP servers will jump and the local ntpd will slew the clock smoothly over the discontinuity, IIRC.
OTOH, if your system is aware of the leap second and if you're using the system clock to calculate intervals (i.e. t2 - t1), expect possibly negative or zero intervals over this timeframe. If you're calculating rates over a roughly 1-second interval, divide-by-zero bugs are definitely possible.
On a related note, does anyone know what the Oracle and OpenJDK JVMs do with respect to System.currentTimeMillis? They claim it's number of seconds since the epoch, which would imply this timer will not encounter discontinuities. The only ways I can think of to achieve that are by reading the system clock state to look for the leap insert/del/doublecount flag, or read a copy of the leap second table.
[edit] You may be asking, "Why would anyone use a system of time in which two numbers could refer to the same instant, or one in which a given number could refer to no time at all? Why not use a time system in which you could subtract two times from each other to get the interval between them? Or hell, even a time system where time always increases, you know, so we could order events.
The closest thing we have to such a time scale is TAI (http://en.wikipedia.org/wiki/International_Atomic_Time), which is what most computer systems like to pretend their clocks are: "the number of seconds since an epoch".
UTC and POSIX time are adjusted, relative to TAI, to keep the number of seconds in a given day at a nice "easy" 86400, which is why we're in this mess. Given that it takes plenty of math to translate a number like 1339696998.435347 into a human-readable date, I think our computers should just be keeping TAI to begin with and make the whole process easier on ourselves; but so many systems assume UTC or POSIX time that we're stuck with it.
Converting from TAI to UTC requires a lookup table; but consider that this is already a problem: your local clocks almost always keep time in seconds, not UTC. In order to keep UTC/POSIX time, it needs regular updates from the network (NTP) or shipping around a lookup table. This probably made more sense before large-scale use of NTP, but nowadays I don't know anyone who syncs their clock to a UTC source.
UTC is in general fucked because two different systems, depending on the state of their lookup tables, may not agree on what time a given number represents. This is an especially big problem for embedded systems which can't receive regular updates; consider that a UTC device manufactured in the 70s may disagree by up to 30 seconds with a modern UTC clock.
The easiest resolution to the problem is likely to drop leap seconds from UTC altogether; at which point POSIX, TAI, and UTC can proceed in lockstep corrected by a fixed offset. [1] Then we can use fixed lookup tables to compute relationships for the period where we were using leap seconds.
[1] I think. Need to check SI/NIST on this.
yes, technically POSIX time is defined not as a number of seconds since epoch, but as 86400 * (number of days since epoch) + (number of seconds since last midnight)
"Although the Date class is intended to reflect coordinated universal time (UTC), it may not do so exactly, depending on the host environment of the Java Virtual Machine."
and further down in notes on possible ranges of return values
"A second is represented by an integer from 0 to 61; the values 60 and 61 occur only for leap seconds and even then only in Java implementations that actually track leap seconds correctly. Because of the manner in which leap seconds are currently introduced, it is extremely unlikely that two leap seconds will occur in the same minute, but this specification follows the date and time conventions for ISO C."
EDIT: Simple time torture script is added:
for((I=0; I<100; I++)); do date --utc --set=@$(( `date --utc +%s`+1 )) ; date --utc --set=@$(( `date --utc +%s`-1 )) ; done(I'd like to point out that after that we did go to a massive party.)
http://googleblog.blogspot.com/2011/09/time-technology-and-l...
I can only think it's too randomize it a little so you don't end up changing clocks only by powers of 2 and showing up some weird bug.
Although 1341100800 refers to two seconds, when converting to UTC it should always become 00:00:00. Your implementation may not be conforming to the standard, though. Make sure to test.
(I'm sure if you rolled your own time code, you already know about this stuff. Probably other folks are curious though :)
[0] I think this is the second we're talking about, not positive though.
If you rolled your own, you should worry more, but you should still think about it even if you didn't roll your own.
[1] Joda is awesome, and by far better than any other time lib out there, but even they have bugs they're fixing in JSR310 (http://jcp.org/en/jsr/detail?id=310)
The amount of time until a timezone is noticeably out of whack with solar time is substantially longer than how long timezones have existed in anything like the modern form. In a thousand years maybe we'll start moving timezones around. But the cost of moving them for astronomical reasons will happen orders of magnitude less often than moving them for random political reasons.
I have read arguments both ways. And I remain convinced that letting UTC slowly drift away from Greenwich is a perfectly reasonable solution that will save us from many potential software bugs, and will cause no significant disruptions in life for the next ten thousand years. Of course eventually the Earth's rotation will slow down enough that the drift of time zones will become noticeable on a human time scale. But that problem is many thousands of years off, let them solve it then. If all goes well they will have had to figure out how they want to handle local calendar time not fitting UTC for people living on asteroids and other planets, and can just adapt that solution to Earth...
Bonus points if you were working on critical public infrastructure like a nuclear power plant.
Worst thing in recent history that I remember is the Zune's leap-year bug: http://en.wikipedia.org/wiki/Zune#First_generation
Of course there will always be outliers and poorly coded applications that rely on time, but at least it's not a Y2K style situation.
[1] http://www.cisco.com/en/US/tech/tk869/tk769/technologies_whi...
[1] http://en.wikipedia.org/wiki/High_availability#Percentage_ca...
Of course we wouldn't have this problem if we just counted seconds from some particular point in space time moving forward. Who cares if the Sun is exactly overhead at noon anyway :-)
I do like GPS time. It keeps going at a constant rate like all good time should. Time differences are easier in GPS, you don't have to worry about pesky leap seconds....
Sidereal time is the most interesting from a cosmic sense.
(I haven't got time to read the article right now (but will do in a week when I'm less busy) and have little to zero experience with times, so forgive me if it's something that's been discussed in the article. I'm just curious.)
http://www.usno.navy.mil/USNO/time/master-clock/leap-seconds
they get if from IERS
They issue leap second guidance to about 1 year in the future. They adjust typically twice a year as needed (Jan 1 and July 1).
It's the "service" that really makes it I think.
Edit: acomjean looks to have a better source (but if you are looking to subscribe to the Local Notice to Mariners in your district, which I strongly encourage if you boat on the ocean, my links will get you there too!).
http://www.bbc.co.uk/news/science-environment-16625614
The parent link is to the authoritative Bulletin C, hard to imagine that it's wrong.
Although it's always possible that the USA will unilaterally ignore cheese-eating surrender monkey time and adopt "freedom time"
The only people that a leap second realistically affects are astronomers and they are more than capable of managing their own time software.
At roughly 1 second every 1.5 - 2 years it will be a couple of millenia before the sun even gets an hour away from local noon - and people manage with daylight savings time. So every 2000years we might need to introduce a leap hour.
But when the clock jumps back abruptly by 1.0 s, the controller gets confused. Its next control loop update cycle is now scheduled 1100 ms into the future instead of the normal 100 ms period. This delays the motor shutdown signal and even causes the controller to miss the top-of-position sensor. The elevator car slams into the roof of the building. The cable snaps and all passengers contemplate Einstein for 10 s as the elevator car freefalls to their certain doom.
Well they would have, except that cable elevators have had mechanical safeties for a backup system since the 19th century.
OK, so instead:
Picture yourself receiving life-saving radiation therapy, when the clock strikes midnight ...
I could understand inserting leap seconds if there were some specific need to have 0 longitude be at solar noon at exactly 12:00:00, but as far as I can tell there's not. If the clock drifts off solar noon by a half-second per year or so, then maybe in a few millennia London will decide to use UTC-1. I could be wrong about this, but I don't see this as a big deal.