Elements or Lower

Tue, 17 Jul 2007

Breaking America

We’re now running a honeymoon gift list for the UK, and a honeymoon registry for the USA.

Aside from the different terminology (which actually works in our favour to help to direct the most popular search queries on each side of the pond to the correct version of the site), one of the key changes we had to make was getting the various dates and times to behave correctly outside of the UK. I’d never actually built proper timezone support into anything before, so this was something of a learning curve for me.

Dave Rolsky’s excellent DateTime modules bore the brunt of the real work for this, of course, but I was anxious to make sure that assigning the correct Olson timezone to a couple’s list didn’t become a hurdle when signing up.

Although there are 26 actual Olsen timezones for America, only a handful are currently relevant. For example, both America/New_York and America/Detroit describe Eastern Standard Time. So, instead of asking our customers to choose between them, we only need ask whether they’re in Eastern, Central, Mountain, Pacific, Alaskan or Hawaiian time. Or Arizona, which irritatingly is just the same as Mountain Time, but without daylight savings. If you choose Eastern, you’re assigned America/New_York behind the scenes.

There aren’t many countries that have more than one timezone, of course. So I set up a small database table for the Olsen timezones, recording the country for each. When you select a country from the dropdown list on our registration screen, a small blob of Ajax kicks in to query this database. If there’s more than one (relevant) timezone for the country you’ve selected, a second dropdown appears listing those timezones. If not, a hidden field is assigned the ID value of the only timezone for that country.

There’s another small Ajax routine on each page of the UK site now to try to direct US visitors to the US version of that page. If your offset from GMT, as reported by your browser, is more than 3 hours behind, a panel is revealed at the top of the page:

The panel reads: "This is the UK version of this page.  View the US version."

We had our first sale to the US today, thanks to the glory of AdWords. Let the conquest begin!