Sandra Henry-Stocker
Underneath the modest veneer of the TZ environment variable (the variable that expresses the local time zone on a modern Unix system) lies a global database that can be used to calculate the local time anywhere on Planet Earth. To fully understand how this database works, one needs to first think about two disparate realities - the physical reality of our spinning planet and the political reality of countries, provinces and states.
Geometry and Time: What's Your Angle?
The physical reality of time zones is not too difficult to think about. Imagine that you are looking down at the planet from somewhere above the North Pole. Then imagine that your view of the "top" of the planet is divided into 24 pie slices, each 15 degrees (of the 360 degrees around the equator) wide. The Earth would be spinning slowly in a counter-clockwise direction - so slowly that you would be unlikely to be able to detect that it is moving at all. Each hour, the planet would turn only the width of one slice of pie.
It is fortunate, but not entirely coincidental, that the number of hours in a day and the number of degrees in a circle are numerically related (thanks to the ancient Babylonians). While both of these numbers are fundamentally arbitrary, they give us a way to relate midday in the US with midday in China. Had the human race decided to live by Universal Time, some of us would wake at noon, some of us would eat dinner at noon and others of us would be deep into REM sleep at noon. Instead, we adopted a system whereby each hour in the 24-hour day relates to the experience of the sun rising and setting in more or less the same way everywhere in the world. And, at any point in the day, it is tomorrow or yesterday somewhere else in the world (but never both).
Politics and time: Time is of the essence
The political reality of time zones is both more complicated and subject to change. Since few political regions are contained entirely within one 15 degree slice of the pie, the neat and tidy longitudinal arcs that might otherwise demark the boundaries between adjacent time zones have been stretched and distorted to allow many political jurisdictions to squeeze into a single time zone. So, when it is 3 PM in Oslo, it is 3 PM everywhere in Norway. And more surprisingly, when it is 3 PM in Beijing, it is 3 PM everywhere in China; this is in spite of the fact that China is roughly 60 degrees wide - the width of four slices of pie (or four time zones)!
While most of us have no trouble thinking about time changing as we travel East to West and vice versa, we might be startled when we have to reset our watches as we move in a North-to-South or South-to-North direction. For an interesting time-related experience, try crossing the Straits of Gibraltar from Moroccao to Spain or the Yalu River on the border between China and North Korea.
Another surprising anomaly in the global time zone map is that some countries and regions maintain time zones that differ from neighboring time zones by a half-hour instead of an hour. This includes India and, to the best of my knowledge, also Suriname, Iran, India, Sri Lanka, Central Australia and Newfoundland.
Astrophysics and time: A hard day's night
Moving back to the spinning Earth, my earlier statement that it is not too difficult to think about the physical component of time glossed over a couple of very interesting complications. For one thing, the fact that the Earth rotates on its axis is not the only determinant of the 24-hour day. The Earth's revolution around the sun also plays a small role in the length of a day. To understand this, imagine the Earth revolving around the sun WITHOUT rotating. If it did, we would still experience one "day" (i.e., one full light to dark cycle) every year because that portion of the planet facing the sun at any point would be slowly changing. If you model this movement with your coffee mug and that tension-relieving squeeze ball sitting on your desk, you might notice that this single-day year would be different from the days we actually experience not only because the day would be so very long, but also because the sun would rise in the West and set in the East.
Now, let's reintroduce the Earth's rotation. With the Earth rotating on its axis 366 times for every time it revolves around the sun, we end up with a 365-day year (more or less) because we lose one day making a complete trip around the sun for each of the 366 times we rotate.
Another complication is introduced because the Earth doesn't just spin and revolve; it also wobbles - due to the gravitational attraction of the Sun and the moon. In addition, the surface of the Earth is not exactly fixed relative to its axis. In other words, the loose coupling between the Earth's core and its surface leads to small shifts of maybe only 50 feet or so in the location of a particular geographical location - such as my farm and your garage.
When we consider time calculations with respect to the solar system or the stars, these calculations become so complex, in fact, that there are four separate systems for reporting time. This is obviously far too complex for a Unix column; If you want to know more about the subtle movements of the planet or the various ways that time can be reported, I suggest that you take an astronomer out to lunch. Ask him or her why the solar day lasts four minutes longer than the sidereal day and I guarantee that your paper napkin will soon be covered with astronomical pencil sketches!
Unix and time: All in a day's work
Given the physical and political rationale for the creation of time zones, a representation of time zones on modern Unix systems is clearly necessary. And, fortunately, a robust system for managing time zone data has been developed and is deployed on most Unix systems. The crux of this system is the TZ database - the most up-to-date source of time zone definitions available to us - and source code for performing date calculations. The TZ database allows us to manipulate time zone variables to determine what time it is in other parts of the world and enables our systems to move automatically into and out of Daylight Savings Time as appropriate for our locations.
Next week's column will look into the TZ database used on Unix systems to define time zones and the commands you can use to manipulate and examine time zone data.
Sandra Henry-Stocker has been administering Unix systems for nearly 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to mailto:sstocker@itworld.com.