0

I want to provide a DB table of time zones so that a UI users can be associated with one of these and would like to know views on the best practice for storing these. Obviously we could just go with storing the windows or tzid zone name as key but this seems wrong, I don’t like storing platform specific information in the database. The information is coming out of an API which may be consumed by Java or windows clients, so presenting Java clients with a windows time-zone seems wrong. Is there a recognised ISO standard (or similar) list of time zone codes that can be used as the primary key?

I have stumbled across this:

http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html

I'm not sure that it helps me though!

Vman
  • 3,016
  • 2
  • 24
  • 20

2 Answers2

1

Yes, IANA maintains an official list of time zone information that defines these identifiers.

To get a guaranteed authoritative dataset download the latest package and parse the zone.tab file for the timezone names.

Jon
  • 428,835
  • 81
  • 738
  • 806
  • Thanks, it looks like the right answer (It’s not pretty though – we cant exactly steer customers there!). – Vman Dec 03 '13 at 15:07
0

There are several items in your question that I'd like to comment on:

I want to provide a DB table of time zones so that a UI users can be associated with one of these and would like to know views on the best practice for storing these.

You shouldn't attempt to build a table of time zones in your database. Time zones aren't static. They change constantly. If you use Windows time zones, you get these updates via Windows Update, and if you use IANA zones, you should be staying on top of the updates yourself. Either way, there are multiple updates per year, and you shouldn't relay on a secondary source of the data that could go out of sync.

If you are using Windows zones, iterate TimeZoneInfo.GetSystemTimeZones(), show the DisplayName property, and associate the Id property with the user.

If you are using IANA zones in .Net, you are (hopefully) using Noda Time, and you would associate the IANA zone name with your user (ex, America/Los_Angeles). You can either display these in a single list to your users, or filter it by country code, or use a map-based time zone picker. Please read this question for more details.

Also read about how to keep Noda Time updated.

Obviously we could just go with storing the windows or tzid zone name as key but this seems wrong

If using Windows zones, you store the Id (ex, Eastern Standard Time). If using IANA zones, you store the full name (ex, America/New_York). There's no way around that, and it is indeed the best practice.

See also this question and answer, which are basically the same question, but from a PHP perspective.

I don’t like storing platform specific information in the database. The information is coming out of an API which may be consumed by Java or windows clients, so presenting Java clients with a windows time-zone seems wrong.

Only the Windows zones are platform specific. If you are using IANA zones, you are fine in any platform. If your application is already deeply tied to Windows zones, then you could translate them using the CLDR mappings you found. These are also in Noda Time. You can read about translation here. If you want, you could store the Windows time zone ids, and convert on the fly in your external API. Or you could just convert one time and start using IANA zones going forward.

Is there a recognised ISO standard (or similar) list of time zone codes ...

No. There are no standards for time zones. The closest thing that exists is the IANA database. It is implemented just about everywhere. I suggest you read more in timezone tag wiki, and on Wikipedia.

Community
  • 1
  • 1
Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575