Bug 54468 - Recreated TimeZoneInfo can't work out UTC offset
Summary: Recreated TimeZoneInfo can't work out UTC offset
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: master
Hardware: PC Windows
: --- normal
Target Milestone: Future Release
Assignee: Bugzilla
Depends on:
Reported: 2017-04-04 20:17 UTC by Jon Skeet
Modified: 2017-10-19 09:37 UTC (History)
3 users (show)

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

Test program demonstrating issue. (614 bytes, text/plain)
2017-04-04 20:17 UTC, Jon Skeet

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 54468 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:

Description Jon Skeet 2017-04-04 20:17:32 UTC
Created attachment 21192 [details]
Test program demonstrating issue.

Discovered in Noda Time when trying to fix https://github.com/nodatime/nodatime/issues/743
My guess is that the underlying cause is equivalent :)

Background: Europe/Malta on Linux is represented via several single-year time zone rules, including 1948, when it entered daylight saving time on Feb 29th.

Ask Europe/Malta for the UTC offset at 1948-01-01T00:00:00Z and it's fine.
Recreate the "same" time zone via TimeZoneInfo.CreateCustomTimeZone, and it fails with an exception:

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) [0x00091] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.DateTime..ctor (System.Int32 year, System.Int32 month, System.Int32 day) [0x00000] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.TimeZoneInfo.TransitionPoint (System.TimeZoneInfo+TransitionTime transition, System.Int32 year) [0x0001b] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.TimeZoneInfo.IsInDSTForYear (System.TimeZoneInfo+AdjustmentRule rule, System.DateTime dateTime, System.Int32 year) [0x00006] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.TimeZoneInfo.IsInDST (System.TimeZoneInfo+AdjustmentRule rule, System.DateTime dateTime) [0x0002d] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.TimeZoneInfo.GetUtcOffsetHelper (System.DateTime dateTime, System.TimeZoneInfo tz, System.Boolean& isDST) [0x0005e] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.TimeZoneInfo.GetUtcOffset (System.DateTime dateTime, System.Boolean& isDST) [0x0005e] in <f712f98eb8e445c8918edaf595bbe465>:0
  at System.TimeZoneInfo.GetUtcOffset (System.DateTime dateTime) [0x00000] in <f712f98eb8e445c8918edaf595bbe465>:0
  at Test.Main () [0x00058] in <a931a161b7a644ec871f4bf6d9e99b8f>:0

I strongly suspect that Mono is trying to do what Noda Time was doing: see when the adjustment rule *would* have occurred in 1947 or 1949, at which point it will fail because February 29th didn't exist.