views:

386

answers:

6

I'm on .NET 2.0, running under Medium Trust (so TimeZoneInfo and the Registry are not allowed options). I'm asking the user for two dates and a time zone, and would really love to be able to automatically determine whether I need to adjust the time zone for DST.

This probably isn't even a valid scenario unless I have some very robust support, a la TimeZoneInfo, to differentiate between all of the different varieties of Time Zones in the first place.

A: 

Well, since TimeZoneInfo is excluded, you're probably not going to find a solution in the framework itself (but don't quote me on that).

In which case, have you considered reflectoring the TimeZoneInfo class and using what you find there?

Domenic
A: 

@Domenic, I've considered, but I'd prefer to stay legal, and I'm fairly sure the information would have to be embedded into the framework anyway, or grabbed from the registry in some sneaky way that doesn't require permissions...

bdukes
+2  A: 

In .NET 2.0 you have to code this yourself. It involves researching daylight savings time laws in various regions and building that into your own data structures. The problem is somewhat simplified if you only care about a subset of time zones, for example just in the USA, but if you need all global time zones, you have a lot of work to do, and then the code has to be updated every few years when the laws change. Even the new time zone objects in the latest version of .NET will require windows updates to keep them correct as laws change.

Look here, here, and here for more info.

Eric Z Beard
Not to mention that if you want to accurately determine DST status for historical dates, besides having to keep up to date, you have to archive all DST rules that have ever applied in those time zones. No operating system or library I'm aware of currently does this.
Mihai Limbășan
A: 

@Eric Z Beard, unfortunately we need to be global. We're going to look into how terrible it would be to require our customers be on .NET 3.5. Otherwise we'll just have to make them manually tell us their DST information. Thanks for the links.

bdukes
+1  A: 

The TZ Database is a public domain database of timezone rules that is very well maintained. There is also a compiled format for the data they provide, and there are lots of libraries available to read the compiled data, like this one: ZoneInfo (tz database / Olson database) .NET API

Daryl
+2  A: 

Excellent timezone library here: TZ4Net

Chris Shaffer