tags:

views:

47

answers:

2

The task:

Time zone chooser widget that allows site visitors to choose their time zone should be generated and populated with reasonable data. It should offer choices like this:

GMT-11 (HH:MM actual time in that zone)
GMT-10 (...)
GMT-1 (...)
... now for the tricky part:
GMT (...)
GMT+1 (...)
... and then all the way until +12.

When user chooses different time zone, server should be able to figure out what time zone to set. This second part isn't much of a problem, once list is populated with correct data.

The problem:

Tricky part is getting actual timezones which are currently in use world-wide. I know how to get entire list of timezones, and how to get their offsets and current DST settings. But, each time zone has two variants: regular time and DST time.

In above list I have marked certain "tricky" part. This is where time zones like Europe/London are. During regular time, Europe/London = GMT, but during DST, Europe/London = GMT+1... Can you see a problem?

What troubles me also is that not all time zones change from DST to regular time and vice-versa, so I can't just populate list with generic data like -11 = GMT-11, -10 = GMT-10, ... and then just apply some logic to locate time zone with appropriate time difference and then set that time zone as a default from that point on.

I'm interested to hear how other sites, that utilize this time zone switching feature, come up with a list of time zones and a logic to choose right time zone, depending on user's choices? Something else you'd like to add or ask?

A: 

Have a look at what Google Calendar does. It displays the standard time offset as well as the city name, e.g.

(GMT+01:00) Tunis

That seems a pretty reasonable way of representing them, too me. On the other hand, I'm aware that some UIs list the current offset from UTC along with the city. Either way you'll confuse people, to be honest.

Jon Skeet
So this is one of those questions without a precise and lucky answer...
mr.b
Well, okay, Google doesn't adjust time zone names, regardless of current DST settings. My zone shows as GMT+1, but currently it is GMT+2 (or is it UTC+2?). When I give it a second thought, it is actually correct (most of the time), since GMT itself is a relative term, and UTC is absolute one. If it was UTC+1, then it would be inaccurate...
mr.b
@mr.b: No, GMT is always (very nearly) UTC. During the summer, the UK is on BST, not GMT. But yes, Google Calendar ignores DST, showing you your standard time offset.
Jon Skeet
@Jon Skeet: Oh, I see. Thanks for the clarification.
mr.b
@Jon Skeet: While we're at London example, can you explain to me how comes that London's offset values vary, in PHP's database, from GMT (0/dst off), via BST(3600/dst off and 3600/dst on) to BSDT (7200/dst on)?
mr.b
@mr.b: During the war, we had double daylight saving time. See http://www.srcf.ucam.org/~jsm28/british-time/
Jon Skeet
A: 

The most commonly used source for time zone data is the tz/zoneinfo database - it's publically available for free.

As you have noticed yourself, a timezone is an political/administrative entity consisting of a base offset, DST switching dates, and even historical data about changes in these, which you need to correctly deal with historical dates (such as six and a half minutes that officially don't exist).

The tz database (and most apps that use it) therefore represent a timezone not through a base offset, but through the name of the continent and a large City that uses it, often the capital of the country that uses that particular time zone. Examples: "Europe/Berlin" or "Australia/Darwin".

Michael Borgwardt
So, basically, I'll be good off with associating one major city from each timezone with one time offset (say, +1 London), but wait - offsets differ and it might not work around time when DST changes in those cities, it might even happen that two zones have same time due to two nearby zones changing time at different dates... I'm still clueless.
mr.b
@mr.b: you still don't seem to understand: it's perfectly normal to have multiple different time zones with the same offset at any given time. The offset is *not* a useful identifier for a time zone. That's why the tz database uses city names, and they have thought long and hard about it. Besides, most users probably don't know their exact UTC offset anyway, but they certainly know which cities are in their country.
Michael Borgwardt
Understood. Thanks for the clarification.
mr.b