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

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


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

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.

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