1

Closed

Daylight Saving transition time

description

I was doing some testing comparing ZoneInfo results to system timezone (using Pacific/Auckland) and found this discrepancy which is probably a bug.
I have this test case:
 
            Assert.AreEqual(TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Parse("2009-09-26 14:00:00")),
                            zone.ConvertToLocal(DateTime.Parse("2009-09-26 14:00:00")));
 
It fails:
Expected: 2009-09-27 03:00:00.000
But was: 2009-09-27 02:00:00.000
 
This has to do with daylight saving time transition. Here's some background
NZ offsite is +12 hours
And the DST rule is: From 30 April 2007, DST (+1h) begins at 02:00 NZST on the last Sunday in September each year, and ends at 03:00 NZDT (or 02:00 NZST) on the first Sunday in April (http://home.tiscali.nl/~t876506/TZworld.html#pac).
So this means at 2am on 2009-09-27 time gets moved to 3am.
Closed Oct 19, 2013 at 11:39 PM by abfo

comments

muxa wrote Apr 19, 2011 at 11:48 AM

It also failed it some other tests:
    [Test]
    public void TestPublicDomainZoneInfo_NZ()
    {
        Database.LoadFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Substring(6), "tzdata"));
        Zone zone = Database.GetZone("Pacific/Auckland");

        Assert.AreEqual(new DateTime(2009, 09, 27, 03, 00, 0),
                        zone.ConvertToLocal(new DateTime(2009, 09, 26, 14, 00, 00, DateTimeKind.Utc)));
        Assert.AreEqual(new DateTime(2010, 04, 04, 02, 00, 0),
                        zone.ConvertToLocal(new DateTime(2010, 04, 03, 14, 00, 00, DateTimeKind.Utc)));

        //When DST is on at 2am on 2009-09-27 time gets moved to 3am - i.e. time between 2am and 3am is invalid           
        Assert.AreEqual(new DateTime(2009, 09, 26, 14, 00, 0),
                        zone.ConvertToUtc(new DateTime(2009, 09, 27, 03, 00, 00)));
        Assert.AreEqual(new DateTime(2009, 09, 26, 14, 00, 0),
                        zone.ConvertToUtc(new DateTime(2009, 09, 27, 02, 00, 00)));

        Assert.AreEqual(new DateTime(2009, 09, 26, 14, 00, 0),
                        zone.ConvertToLocal(new DateTime(2009, 09, 26, 02, 00, 00, DateTimeKind.Utc)));
    }

muxa wrote Apr 19, 2011 at 11:58 AM

I've submitted a patch for this: ID 9207 at http://zoneinfo.codeplex.com/SourceControl/list/patches

wrote Feb 14, 2013 at 6:21 PM

pawaw wrote Sep 19, 2013 at 4:01 PM

This is actually a very important bug in my opinion, I just saw problems with this issue myself in production and your patch solves it. Nice job. I hope this patch will get approved asap (but i wonder if the admin of this project is still here??).

wrote Oct 19, 2013 at 11:39 PM

wrote Oct 19, 2013 at 11:39 PM