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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 4832 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

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,