h1

Time flies like a banana

May 3, 2012

As we traveled east, many of the gadgets have not done well with the time change. The iPhone, teacher’s pet that it is, offers a near perfect user experience. As we crossed the time zones, the iPhone continues to display local time whatever that is.

For something so seemingly easy, that is incredibly difficult. None of the other gadgets come close.

The iPhone has four sources of time, let’s go through them and work through why the other gadgets don’t work as well. First, the phone, like many gadgets, has a clock. This is a crystal that counts how many ticks since it was booted. The ticks could be from a  32.768kHz crystal (a real-time-clock or RTC component that keeps a slow-for-a-computer heartbeat). Like any watch, all you need to do it tell it what local time is, and the RTC (or other crystal) maintains it. However, it will drift off from the correct time (particularly if it stays in a hot car for a long time or in a particularly cold room). So when your 1984 Star Wars watch would lose a couple minutes a month, that is why. The clock counts ticks from when you set it but if the ticks are off by 0.01%, you end up losing a minute a week.  Temperature extremes makes this worse.

Ok, so that is old, old method for doing it. But if you have nothing else, a gadget with a crystal will keep time reasonably well. Though, it can’t tell if you’ve crossed timezones. That is why we had to reset the car’s digital clock every day or two.

The iPhone also has a GPS which isn’t only for location. GPS provides very accurate time information. However, the time is not local time but UTC (Coordinated Universal Time) which, for this purpose, is the same as GMT (Greenwich Mean Time, from when Greenwich, England was the center of the world). In California, we were GMT-8. Well, sometimes; California has daylight savings time so the offset shifts depending on the season.

This is (nominally) to reduce energy consumption as people tend to be clock based. The time shifts so the bulk of the daylight is after people wakeup. Sunlight at 4am in’t that useful but by shifting the clock, that sunlight moves to 5am and the evening light moves from 7pm to 8pm, a reasonably big win for folks stuck in 9-5 jobs.

Gadgets hate daylight savings time. Well, the programmers of gadgets hate DST.  Not everywhere in the US has daylight savings time (ahem, Arizona!). So now, a gadget using GPS time needs to know how to map from location to time and whether that place uses daylight savings time. It also needs to know when DST begins and ends, which can change (thank you, President Bush), causing devices that you (the customer) end up having to change 4 times every year (correct DST, gadget’s faux correction; forward and back). Oh, but there are some counties in the US that vote on whether to do DST each year so it isn’t enough to just use the current protocol.

GPS provides a signal that is both good and bad: it is very accurate (the gadget can know how long a second is to nanosecond precision) but not very precise (the gadget can be hours off of local time but it would always know what time it is in Greenwich (gee, thanks, England!)). Since it is very accurate, I’ve used it in devices to time how long something took, was it 0.00011 seconds since the system heard a gunshot or 0.00013 seconds? As a stopwatch, the GPS clock is fantastic.

A GPS can also be used to keep a a crystal real time clock accurate. Every time GPS updates the time (every second), the gadget (microprocessor) counts how many ticks the RTC had. Now, it can predict for the next second how many ticks there will be (the drift associated with the crystal is relatively slow so this works well).

The user still has to set the time. And reset the time for daylight savings time. And change the time when the user moves to a new timezone. The GPS gave us accuracy but didn’t solve any of the other problems.

Ok, so the iPhone also has WiFi which can help with some of these. It can use the internet to contact a mainframe server and ask, “what time is it?” The gadget doesn’t really need a GPS for accuracy, it can use the standard servers and Network Time Protocol (NTP) to get accurate timing information (or Simple Network Time Protocol to get reasonably accurate time information). Unfortunately, this is UTC as well so it has all the disadvantages of GPS: it has to ask the user for their offset (usually they ask you to select a nearby city and the gadget figures it out; and all of the daylight savings time complexity). NTP is a general internet service, available using different servers. A gadget manufacturer can instead have the gadget call home to their own server which can provide more information than just NTP.

However, if the gadget has WiFi and GPS, it can contact a server with a query that essentially says, “I’m here, what time is it?”  The GPS isn’t completely necessary for the WiFi phone-home method to work. There are databases of WiFi networks and their location (the iPhone uses those to help locate you!) so the gadget can phone home with the WiFi network and probably get the time that way.

The server can have a much larger daylight savings time database than the gadget (and one more easily updated with the vagaries of humans). The weak point of this plan is the server… if the gadget can’t get there, it will act stupid.

In the car, the gadgets don’t have WifFi so things like the iPad don’t get updated until we get to a hotel and log on. Then, the iPad, disconcertingly, loses an hour sometime between I get used to it being wrong and when I look at it again and wonder how it got so late.

There isn’t  a standard for how to do this conversion from location to local time. Well, there is the Network Identity and Time Zone protocol but if you go look at that you’ll notice is isn’t exactly a networking protocol with the ubiquity of NTP. Instead, it is phone based.

The iPhone is actually a cell phone (yes, I know it is a somewhat terrible phone but it has cellular technology so we’ll give it the benefit of the doubt). As this gadget moves, it connects to the cell towers and asks, “Beg pardon, but do you have the time?” and changes to the new time if the cell towers give something different than the device’s current time.

So, all a gadget needs is a cellular modem and a contract with one of the major cell phone vendors. Then it can function as a reasonably accurate clock, always updating to local time.

Or the gadget can just assume its customer never leaves their home time zone and make them set the initial time. And then it can use a crummy real time clock and let the time drift. Not that big of a deal, the clock will be correct-enough 99% of the time. Since we want our gadgets to be cheap, not many things can afford to have all the supporting hardware.

(Thanks to Christopher White who complained enough about broken gadgets that I put this together._