Sign in to follow this  
capn_midnight

[.net] DateTime and time zone issues

Recommended Posts

How can code running in a time zone that does not observe Daylight Savings Time tell when another time zone that *does* observe DST is actually in observance of DST? Using DateTime.Now.IsDaylightSavingsTime() won't work for such places. For example, say I have a web server in Indiana (Indiana is one of the few places in the USA that does not observe DST) that is serving an ASP.NET site. It wishes to determine if the Eastern Time Zone is currently observing DST (such as it is right now). The ASP.NET web app in Indiana needs to make decisions based on business rules defined by people in Pennsylvania, and one of these rules says that a decision is made in relation to 5PM in PA. So, if it is currently Daylight Savings Time, then 5PM in PA is UTC1900, but if it is not, then 5PM in PA is UTC2000. But for Indiana, 5PM is always UTC2000. GAH!

Share this post


Link to post
Share on other sites
I think this could be what you need. I'm reading the code now to extract the part that should help you.

Ok, this code just extracts all the info from window's registry:

SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones

And parses the tzi (timezoneinformation).

If you're interested in this approach, you'd probably need most of timezoneinformation.cs from the code in that article.

--------

Maybe you only need this:

"You can see what the DST settings are for your current timezone by
calling TimeZone.CurrentTimeZone.GetDaylightChanges(callDate.Year).
This returns a DaylightTime instance, and its Delta, Start and End
properties will tell you if .Net is detecting your DST settings
correctly."

[Edited by - Zanshibumi on June 1, 2007 3:57:28 PM]

Share this post


Link to post
Share on other sites
<sigh>

Let me spell it out again:
-The code runs in Time Zone A
-The time-sensitive Business Rules are based on Time Zone B
-Time Zone A does not observer DST
-Time Zone B observes DST
-The code in Time Zone A needs to know the time in Time Zone B
-The code needs to be self contained, so I can't run a Web Service from Time Zone B to report the current time
-The code has to be stateless, so I cannot garauntee that I will not exceed the maximum "1 query per 4 seconds" requirement for querying Time from the National Institute for Science and Technology (NIST) servers,
-The code runs on an internal intranet and connectivity to the Internet cannot be garaunteed, another reason why I can't rely on NIST (or a custom Web Service, for that matter).

Share this post


Link to post
Share on other sites
Oh! I wrote 'a href:' instead of 'a href=' so the link didn't work.

The "this" part of my post directed (directs now) to a solution that I think covers what you need (I did understand you the first time, I just posted the easy way in case I was wrong).

I suppose it didn't make much sense without that, sorry.


I'll check it now that I'm at home, to see if it works for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this