Bug 4832 - TimeZoneInfo.IsAmbiguousTime() returns incorrect results.
Summary: TimeZoneInfo.IsAmbiguousTime() returns incorrect results.
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-05-02 16:59 UTC by James Clegg
Modified: 2012-05-02 16:59 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description James Clegg 2012-05-02 16:59:05 UTC
TimeZoneInfo.IsAmbiguousTime() has a subtle bug where the "fall back" hour for daylight saving time returns incorrect results for the start and end of the fall back hour, which causes non-contiguous results when advancing thru the fall back hour.

For example 11/4/2012 1:00:00 AM in "US/Eastern" occurs twice and is ambiguous.  2 AM occurs once and is not ambiguous.  All times *in between* 1am and 2am occur twice and are ambiguous.  IsAmbiguousTime is returning false for 1am (incorrectly), true for 2am (incorrectly).  Times in between 1 and 2 AM correctly return true.

I have replicated this bug in multiple timezones that support Daylight Saving Time on Debian and Mac OSX.

The following code demonstrates the issue by picking a time before the transition, and advancing a UTC time by 30 minutes
per iteration.  The UTC time is converted to US/Eastern time and IsAmbiguousTime is called.   The first line assumes
you are running the local system set to a US/Eastern timezone (but this is not necessary to reproduce the bug). 

static void Main(string[] args)
{
    DateTime utcTime = new DateTime(2012, 11, 4, 0, 0, 0, DateTimeKind.Local).ToUniversalTime(); // "fall back" day
    var tzi = TimeZoneInfo.FindSystemTimeZoneById("US/Eastern");
	
    for (int i = 0; i < 8; i++)  // advance across fallback hour.
    {
        var localTime = TimeZoneInfo.ConvertTimeFromUtc(utcTime, tzi);

        Console.WriteLine(string.Format(" UTC {0} to local {1} IsAmbiguousTime() returns {2}, ", 
		                                utcTime, localTime,  tzi.IsAmbiguousTime(localTime)));
	utcTime =utcTime.AddMinutes(30);
    }
}

For a computer set to timezone "US/Eastern" it SHOULD return:

 UTC 11/4/2012 4:00:00 AM to local 11/4/2012 12:00:00 AM IsAmbiguousTime() returns False, 
 UTC 11/4/2012 4:30:00 AM to local 11/4/2012 12:30:00 AM IsAmbiguousTime() returns False, 
 UTC 11/4/2012 5:00:00 AM to local 11/4/2012 1:00:00 AM IsAmbiguousTime() returns True, 
 UTC 11/4/2012 5:30:00 AM to local 11/4/2012 1:30:00 AM IsAmbiguousTime() returns True, 
 UTC 11/4/2012 6:00:00 AM to local 11/4/2012 1:00:00 AM IsAmbiguousTime() returns True, 
 UTC 11/4/2012 6:30:00 AM to local 11/4/2012 1:30:00 AM IsAmbiguousTime() returns True, 
 UTC 11/4/2012 7:00:00 AM to local 11/4/2012 2:00:00 AM IsAmbiguousTime() returns False, 
 UTC 11/4/2012 7:30:00 AM to local 11/4/2012 2:30:00 AM IsAmbiguousTime() returns False, 

(note that the "true" results are contiguous)

But the actual result is:

 UTC 11/4/2012 4:00:00 AM to local 11/4/2012 12:00:00 AM IsAmbiguousTime() returns False, 
 UTC 11/4/2012 4:30:00 AM to local 11/4/2012 12:30:00 AM IsAmbiguousTime() returns False, 
 UTC 11/4/2012 5:00:00 AM to local 11/4/2012 1:00:00 AM IsAmbiguousTime() returns False,   < incorrect 1am occurs twice
 UTC 11/4/2012 5:30:00 AM to local 11/4/2012 1:30:00 AM IsAmbiguousTime() returns True,    < correct
 UTC 11/4/2012 6:00:00 AM to local 11/4/2012 1:00:00 AM IsAmbiguousTime() returns False,   < incorrect 1am occurs twice
 UTC 11/4/2012 6:30:00 AM to local 11/4/2012 1:30:00 AM IsAmbiguousTime() returns True,    < correct
 UTC 11/4/2012 7:00:00 AM to local 11/4/2012 2:00:00 AM IsAmbiguousTime() returns True,    < incorrect 2am occurs only once
 UTC 11/4/2012 7:30:00 AM to local 11/4/2012 2:30:00 AM IsAmbiguousTime() returns False,

Note You need to log in before you can comment on or make changes to this bug.