It’s About Time

I’m pretty good with time zones. After all, I live in Germany, Hackaday’s server is in Los Angeles, and our writers are scattered all over the globe. I’m always translating one time into another, and practice makes (nearly) perfect. But still, it got me.

I was in the states visiting my parents, when Daylight Saving Time struck, but only in the USA. Now all my time conversions were off by an hour, and once I’d worked through the way the sun travels around the globe, I thought I had it made. And then my cell phone started reporting a time that was neither CEST nor EDT, but a third time zone that was an hour off. Apparently some cell towers don’t transmit time zone information, and my phone defaults to UTC. Who knew? For a short while, my phone lied to me, the microwave oven clock in the hotel lied to me, and I felt like I was going nuts.

But this all got me thinking about clocks and human time, and possibly the best advice I’ve ever heard for handling it in your own programs. Always keep time in something sensible like UNIX time – seconds elapsed since an epoch – because you don’t have to worry about anything more than adding one to a counter every second. When and if you need to convert to or from human times, you can write the function to do that simply enough, if you don’t already have a library function to do so.

Want to set an alarm for 2 hours from now? That’s easy, because you only need to add 7,200 seconds, and you don’t need to worry about 59 wrapping around to 0 or 23:59 to 0:00. Time math is easy in seconds. February 29th? That’s just another 86,400 seconds. It’s only us humans who make it complicated.

How Many Time Zones Are There Anyway?

Nowadays, it’s an even bet that your newest project somehow connects to the Internet and, thus, to the world. Even if it doesn’t, if you share your plans, someone might reproduce your creation in some far distant locale. If your design uses time, you might need to think about time zones. Easy, right? That’s what [Zain Rizvi] thought until he tried to deploy something that converted between timezones. You can learn from his misconceptions thanks to a detailed post he provides.

You might think, “What’s the big deal?” After all, there’s UTC, and then there are 12 time zones ahead of UTC and 12 time zones later. But that’s not even close to true.

As [Zain] found out, there are 27 hours in a full-day cycle if you count UTC as one hour. Why? Because some islands in the Pacific wanted to be on the wrong side of the International Date Line. So there are a few extra zones to accommodate them.

You can’t even count on time zones being offset by an hour from the previous zone. Several zones have a half-hour offset from UTC (for example, India’s standard time is 5.5 hours from UTC). But surely the offset is always either a whole number or a number where the fractional part is 0.5, right?

Um, no. Nepal wants the sun to be directly over the mountain at noon, so it offsets by 45 minutes! [Zain] wonders — as we do — what would happen if the mountain shifted over time? Until 1940, Amsterdam used a 20-minute offset. Some cities are split with one half in one time zone and another in the other.

Of course, there are the usual problems with multiple names for each zone, both because many countries want their own zone and because the exact same zone is different in different languages. Having your own zone is not just for vanity, though. Daylight savings time rules will vary by zone and even, in some cases, only in certain parts of a zone. For example, in the United States, Arizona doesn’t change to daylight savings time. Oh, except for the Navajo Nation in Arizona, which does! Some areas observe daylight savings time that starts and ends multiple times during the year. Even if you observe daylight savings time, there are cases where the time shift isn’t an entire hour.

Besides multiple names, common names for zones often overlap. For example, in the United States, the Eastern Standard Time zone differs from Australia’s. Confused? You should be.

Maybe we should have more respect for multiple time zone clock projects. We’ve noticed these problems before when we felt sorry for the people who maintain the official time zone database.

Hackaday Links Column Banner

Hackaday Links: December 7, 2014

Have some .40 cal shell casings sitting around with nothing to do? How about some bullet earbuds? If you’ve ever wondered about the DIY community over at imgur, the top comment, by a large margin, is, “All of these tools would cost so much more than just buying the headphones”

Here’s something [Lewin] sent in. It’s a USB cable, with a type A connector on one end, and a type A connector on the other end. There is no circuitry anywhere in this cable. This is prohibited by the USB Implementors Forum, so if you have any idea what this thing is for, drop a note in the comments.

Attention interesting people in Boston. There’s a lecture series this Tuesday on Artificial Consciousness and Revolutionizing Medical Device Design. This is part two in a series that Hackaday writer [Gregory L. Charvat] has been working with. Talks include mixed signal ASIC design, and artificial consciousness as a state of matter. Free event, open bar, and you get to meet (other) interesting people.

Ghostbusters. It’s the 30th anniversary, and to celebrate the event [Luca] is making a custom collectors edition with the BluRay and something very special: the Lego ECTO-1.

Let’s say you need to store the number of days in each month in a program somewhere. You could look it up in the Time Zone Database, but that’s far too easy. How about a lookup table, or just a freakin’ array with 12 entries? What is this, amateur hour? No, the proper way of remembering the number of days in each month is some bizarre piece-wise function. It is: f(x) = 28 + (x + ⌊x8⌋) mod 2 + 2 mod x + 2 ⌊1x⌋. At least the comments are interesting.

Arduinos were sold in the 70s! Shocking, yes, but don’t worry, time travel was involved. Here’s a still from Predestination, in theatres Jan 9, rated R, hail corporate.