UEH

Newsgroup message

A lot of time in development is spent making nearly invisible solutions to complex problems. Take for example the event stuff I’m working on right now (and have worked on most of last week, and even some of the weekend).

Basically an event is just a date with some info attached to it (thanks for that description Joris :-P). But how do I store this date? Events take place all around the globe, so, to accurately store and represent the date of a party I somehow need to know in which timezone it takes place.

Now, I could put a giant dropdown with all available timezones on the form used to submit a event… but I believe that wouldn’t be very user friendly. Is it reasonable to expect that you know the timezone name or GMT offset of a date you are entering? I don’t think so, even more if you take in account you might be submitting an even that doesn’t take place in your region… So I dug a little further into timezones.

Most countries on this planet only have one timezone. So if I provide a country dropdown I can deduce the timezone in a bunch of cases. Also, the country of an event is a much more reasonable thing to ask, unlike the timezone.

We all know the giant “Please select you country” dropdowns found all over the internet. Getting one of those is not that hard, Rails even has/had it built in. But, I don’t just want the countries, I want them grouped by continent making them (theoretically) easier to find in a huge list. Getting a list of countries grouped by continent (trustworthy and in a usable format) is much harder…

So I spent some time Googling and after a while I found the United Nations M.49 standard. Which is a list of countries nicely grouped by continent and subregions. After some copying and pasting, some reformatting (I’m skipping some parts here) I had this list in a database.

Now, to find the timezone of a country I use TZInfo. This library enables me to lookup a country by it’s ISO 3166-1-alpha-2 code and get the associated timezones. The M.49 region list does not include this two letter code. Luckily the list of ISO 3166-1-alpha-2 codes in a usable format is easy to find.

Since the ISO3166 list is based on the M.49 list (the country names are the same) I just have to perform some spreadsheet magic to combine the data. Now I have a list of both country names and the codes needed to get a country’s timezone(s). Providing a nice and clean solution for the timezone problem for most European countries.

Sadly, all of this, still isn’t enough for those pesky multi timezone countries… even worse, these multi timezone countries include the United States, Canada and Australia. Obviously, I cannot ignore these countries as it’s quite probable that some of the event will take place in those regions.

I believe I can solve the US’ timezone ambiguity by asking which state the event takes place in but I’m not sure… I haven’t even got a clue about the other ones.

So I’ll probably spend the next couple of days finding out how to overcome this last hurdle. If I can’t figure it out I’ll have to resort to providing a timezone dropdown if the event takes place in a multi timezone country. At least I can limit the list of options to only those timezones that are available in the selected country.

Yes, sometimes things are (or can be made) a lot more complex than they seem to be.

Upcoming parties/events

Show more events or add a party