You may be relived to know that Unix epoch time does not have this problem. But you may also be horrified to know why.
First, epoch seconds are not the numbers of seconds since 1970/01/01. This is a lie we tell to children. Rather, epoch seconds are the number of days since 1970/01/01 * 86400 plus the number of seconds since midnight.
Leap seconds, to epoch time, don't exist. Or maybe they are double counted. Or maybe we smear them over 12 or 24 hours (but which 12 or 24 hours depends on whether you are Google, Microsoft, or Oracle; I can't even make this stuff up). The point is, it's not defined, and this means implementations do it differently.
A negative leap second might be easier though. The spec suggests (though lack of speaking) that a correct implementation will just skip it since number of seconds stays less than 86400 for that day. But of course the smear-organizations still smear it.
So what if you really want to know how many seconds were between two different epochs? Subtracting epoch seconds is wrong because you need to correct for the number of leap seconds between the two times.
And the smears.
Indeed. I like to say, we would like three things to be true:
1) Every day has 86400 seconds.
2) Every day is from noon (sun exactly above) to noon (sun exactly above).
3) We use SI seconds.
You can't have all three. Pick any two:
1, 2, not 3: What you describe. Day has 86400 seconds, we keep in sync with the sun, but we tweak the seconds a bit. There are different versions, like epoch time, or UT1.
1, not 2, 3: Every day has 86400 SI seconds, and we slowly go out of sync with the sun. That's TAI.
not 1, 2, 3: We use SI seconds and keep in sync with the sun +/- 1 second, but need to add/drop seconds occasionally. That's UTC.
https://en.wikipedia.org/wiki/Universal_Time
https://en.wikipedia.org/wiki/International_Atomic_Time
https://en.wikipedia.org/wiki/Coordinated_Universal_Time
The length of a noon-to-noon day (synodic day) varies from +29.9 seconds near the winter solstice to −21.3 seconds near the autumnal equinox[1]. If you account for the seasonal changes, you get closer to the ideal solar day which only deviates by milliseconds from 86400 s, but that deviation does pile up and "forces" leap seconds. I say "forces" because it's a legal requirement that the time tracks the sun.
Going to leap hours I think is a sufficient kick of the can down the road, one is only needed every few centuries. Pretty sure something'll happen in the next 600 years that obviates the need for that though (nuclear war, asteroid, technological singularity, need for a unified solar system time...), so us hack programmers can assume all three of those things.
[1]: https://en.wikipedia.org/wiki/Synodic_day
Legal only in the sense that the requirement hasn't changed since the Romans invented the concept of time.
If you really want to think about it, were it not for them, we wouldn't have many of the things we have today.
Philip K. Dick was correct, the Roman Empire never truely fell.
> Going to leap hours I think is a sufficient kick of the can down the road, one is only needed every few centuries.
The drama of rolling out the Gregorian calendar to replace the Julian so that the seasons went back to where they 'should' be shows how convoluted things could get in coördinating things.
Unless you're an astronomer, you probably don't care about condition 2. Many countries still shift wall time around by an hour twice a year for DST - if people are okay with that, solar time being offset by a few seconds is insignificant.
Even for astronomers, I suspect that preserving conditions 1 and 3 is probably more valuable than 2. It's easier to correct for the uneven rotation of our planet than for an uneven timescale.
I agree. The difference in how much we're out of sync with the sun is tiny and also completely inconsequential in the vast majority of cases, especially compared to the trouble of the alternatives. By the time the difference is relevant or noticeable, I sure hope we have a better way of tracking time.
If anything, it's probably for the better to completely disconnect the measurement from it's old standard, the same way imperial measurements are now defined using SI units as a baseline, and how 1 AD isn't actually the year of Christ's birth. It's OK that the actual measurement is off from what it was once based of, so long as we all agree how we're defining our units.
Condition 2 are pretty much hard to get. Happens everytime in the equator, happens only twice a year in most countries, hopefully never happens in the n/s pole
Yes, it's wrong. But we have also agreed to all be wrong in the same way. Except during the specific day that we are wrong in different ways.
Correction: We are mostly right, most of the time, but wrong in ways most people don't notice except if they try to talk while everyone is wrong.
Clarification: Human perception of time is not understandable, and the machine abstraction even less so.
And this, ladies and gentlemen, is why you use a proper datetime library rather than doing epoch arithmetic yourself.
"How hard could it be?"