views:

190

answers:

3

I'm working on an asp.net mvc application. Each user have his own time zone.

Right now, I'm using "TimeZoneInfo.GetSystemTimeZones" to generate a drop down list in order for the user to select a timezone and this is what I store in my db
They are like that:
Morocco Standard Time (00:00:00)
UTC (00:00:00)
GMT Standard Time (00:00:00)
...

I know that php use a different timezone set, they are "region timezone", for example:
Europe/Paris
Europe/London
...

My question is: is there a way to play with the region timezone (like php) in an .NET application? The only way I can think of is to bind each php region timezone to the .net timezone.

Also, the "TimeZoneInfo.GetSystemTimeZones" list all of the timezone on the machine. Is the list different between windows server, windows vista, windows xp?

Hope this make sense, thanks guys

+1  A: 

I would use that method to initially populate your Time Zone table with data, not pull from the collection each time. If something does change, you could accidently change the Ids that each person uses at some point later down the road. You also then don't have to worry about any potential differences between OS'.

Tejs
+1  A: 

It sounds like you're after the zoneinfo or Olson database names. Basically those are the names the non-Windows world uses :)

They're also what Noda Time uses typically, although we'll support the Windows names as well eventually. Unfortunately Noda Time isn't production-ready yet - when it is, it should be the right answer to your question :)

In the meantime, if you're definitely only going to be using Windows, I think it would be reasonable to store the Windows time zone IDs - make sure you use the Id property instead of StandardName though. There are translations between the Windows IDs and the Olson IDs around the web - but I don't know how comprehensive (or up-to-date) they are.

Jon Skeet
+2  A: 

The zone name schema used by php is often called Olson database.
You can find a conversion table for windows zone (id) -> Olson DB at http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html

You might also be interested in noda-time (though there's not release yet). Jon Skeet talked a bit about it on the 200th hanselminutes episode and it's going to use Olson DB as well.


In case the list/document at http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml is complete and up-to-date you can create a simple conversion function for php via

$supplementalData = simplexml_load_file('http://unicode.org/repos/cldr/trunk/common/supplemental/windowsZones.xml');

$zones = array();
foreach( $supplementalData->windowsZones->mapTimezones->mapZone as $zi ) {
  $zones[ (string)$zi['other'] ] = (string)$zi['type'];
}

file_put_contents('zoneconvert.php', '<?php function windowszone2olson($winzone) {
  static $zi = '.var_export($zones, true).';
  return isset($zi[$winzone]) ? $zi[$winzone] : false;
}');

This will create/overwrite a file zoneconvert.php that exposes the function windowszone2olson($winzone). You can do more or less the same on the .net end, too (which is probably the better place).

VolkerK