Bug 41667 - new DateTime().ToLocalTime() results in an exception
Summary: new DateTime().ToLocalTime() results in an exception
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2016-06-09 18:34 UTC by Mike Voorhees
Modified: 2016-06-21 13:23 UTC (History)
2 users (show)

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


Attachments
Output from running the program with .NET & mono (4.21 KB, text/plain)
2016-06-09 18:34 UTC, Mike Voorhees
Details


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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Mike Voorhees 2016-06-09 18:34:52 UTC
Created attachment 16254 [details]
Output from running the program with .NET & mono

The following code works on .NET and in an older 2.10 mono, but results in an exception using recent builds of mono.

static void Main(string[] args)
{
    // Fails
    Console.WriteLine(DateTime.MinValue.ToLocalTime());

    //Fails
    Console.WriteLine(new DateTime().ToLocalTime());
}

Unhandled Exception:
System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
  at System.DateTime.DateToTicks (System.Int32 year, System.Int32 month, System.Int32 day) <0x2acbe38 + 0x00197> in <filename unknown>:0
  at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day) <0x2acc180 + 0x0001f> in <filename unknown>:0
  at System.TimeZoneInfo.TransitionPoint (System.TimeZoneInfo+TransitionTime transition, System.Int32 year) <0x2acf270 + 0x00103> in <filename unknown>:0
  at System.TimeZoneInfo.IsInDSTForYear (System.TimeZoneInfo+AdjustmentRule rule, System.DateTime dateTime, System.Int32 year) <0x2ad0658 + 0x00103> in <filename unknown>:0
  at System.TimeZoneInfo.IsInDST (System.TimeZoneInfo+AdjustmentRule rule, System.DateTime dateTime) <0x2ad05b0 + 0x00093> in <filename unknown>:0
  at System.TimeZoneInfo.GetUtcOffsetHelper (System.DateTime dateTime, System.TimeZoneInfo tz, System.Boolean& isDST) <0x2acfb48 + 0x0043b> in <filename unknown>:0
  at System.TimeZoneInfo.GetUtcOffset (System.DateTime dateTime, System.Boolean& isDST) <0x2acf9a8 + 0x0009f> in <filename unknown>:0
  at System.TimeZoneInfo.GetUtcOffsetFromUtc (System.DateTime time, System.TimeZoneInfo zone, System.Boolean& isDaylightSavings, System.Boolean& isAmbiguousLocalDst) <0x2ace8e0 + 0x0007f> in <filename unknown>:0
  at System.DateTime.ToLocalTime (System.Boolean throwOnOverflow) <0x2ac1788 + 0x000b3> in <filename unknown>:0
  at System.DateTime.ToLocalTime () <0x2ac1740 + 0x0001f> in <filename unknown>:0
  at DateTimeProblem.Program.Main (System.String[] args) <0x2ac15c0 + 0x00037> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime.
  at System.DateTime.DateToTicks (System.Int32 year, System.Int32 month, System.Int32 day) <0x2acbe38 + 0x00197> in <filename unknown>:0
  at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day) <0x2acc180 + 0x0001f> in <filename unknown>:0
  at System.TimeZoneInfo.TransitionPoint (System.TimeZoneInfo+TransitionTime transition, System.Int32 year) <0x2acf270 + 0x00103> in <filename unknown>:0
  at System.TimeZoneInfo.IsInDSTForYear (System.TimeZoneInfo+AdjustmentRule rule, System.DateTime dateTime, System.Int32 year) <0x2ad0658 + 0x00103> in <filename unknown>:0
  at System.TimeZoneInfo.IsInDST (System.TimeZoneInfo+AdjustmentRule rule, System.DateTime dateTime) <0x2ad05b0 + 0x00093> in <filename unknown>:0
  at System.TimeZoneInfo.GetUtcOffsetHelper (System.DateTime dateTime, System.TimeZoneInfo tz, System.Boolean& isDST) <0x2acfb48 + 0x0043b> in <filename unknown>:0
  at System.TimeZoneInfo.GetUtcOffset (System.DateTime dateTime, System.Boolean& isDST) <0x2acf9a8 + 0x0009f> in <filename unknown>:0
  at System.TimeZoneInfo.GetUtcOffsetFromUtc (System.DateTime time, System.TimeZoneInfo zone, System.Boolean& isDaylightSavings, System.Boolean& isAmbiguousLocalDst) <0x2ace8e0 + 0x0007f> in <filename unknown>:0
  at System.DateTime.ToLocalTime (System.Boolean throwOnOverflow) <0x2ac1788 + 0x000b3> in <filename unknown>:0
  at System.DateTime.ToLocalTime () <0x2ac1740 + 0x0001f> in <filename unknown>:0
  at DateTimeProblem.Program.Main (System.String[] args) <0x2ac15c0 + 0x00037> in <filename unknown>:0



Looks like the DateTime implementation is coming from the reference source these days.  Not sure how you guys handle bugs like this, if they should be filed here or against .NET core.  I thought I'd file it here for now since ultimately it's mono's master branch that we'd like to see the fix end up in.

Thanks,
-Mike
Comment 1 Marek Safar 2016-06-10 09:25:32 UTC
Similar issue was fixed recently please ensure you are running recent mono (at least 4.4). Please reopen the issue if you can still reproduce it with details about your TimeZoneInfo.Local and operating system
Comment 2 Mike Voorhees 2016-06-10 17:16:12 UTC
I'm fairly certain this is still happening.  I can reproduce it with a build of mono from the master branch @ 14f8acced5bbb2f6d55fb3e7800382700bcc65eb, which is only a day old.

My mono build reports as version 4.5.2

The additional info you requested :

(UTC-05:00) Eastern Time (US & Canada)

OS : Windows 10 Pro
Comment 3 Marek Safar 2016-06-21 13:23:51 UTC
Fixed in master and Mono 4.5.1