TimeZone.GetUtcOffset and DateTime.ToUniversalTime() not consistent for brief period for Atlantic Time Zone
as Won't Fix
11/6/2011 7:15:54 PM
User(s) can reproduce this bug
I believe I have found a timezone-related bug in the .Net framework. My assumption in the following NUnit test is that the UTC offset for a given date should be the same whether fetched from the TimeZone or by converting a local date to UTC, and fetching the difference.
I am in the Atlantic Time Zone.
public void AnotherTest(
[Values(2006, 2006, 2006, 2006, 2006, 2006, 2006)] Int32 year,
[Values(10, 10, 10, 10, 11, 11, 11)] Int32 month,
[Values(26, 27, 30, 31, 1, 2, 3)] Int32 day)
var dt = new DateTime(year, month, day, 0, 0, 0, DateTimeKind.Local);
var utcOffset1 = TimeZone.CurrentTimeZone.GetUtcOffset(dt);
var utcOffset2 = dt.Subtract(dt.ToUniversalTime());
These pass on Oct 26 and Nov 3, and fail for the dates between. I also ran tests for various earlier years, with same results. For dates from 2007 through 2011, these all pass. For all failures I've found, utcOffset1 was -3 hours while utcOffset2 was -4 hours. (According to <http://www.timeanddate.com/library/abbreviations/timezones/>, AST is supposed to be UTC-4 and ADT should be UTC-3.)
NOTE: When daylight savings was changed to 34 weeks in 2007, it also starts earlier. I haven't looked into it as much, but dates I've tried between March 10 and April 4 appears to indicate a problem at that end as well.