Geeks With Blogs
Nat Luengnaruemitchai Geek Blog

As Bush's goverument proposed the extension of daylight saving time period, the daylight saving time will start in March and end in November in 2007 instead of April and October previously. This will cause a problem for unpatched system not to display time correctly. Therefore, several vendors have provided a patch for their own system including Microsoft. Microsoft released a KB928388 patch. What this patch does is to modify some registry keys that keep information about time offset and daylight saving information. This information is quite static. It stores time offset, the start of DST (Xth day of week of Yth month as well as the time difference between daylight saving time and regular time). For example, this information has been patched to Second Sunday in March at 02:00:00 and First Sunday in November at 02:00:00 respectively.

It looks OK right. System has been patched. Life is good. Not so fast, my friends. The operating system before Vista era doesn't really support Dynamic DST (Ability to keep different daylight saving information for different periods.) This means the time will be changed retroactively. For example,

Before the patch

TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2006, 11, 1)) should return -05:00:00
TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2007, 11, 1)) should return -05:00:00

After the patch

TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2006, 11, 1)) should return -04:00:00
TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2007, 11, 1)) should return -04:00:00

Expected behavior

TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2006, 11, 1)) should return -05:00:00
TimeZone.CurrentTimeZone.GetUtcOffset(new DateTime(2007, 11, 1)) should return -04:00:00

First when I heard about this problem, I couldn't believe my own ears that Microsoft would provide a patch where it will cause a problem somewhere else but it is. The implication of this means if you store the data in UTC timezone to represent datetime, you stored 2006-11-1 12:00:00AM as 2006-11-1 05:00:00 AM previously and when you retrieve it back based on new patch, you will get 2006-11-1 01:00:00AM back instead. So if you search such date in the database probably you won't get anything back. The same problem applied with a case I found recently. We have a system that needs interopability between Java and .NET. We use the native implementation of Date where the DateTime in .NET will be converted into .NET ticks at UTC time sending over to Java side and then Java will convert .NET tick back to milliseconds since epoch and construct java.util.Date object in Java. Everything had been good until recently our beloved administrators installed timezone patch in every machine. One user started complain that she entered 2007-11-1 in the application but it turns out to get data on 2007-10-31 for her instead. What happened was 2007-11-1 in .NET Datetime will be converted into 2007-10-31 11:00PM and it got serialized into XML as 2007-10-31. When the data got transferred to the other side, it will return wrong data back to us. To make the story funnier, although Microsoft provided an API to get dynamic DST in Vista, .NET code seems to use the old function. Therefore it will return wrong timezone information as well. What a compatibility!

If you have a problem like me, I hope that the information provided here would help you not to spend too much time diagnose what's going on here.

Thanks Citrin Wayne for providing such responsive help, extensive information, and the great product.

Reference:
DYNAMIC_TIME_ZONE_INFORMATION
2007 time zone update for Microsoft Windows operating systems
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1180416&SiteID=1
More about JNBridgePro and the new daylight savings time rules

Posted on Sunday, February 11, 2007 6:40 PM Programming | Back to top


Comments on this post: new DateTime bug^H^H^Hby-design feature with Microsoft's latest patch for Daylight Saving

# re: new DateTime bug with Microsoft's latest patch for Daylight Saving
Requesting Gravatar...
Thanks for posting about this Nat.

D
Left by D'Arcy from Winnipeg on Feb 11, 2007 7:59 PM

Your comment:
 (will show your gravatar)


Copyright © Nat Luengnaruemitchai | Powered by: GeeksWithBlogs.net