Time arithmetic

Jul 09, 2026 Last reply: 9 hours ago 24 Replies

We've been... "distracted" (I'll write more, later)

Yes -- leap seconds. They aren't particularly predictable. And, can make for unexpected results (e.g., when strftime returns a time having a seconds value of *60*, not "59"!)

The advantage of handling all the "magic" comes when YOUR local timebase loses sync with a time server -- so YOU know to insert the leap seconds.

In the case of my "complaining colleague" (at the top of the thread), it was his ignorance of all the subtle (but predictable) intracacies of "human time" that confused his expectations and computations.

I "solved" the problem by creating a "map to human time" function that takes a system time (an unsigned long int that is always monotonically increasing at a rate of 1 second per second) and provides the "human time" relative to that as offset by a tuple specifying some number of seconds, minutes, hours, days, weeks, months, years). Because the components of the tuple aren't constrained to represent "human times" (e.g., you can specify 37 months, 449 weeks, 82 days, -3 hours, 90045 minutes, -300 seconds), the possibility of specifying an incorrect

*time* goes away.

It also makes it easy to find specific instants relative to some arbitrary epoch: START_OF_1900 (a system time) plus 23 years,

9 months, 2 weeks... and come up with a valid time representative of that instant. (Mapping back to system time from human time requires you specify a VALID human time -- so "March 43rd" throws an error. If you want to know when March 23rd is, then map "3 months, 43 days" using the aforementioned function!)

Not leap seconds. Corrections to time because the Earth is not actually rotating at a constant rate.

Ah, good to know.

And the seconds applied to correct for the Earth rotation variances?

there used to be the Earth Rotation Service in London, now under the new name IERS in Frankfurt, .de

<
formatting link
>

Gerhard

From Wikipedia:

"A leap second (sometimes called intercalary second)[1] is a one-second adjustment occasionally applied to Coordinated Universal Time (UTC), to accommodate the difference between International Atomic Time (TAI), as measured precisely by atomic clocks, and observed solar time (UT1), which varies due to irregularities and long-term slowdown in the Earth's rotation."

If you have a "local" timebase that accurately tracks elapsed time, that timebase will deviate from the time that humans regard. This deviation increases, over time (we are presently correcting by almost

30 seconds over the past 50 years).

If you naively assume a minute consists of 60 seconds, an hour of 60 minutes and a day of 24 hours in calculating differences between two times, this error will manifest.

If you ask your computer for the last second of the date 2016-Dec-31, you will discover that to be 23:59:60 (not 59). If your code has naively assumed that the seconds component of the time will always be [00..59], you have a latent bug, the consequences of which will be unknown.

[It is conceivable -- and the software interfaces support -- for a day to *lose* a second (leap seconds have variable polarity) but that has yet to happen

It seems the current idea is to do away with leap seconds as discrete events and perform the requisite "time correction" by "smearing" that extra second over a longer period of time, thereby distorting the FLOW of time over that interval. This because people can't count to 61?

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required