Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Real Time Zones


Oct01: Embedded Space

Ed is an EE, PE, and author in Poughkeepsie, New York. You can contact him at [email protected].


You've undoubtedly seen the ads extolling the virtues of Atomic Clocks: They're always accurate, automatically step into and out of Daylight Savings Time (DST), and handle leap years with aplomb. You can even get an Atomic Watch that's waterproof to 30 meters.

The distributors obviously view these doodads as geek appurtenances, because American society at large will have nothing whatsoever to do with atomic or nuclear anything. Atomic power? Radon? Uranium, depleted or otherwise? When nuclear magnetic-resonance-imaging systems moved out of the lab and into the hospital, they shed that first, most fearsome, word almost instantly. Atomic watches obviously don't stand a chance with most consumers.

Despite the name, atomic timepieces include no "atomic" parts whatsoever, other than their constituent atoms. Instead, they incorporate a radio receiver tuned to the WWVB time signal from the National Institute of Science and Technology's Colorado transmitter. It's not clear to me that the intricate NIST time standard hardware can still be called an "atomic clock," but that's the name of the game.

Several times every 24 hours, generally during the night for best reception, the timepiece turns on its receiver, decodes the WWVB time signal, adjusts its display to match, and then shuts the receiver off to save power. A standard quartz crystal oscillator maintains the time for the rest of the day, just like essentially every other electronic clock in the world.

Ah, now, crystals. Americans love crystals. Sheesh.

Enough of that. What do nonatomic atomic clocks have to do with embedded systems? Simple: They provide an interesting example of the interplay between reality, specification, and implementation that affects nearly any project. The watches work, they do pretty much what's claimed, but there's ever so much more to the story.

The Source of Time

The Babylonians started the practice of dividing day and night into 12 parts apiece, giving us the familiar 24-hour day. They also had a sexagesimal fascination that begat 60-minute hours and 60-second minutes, albeit much later when technology permitted such fine divisions. As with most such decisions, base-60 must have made sense at the time.

The French tried and failed to rationalize timekeeping by introducing decimal time in the late 1700s, with three 10-day decades per month, two 10-hour sections per day, 100 minutes per hour, and 100 seconds per minute. Not even the Revolution could change the 12-month year and, after about 13 years of dogged effort, France rejoined the rest of the world with Babylonian standard timekeeping.

Up through the late 1800s, timekeeping remained a largely local affair, with the sun's maximum declination determining the moment of noon. When railroads reached continental scale, consistent time became more than a convenience. After all, how can anyone make the trains run on time when each station sports a different time?

The 1884 International Meridian Conference established Greenwich Mean Time (GMT) as the worldwide standard and introduced the notion of time zones. With two exceptions, each zone occupied 15 degrees of longitude and represented one hour of the sun's travel around the earth. For this application, the old geocentric model worked perfectly well.

The Zero Meridian passed through Greenwich, England, around which the Conference centered the zero-th time zone. Within each zone, local time became equal to GMT plus or minus an offset determined by the zone's longitude relative to Greenwich. This ensured all clocks showed a consistent time throughout each zone.

The Conference defined the two zones at GMT+12h and GMT-12h to occupy 7.5 degrees each, with the International Date Line separating them. If you count carefully, you'll discover that includes 25 time zones: 12 leading and 12 lagging GMT, plus the zero-th zone.

Several gotchas complicate this orange-fruit-segment, integer numbered, Platonic ideal. For obvious reasons, nations tweaked the actual time zone boundaries along political boundaries, producing bumps and dents in what should have been Great Circle arcs. The continental U.S. used four zones, while all of similarly sized China used a single zone set to the Beijing (or Peking or Peiping. Never hardcode strings!) offset.

A current time zone map shows 37 time zones, with time offsets ranging from -12 to +14 hours. Obviously, there's been some serious gerrymandering since 1884.

Nations may also define their own clock offsets. Despite the compelling logic of exact hour differences, places as diverse as Newfoundland and Nepal sport half-hour offsets. In fact, an old time zone map in my collection clearly shows Nepal at GMT +5-2/3: a 40-minute offset. Other, ostensibly current, sources tell me Nepal uses a +5:45 offset.

Go figure, indeed.

Daylight Confusion

In addition to setting their own zones, boundaries, and offsets, many nations use Daylight Savings Time to shift more daylight into the hours when most people are awake. Contrary to a popular misconception, DST occurs during summer, not winter.

Generally, local time steps forward one hour in the spring and backward one hour in autumn; "spring forward, fall back" may be burned into our DNA by now. The exact dates and amounts remain under national control, with the usual results.

During the Second World War, for example, the U.S. remained on DST continuously for over three years. England used "Double Daylight Time," stepping ahead one hour in the winter and two hours in the summer. Again, all this made perfect sense at the time.

For an idea of how difficult DST adjustment algorithms can be, consider Microsoft Knowledge Base Article Q139807, which describes this exquisite little Windows 95 inconvenience:

The Daylight Savings Time tool changes the time back one hour as it should, but does not notify the system that the change has been made. Therefore, the process keeps repeating at 2:00 am.

Fortunately, I don't even have a heartbeat at that hour of the morning and have never been stuck in a time loop.

Time Source

The final puzzle piece arrives from radio station WWVB. The more familiar WWV and WWVH broadcasts, intended primarily for human audiences, can be picked up on any shortwave receiver. WWVB, however, transmits the current Coordinated Universal Time (abbreviated UTC from the French acronym) in machine-readable BCD at 1 bit per second on a 60-KHz carrier frequency that can't be tuned by most general-coverage receivers.

Yes, the data rate really is 1 bit per second. The entire time code repeats once each minute, with 43 data, 10 unused, and 7 framing bits. The 60-KHz carrier provides a phase reference, and the BCD digits give the actual time at the start of each minute.

In addition to the current minute, hour, day, and year, the time code indicates leap seconds, leap years, whether DST is in effect, and a few other odds and ends. If you need sidereal (pronounced "sigh-DEER-al") time with subsecond resolution, the signal includes the current fractional-second offset between UTC and UT1 but, if you know and care about that, you probably haven't read this far anyway.

Now, let's put everything together.

Here and Now

Because WWVB transmits UTC time, the receiver must know its offset from UTC. That's what the time zones tell us: Adding the zone's offset to UTC produces local time. For example, the east coast of the U.S. is in time zone -5, so 1200 UTC becomes 0700 Eastern Standard Time (EST).

At least in the winter, that is, with EST in effect. During the summer months the east coast of the U.S. enters Daylight Savings Time, steps forward one hour, and the time zone offset becomes UTC-4 hours: 1200 UTC becomes 0800 Eastern Daylight Time (EDT).

The WWVB signal includes DST information so, given the time zone, the receiver can figure out the correct local time. Except, of course, in Arizona, Hawaii, or the 77 Indiana counties that do not observe Daylight Savings Time. In those areas, the watch inexorably displays the wrong time.

Indiana has a particularly interesting situation. The state's 92 counties span the Eastern (-5) and Central (-6) time zones. The eastern five counties switch from EST to EDT, and the western 10 switch from CST to CDT, but the central 77 remain on EST throughout the year. Even if the watch knew what state it was in, it still couldn't show the right time!

New Zealand presents another boundary condition, because they're in zone UTC+12 during their winter months. Because they observe DST, their time jumps to UTC+13 in the summer, just about when the northern hemisphere switches out of DST. I wonder if radio-controlled watches can handle a 13-hour winter offset?

I don't know if the watches include a DST override function to disable the automatic adjustment. The only other choice would be to use an adjacent time zone to make the numeric answer come out right. Travellers to Arizona, for example, would normally set their watch to Mountain Standard Time (MST), except during the usual summer months when they must set it to Pacific Standard Time (PST) so the automatic adjustment to PDT would kick the display back into step.

As a result, only those people who wouldn't ordinarily have anything to do with DST must adjust their atomic timepieces twice each year. This is progress?

Fractional Time

The advertisements I've seen mention that the radio-controlled watches and clocks have adjustments for "24 time zones," which sounds reasonable until you recall that there are really 25 ideal and 37 actual zones. I assume, without any justification, that they do not count the UTC zone itself as a time zone and list only the 24 offsets from that base.

Newfoundland provides a useful boundary test case for this situation. Although it's geographically in the Atlantic Time Zone with a -4-hour offset, it adds an additional 30 minutes so that local time is UTC-3:30. I'm reasonably sure that Newfoundland Standard Time isn't among the 24 (or 25) time zones included in the watch's repertoire, which means you must set the time manually.

This is not an isolated situation, as 10 of the 37 time zones on that map I mentioned earlier use half-hour offsets from their nominal zone time. And that doesn't include whatever Nepal's offset might be this week.

The WWVB transmitter emits 50 KW of RF power and covers nearly all of the continental U.S. with an effective signal. It does not blanket the world, so travellers must rely on the accuracy of the internal quartz oscillator when they are out of range.

Newfoundland lies just on the fringe of the WWVB coverage area, so we may safely assume (by invoking the Law of Conservation of Perversity) that a radio-controlled watch will occasionally receive a valid signal. Unless you disable the receiver in your watch, it will automatically adjust itself to the wrong time whenever it hears WWVB.

It's worth noting that Newfoundland also observes DST, but the changeover does not occur at 2:00 am local time as it does in the U.S. The governing statute for Newfoundland specifies that the time changes one minute after midnight, which leads to interesting complications: The effective time steps across a day boundary.

I suspect, without evidence, that Windows 95 would have trouble with those transitions, too.

Redundant Errors

A friend called a while ago and asked if I knew any reason why his new WWVB-based alarm clock might be off by exactly six hours for a while, then snap back to agree with his other, nonradio clocks. The changes seemed to come overnight, when radio reception improves.

Although it may seem strange, the WWVB signal does not include any error-detection or correction bits. Given generally noisy reception and the consequent bit errors, the receiver must sanity-check the framing bits, verify that the time code steps sensibly in successive minutes, and use copious redundancy to overwhelm entropy. This is not as bad as it sounds because the short-term drift of the local oscillator can be quite good. Indeed, a single daily synchronization will suffice for most around-the-house timing purposes.

We both decided that his clock's error-detection algorithm, whatever it might be, had mistakenly accepted at least one invalid time frame. Until it accepted a valid frame, which it might not be able to do for the next 24 hours, the clock displayed the wrong time. There being no manual override, what you saw was what it got, for a whole day.

Now, if the guts of that clock formed part of a system that depended on always having the correct time, there could be some nasty side effects. In order to ensure a valid time code, you must endure a considerable delay, and oscillator stability becomes a significant part of the overall spec.

What's Wrong With...

Although we engineering and programming bears tend to think of time as an inherent part of the universe, it's actually a political construct and, as with all things political, subject to change essentially without notice.

Back in the bad old days, when humans either set their own clocks or got along perfectly well without them, governments could change nearly anything on short notice with impunity. Add a few days to the calendar? Define time zones? Tweak the definition of the second itself? Anything was possible.

Now that the world depends on precise, synchronized clocks, such wrenching changes become decreasingly likely. At some point, though, DST will probably vanish, simply because accounting for duplicate and missing hours twice a year is such a pain in the CPU.

Actually, political time forms just the tip of the legal iceberg, as any and all of the rules and regulations you (or your lawyers) depend on may change during your product's development. It's not like pure engineering, where physical constants and equations generally remain fixed for decades.

Conversely, there may be no such thing as pure software engineering, where even the development tools have the lifetime of a mayfly. But that's an entirely different rant.

The user interface forms another part of the problem. Just how much complexity do you want to jam into a wristwatch-sized case with two or three buttons? No, the IBM Linux watch (http://www.research.ibm.com/WearableComputing/factsheet.html) doesn't count.

The lesson to be learned? Even when your project's specifications seem simple and well contained, Stuff Happens.

Reentry Checklist

Not all radio-controlled timepieces have all the faults I've mentioned and, in particular, industrial-grade clocks get nearly everything right, sometimes by using GPS receivers to supplement or replace WWVB. The issue involves trading off cost with power consumption with code size with performance: A simple, cheap digital wristwatch simply can't include the same features as a kilobuck whole-building timekeeping system.

A web search will tell you more than you want to know about time zones, so start from http://www.rog.nmm.ac.uk/ at the Zero Meridian. The U.S. Naval Observatory provides information and up-to-date, printable, time zone maps at http://aa.usno.navy.mil/faq/docs/world_tzones.html. Set your computer clock directly from NIST at http://www.boulder.nist.gov/timefreq/index.html or get it in human-readable format from http://www.time.gov/.

You'll find links to home pages for other LF time code transmitters at http://www.cl.cam.ac.uk/~mgk25/lf-clocks.html.

Answering the question "What time is it?" can be surprisingly difficult. The Network Timekeeping Protocol RFC at http://www.faqs.org/rfcs/rfc1305.html has a good overview of the various Universal Time systems and discusses what happens when time doesn't increase monotonically.

Although I'm not going to even mention Swatch Internet Beats, Vernor Vinge described an honest form of decimal timekeeping in A Deepness in the Sky. A spacefaring race will have little use for the notions of day and night, let alone conversions between hours, minutes, and seconds. After a few centuries, you might well say "kaysec" instead of "15 minutes" and "emsec" instead of "week." True hackers will appreciate Qeng Ho localizers and recognize Focus, if not mindrot, as a common personality trait among their peers. Go read it.

Spencer Weart's Nuclear Fear explains why we mistrust anything and everything atomic. Oddly, despite the subtitle ("A History of Images"), the book contains not a single picture. The mind's-eye images are graphic enough for me.

DDJ


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.