Universal Time

For most of human history the passage of time has been measured by the Sun, and the distance you could walk in a day. Now all of humanity is synchronized to the vibrations of the same Cesium atoms.

Local Time

Until very recently telling the time meant how much daylight was left in the sky from where you were standing. Since Biblical times the “hour of the day” meant which fraction (usually 1/12th) of the daylight had expired. The first hour was sun up, the last hour was sundown. An “hour” was not a fixed duration of time, but varied throughout the seasons.

Of course this meant that in higher northern latitudes an hour in the winter was much shorter than an hour in the summer, but it was consistent and everyone had access to the same clock; the Sun.

Sun dials are just vertical sticks that cast a shadow on a calibrated dial. Where the shadow falls can give you a fairly precise indication of the hour of the day, but just looking at your own shadow, or noticing how high the Sun is in the sky was usually close enough. Our modern idea of a “clock” actually came from measuring durations, more like a timer.

Clocks

The oldest clocks measure durations using continuous physical processes that are not the Sun; usually flowing water (or sand). Water clocks appear in antiquity across many cultures, from Egypt and Greece to China. At their simplest they were cisterns with an outflow and marks that showed the level of the water. One of the problems with this is that that rate of flow of water changes as the water level decreases, and ingenious improvements were made to make this flow consistent. In both Greece and China mechanisms were added with gears that turned dials or activated bells or moved figures when a particular amount of time elapsed. It was likely these geared mechanisms that gave us one of the worlds least recognized and most important devices, the escapement.

No one really knows who invented the escapement. Suddenly in the 1300’s clock towers begin appearing all over Europe, all based on the verge escapement. The function of all escapements is to pause the continuous operation (usually of a turning gear) into steady increments, or oscillations. It’s these oscillations that give a clock it’s characteristic tic-tok. The verge escapement is simply a rod with paddles that interrupt the turning of a gear just long enough for the alternating paddle to catch the next gear. These oscillations can be “counted” by using gear trains that correlate the number of oscillations to rotations. An escapement is one of the earliest examples of analog-to-digital encoding.

The verge escapement is not particularly accurate (the intervals are not particular uniform) and these early clocks were usually off by as much as an hour a day. The earliest clock towers didn’t even have faces, they just rang bells every “hour”. But more accurate escapements were on their way (like the pendulum escapement we associate with grandfather clocks today). By the 1800’s many escapements had been designed to work with springs and pocket watches were more common than house clocks.

While these clocks were usually accurate to within minutes a day, they still had to be reset frequently, and the source of time used to reset them was the same as it had always been, the Sun.

Railway Time

How fast do you need to move to outrun the Sun? The circumference of the Earth at the equator is almost 25 thousand miles. Divide that into 24 equal pieces and you get just over 1000 miles for each hour. As you reach 45° latitude that shrinks to just over 600 miles. Over 90% of people live between 20-40°N latitude, which means if you can travel 800mph due west, you could have constant daylight in most of these places.

But you don’t have to travel that fast to notice the Sun rises and sets at different times in different places. If you get on a train at noon and travel west for four hours you might notice that the clocks when you get off say 3:26pm instead of 4:00pm like your watch. This made making train schedules problematic, and it was because of the railways that the first attempts at a standard time were introduced in Britain in 1847.

Greenwich Mean Time

Numbering latitude is straightforward; halfway between the poles is the equator which we designate as 0°then north up to 90° and south to -90°. But there is no natural “middle” for longitude, we have to pick some place to start as “0°”. This place is Greenwich, a small area within London. It is home to one of the earliest observatories where taking accurate measurements of the fixed stars and moon were very useful for determining latitude and longitude. The lines that mark off longitude are the half circles that meet at the poles, called meridians. This is an old term for midday, since midday occurs at the same time for all locations along any meridian. Since Greenwich became the starting meridian this line is also called the Prime Meridian.

The observatory at Greenwich had the equipment and skills to precisely determine midday (or midnight) in Greenwich. This became the clock that the railways throughout Europe synchronized their own clocks to. This standard time became known as Greenwich Mean Time (GMT). Depending on how far away a particular city was from Greenwich, local time may add or subtract one or more hours to this time, but the important point was that rather than synchronizing their clocks to the Sun, the railways synchronized their clocks to the clock in Greenwich. How? By sending the current time in Greenwich over the Telegraph.

Network Time Protocol

I remember when I was a kid getting my first wristwatch. I was probably 7 or 8. To set this watch I would find one of the wall clocks in our house. Sometimes these clocks would be off by five or ten minutes from each other. To find the real time there was a toll-free telephone number with a woman’s mechanical voice that would say “…at the tone the local time will be eight thirty two PM…”. I would then reset all the clocks in the house (and my watch) based on this time.

In 1928 the term Universal Time (UT) was used to replace GMT. It was still based on astronomical measurements but it fixed the time as beginning at midnight (GMT was used for midnight or midday in some places, it never specified which). In 1955 the caesium atomic clock was invented. Rather than a mechanical escapement, the oscillations come from the decay of the caesium atom itself. The accuracy of this clock made it unnecessary to recalibrate the official clocks with astronomical measurements. Beginning in the 1950’s UT time was transmitted over radio, and UT time began to transition to atomic clocks. By 1967 this new standard of time replaced UT as Coordinated Universal Time, or UTC. “UTC” is a designation, not an abbreviation, chosen to extend “UT” and be the same across languages, which is why it doesn’t match the English name.

The UTC time was broadcast over radio, telephone, and television up until the 1990’s. There are still some stations that broadcast it directly. But by 1985 there was a new mechanism that would allow computers to synchronize their clocks to this signal automatically.

The Network Time Protocol (NTP) is one of the oldest surviving protocols in use on the internet. Like DNS it is a hierarchy of servers, each an increasingly authoritative time source. Each level of the hierarchy is a stratum, with stratum 0 being the top. The stratum 0 layer contains precise time sources like atomic clocks, which are known as reference clocks. The stratum 1 computers are directly connected to these clocks, not through a network. Since there are very few of these, a much larger number of stratum 2 servers synchronize their time to them. Each stratum below increases in number, down to stratum 15, which is as far from a reference clock as you can get and still be considered synchronized.

This hierarchy of servers solves the problem of scale, but introduces a new problem. It takes time to make a network call to a server. So if a server says it’s a particular time, but it takes 200ms to get the message, then the time is already off. Each stratum adds additional latency and this adds up. What’s worse is that the latency is not constant or predictable but subject to all kinds of variables. The NTP solves this in a clever way by not simply asking the server for the time, but by sending a round-trip message of it’s own time to compare it to. If a client sends it’s own timestamp as t0 and the server immediately records the time it received it as t1, then sends a return packet containing t0, t1 and the time this packet is sent as t2, then the client can record the time it receives this return packet as t3.

Notice that even if the client and server clocks are off, the t0 and t3 times are generated by the same clock, so we can subtract t0 from t3 to get the total elapsed time to send and receive the packets. This total time includes both the latency to send the first packet and the latency to receive the second packet.

    
T = t3 - t0

But t1 and t2 are also generated by the same clock. And the difference between t2 and t1 is the time the server takes to process the messages, in other words the time between when it receives the first packet and sends the second.

    
P = t2 - t1

If there were no latency and the clocks were perfectly in sync then T would equal P. But let’s say the total latency is δ and the time the clocks are skewed is θ. If we assume the latency is the same in both directions, we can get two equations to tell us the clock skew:

t0 + δ/2 + θ = t1 (sent packet)
t2 + δ/2 + θ = t3 (received packet)

We can solve for θ in each of these, which gives us two ways to find the clock skew: one in terms of the latency to send the packet, and the other in terms of the latency to receive it. If both of these clock skews are the same, then the latency in both directions is the same, or symmetric, and we can use the clock skew to adjust our own clock.

In practice they are usually different, giving a low bound and high bound for the clock skew. To mitigate this additional packets are sent. The clock skew values are gathered and outliers are discarded and the others are filtered and fitted to a statistical regression to obtain their most likely value. This skew is used to adjust the clock. Since adjusting the clock will affect future NTP requests (the clock will have changed), this introduces feedback. So instead of applying the skew all at once it’s done incrementally, then more NTP requests are sent and the whole process tunes the skew down to a very small value, usually within milliseconds.

This process happens when a device boots and connects to the network, and every ten minutes or so it’s checked and adjusted so a device’s clock is always synchronized to a server, which is synchronized to a server, and so on until you reach the atomic clocks. This happens with every cell phone, laptop, automobile, and microwave oven connected to a network.

But what time are they all synchronizing to? The current time in Greenwich, or UTC. To know the local time requires a bit more information.

tzdata

It seems like a simple thing to chop the world up into 24 slices and simply add an hour to UTC as you travel east, UTC+1, UTC+2, etc. or subtract an hour if you travel west, UTC-1, UTC-2, etc. But many of these lines would go through major cities or split countries in distasteful ways. Also many places sharing a geography have decided to observe daylight savings time in different ways, making time zones more political than geographic. And anything political is messy.

One effort to standardize time zones has been a dataset maintained by the Internet Assigned Numbers Authority (IANA). This dataset (and accompanying software) contain a list of time zones both current and historical going back to earlier last century. The time zones are identified by English names of the format {ocean or continent}/{major city}. It does not contain geographical information (eg lat/lon) so that you must know which city you share a time zone with. For example, the time zone for Seattle (along with the west coast of the US) is America/Los_Angeles.

The dataset includes the daylight savings time rules for that time zone. This has the rules for when the daylight savings time starts and ends. It also includes the abbreviation for the time format name during these times, eg PST for Pacific Standard Time, or PDT for Pacific Daylight Time. The actual full legal names are not part of the dataset, but must come from auxiliary sources. Most operating systems on most devices have some variation of this dataset as well as extensions to it for showing legal names of time zones in various languages. But it does have the UTC offsets for each of the rules. So if your device can get the UTC time from NTP, it can use the tzdata to show you you’re local time regardless of the time of year.

As an example of how you can even get access to this data through a browser, if you open a development console and enter:

const us = new Intl.Locale('en-US');
console.log(us.getTimeZones());

It will list all 29 time zones for the United States. It also includes the localized versions of the full legal names of the time zones as well. For example:

const now = new Date();
console.log(new Intl.DateTimeFormat('en-US', { timeStyle: 'full' }).format(now));

This prints out something like:

5:56:51 PM Pacific Standard Time

Or in French:

const now = new Date();
console.log(new Intl.DateTimeFormat('fr-FR', { timeStyle: 'full' }).format(now));

Displays:

17:59:02 heure normale du Pacifique nord-américain

Notice the time is still my local time near Seattle (5:59PM), but shown in French.

One Pulsing Brain

Whenever I think of all of those NTP packets connecting all of us to a single synchronized clock it makes me think of the pulsating brain in A Wrinkle In Time by Madeleine L’Engle. The brain controls the people in that world to the point that all the kids bounce their balls in unison; creepy. But then I wake up late on a winter morning when the Sun doesn’t rise until after 8am and my body knows it’s morning regardless of what the clock says. We will never be detached from the Sun.

Etc: