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 ?
The average speed of Earth's rotation is measured by Universal Time (UT1). When the difference between UTC and UT1 is predicted to reach 0.9 seconds within 12 months, a leap second is added to UTC and clocks worldwide. In other words, our clocks are always kept within a second of the average length of a day.
Smearing. More recently, it has become a common practice to “smear” a leap second by simply slowing down or speeding up the clock. There is no universal way to do this, but at Meta we smear the leap second throughout 17 hours, starting at 00:00:00 UTC based on the time zone data (tzdata) package content.
A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC), to accommodate the difference between precise time (International Atomic Time (TAI), as measured by atomic clocks) and imprecise observed solar time (UT1), which varies due to irregularities and long-term slowdown ...
LEAP SECOND TIME ADJUSTMENT DAY - December 31 - National Day Calendar. Today.
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 from t = 0
to t = 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]. At x = 0
we have cos(0) = 1
and at x = pi
, cos(pi) = -1
. The value t / w
linearly increases from 0 to 1 from t = 0 ... w
. So cos(pi * t / w)
changes from +1
at t = 0
down to -1
at t = w
. The rest follows from this.
The periodic qualities of cos(x)
are actually quite important. We can't just choose to use something like lie(t) = t / w
. If we did, the lie would always increase over time. Leap seconds would just keep on piling up at a rate of 1 / w
per second. cos(x)
has the property that it oscillates between -1
and +1
.
I'll kinda guess.
cos() outputs values in the range -1 to +1 so, the maximum lie would be when cos is -1, because
(1.0 - -1)/2 == 1.0
and the min when cos is +1
(1.0 - 1)/2 == 0.0
Note that 0.0 would be a suitable value for "no lie" and 1.0 would be a suitable value for the "leap second".
heres a plot of the function, you can see it has a nice and smooth gradual transition from 0 to 1.
as for the expression used to calculate the argument to cos: pi * t / w
, they can just be thought of as changing the speed/interval at which the function transitions from -1 to 1. Making t bigger makes it transition faster, and making w bigger makes it transition slower.
They mentioned w was the window of time before the offical leap second was to be applied, so take that in seconds. Then t could be some increasing number, likely seconds again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With