The formula mentioned in post Google’s Leap Second Smear Techinque :Modulating “lie” over a time window w before midnight:
lie(t) = (1.0 - cos(pi * t / w)) / 2.0
There is no description of the math behind this. Can someone explain why the formula works. Also can this be used for any situation where we want to synchronize time gradually over a window and avoid abrupt jumps ?
This works because the graph of
cos(x)varies smoothly over time. It doesn’t change abruptly, though it does change non-linearly.Let’s say we’re smearing over a window of
w = 86400. Here’s what the lie is fromt = 0tot = 86400:Towards the beginning of the day, the lie we’re telling is very small. The time you’re reporting (
t + lie(t)) is almost identical to what the real time should be (t). The smeared time you’re reporting is also changing very slowly over time. Ideally, for each 1 real second that passes you should report 1 second has passed. In smeared time, what you instead see is:Towards the middle of the day, we see the largest changes. But those changes are on the order of
10^-5. They’re small enough that anyone receiving the smeared time wouldn’t suspect that something is wrong. At noon, you’re talking about differences of microseconds in how much faster smeared time is moving.In Google’s case, they want to smoothly change time very slowly so that local corrections don’t occur. If they abruptly change time by a second then local corrections may occur. And from the blog post, it sounds like this generally leads to very bad things happening (i.e. stuff breaks).
One thing to note is they may not be smearing the leap second out over a day. It may be over a full year. In that case, the change is even smaller. In this case, the day to day changes are on the order of nanoseconds.
If you want to know about the actual math — that part isn’t very interesting.
cos(x)is bounded by [-1, +1]. Atx = 0we havecos(0) = 1and atx = pi,cos(pi) = -1. The valuet / wlinearly increases from 0 to 1 fromt = 0 ... w. Socos(pi * t / w)changes from+1att = 0down to-1att = w. The rest follows from this.The periodic qualities of
cos(x)are actually quite important. We can’t just choose to use something likelie(t) = t / w. If we did, the lie would always increase over time. Leap seconds would just keep on piling up at a rate of1 / wper second.cos(x)has the property that it oscillates between-1and+1.