4

I am writing an app that asks the user to choose a time zone. I am getting my list of time zones from the Olson database (via NodaTime) but that is a massive list with many redundant entries, for my purposes at least.

When you create an event on Google Calendar it lets you choose the time zone from a relatively small list with ordering by country where necessary. I would like to be able to achieve something as simple as that without creating a separate database, which is what this person does.

Because I am writing this in C# MVC plus JavaScript on the front end, I am looking for a library in either of those languages that gives me a reduced list in a user-friendly format that I could display in a dropdown. Is there such a thing or do I have to create my own and regularly keep it up to date, like the example shown in the hyperlink?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Rob Kent
  • 5,183
  • 4
  • 33
  • 54
  • I have discovered that my question is almost identical to this one: http://stackoverflow.com/questions/13056759/how-should-i-populate-a-list-of-tzdb-olson-timezones-from-nodatime?rq=1 I an delete mine if that is the convention but I have left it here because it contains additional information not in the other one. – Rob Kent Nov 10 '12 at 11:55

1 Answers1

3

Two possible answers here:

  • Information from the zone.tab file. As it happens, just today another contributor mailed the list with an hg clone which uses this data. I haven't looked at it yet, but hope to do so over the weekend - and after a bit of massaging, we'll hopefully get it into the 1.1 branch.

  • Information from CLDR. This provides suggested example cities to present to a user - it's designed for exactly this purpose (even localized, I believe). However, you'd need to integrate this with Noda Time yourself; we don't currently have any code for this, and just getting to grips with CLDR will take some time.

Apologies for this not being solved out of the box - but we're aware of it and hope to provide an answer over time.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks. The CLDR looks like too big a toolset for me to grasp in my timescale :) but the ZoneLocation code looks interesting. I am going to clone it and see if it works for me. – Rob Kent Nov 10 '12 at 12:13
  • I cloned Matt's code and tested it. It certainly reduces the list to some order but doesn't produce the reduced list that I am looking for. GetZonesByCountry("GB") produce seven zones where I only need one. GetZonesByCountry("US") produces 48 whereas the Google Calendar list has seven. I don't understand the tz database well enough to know how you would reduce it further (unambiguously) so I need to study it some more. Thanks. – Rob Kent Nov 10 '12 at 13:30
  • I'm assuming that when tzdb returns europe/belfast, europe/london and europe/jersey for GB, it's because they are different jurisdictions and could potentially have different rules. Because they don't practically have different rules, as far as I know. So I guess I need a 'lenient' version that does a 'group by ruleset' within country and also knows to choose the most significant, ie London not Jersey. I doubt that this is core NodaTime though, more a UI concern. – Rob Kent Nov 10 '12 at 15:34
  • @RobKent: Based on my poor understanding of zoneinfo rules, it looks like those are aliases, yes. Will edit my answer to give an example of how to get a "normalized" set of IDs. (Will also add it into the codebase as a demo...) – Jon Skeet Nov 10 '12 at 15:41
  • @RobKent: Hmm. Looks like it's not quite as simple as I thought. We handle the link transparently, so you still get a zone of Europe/Jersey. Will have a look at how we can expose the aliasing. See https://code.google.com/p/noda-time/issues/detail?id=32 – Jon Skeet Nov 10 '12 at 15:47
  • @RobKent: The default branch now has a fix in. See https://code.google.com/p/noda-time/source/detail?r=fbf49bd8ec7237da638810356f14940bc0e6fb74 – Jon Skeet Nov 11 '12 at 21:09
  • Thanks for that, but I am still not sure what tells me which is the canonical one. If I were to clone your latest code and then merge Matt's ZoneLocation change, his GetZonesByCountry method would need to keep only canonical ones? Is that right? – Rob Kent Nov 12 '12 at 14:21
  • @RobKent: I haven't checked Matt's code, but the *keys* in the Aliases lookup are the canonical IDs. – Jon Skeet Nov 12 '12 at 14:29
  • Glad to see someone else has the same concerns. :) I too would like some way to present a simplified list to the user, perhaps the CLDR data is what we really need? I'm not dead set on zone.tab, I just thought it might be useful. – Matt Johnson-Pint Nov 13 '12 at 01:31
  • @RobKent There were some bugs in the first pass I did of the zone.tab implementation. Try this one http://code.google.com/r/mj1856-noda-time/source/detail?r=db68aca2aef855ed63dc2bb1accba51beafea889 and you should only get 1 zone for GB. There are 30 for US. The source file is here http://code.google.com/p/noda-time/source/browse/src/ZoneInfoCompiler/Data/2012i/zone.tab – Matt Johnson-Pint Nov 13 '12 at 01:41
  • @Matt: Thanks, I'll be getting back to this in a couple of days and I'll take a closer look at the data. It would be nice to find a way to reduce that 30 US list to the 7 that Google show. – Rob Kent Nov 13 '12 at 09:44