Skip to content

BclDateTimeZone doesn't handle base-offset changes #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GoogleCodeExporter opened this issue Mar 15, 2015 · 7 comments
Closed

BclDateTimeZone doesn't handle base-offset changes #342

GoogleCodeExporter opened this issue Mar 15, 2015 · 7 comments
Labels
Milestone

Comments

@GoogleCodeExporter
Copy link

Consider the following tests:

    [Test]
    public void CanHandleBaseOffsetChange_Tzdb()
    {
        var tz = DateTimeZoneProviders.Tzdb["Europe/Moscow"];
        var dt = Instant.FromUtc(2013, 6, 1, 0, 0, 0).InZone(tz).LocalDateTime;
        var expected = new LocalDateTime(2013, 6, 1, 4, 0, 0);
        Assert.AreEqual(expected, dt);
    }

    [Test]
    public void CanHandleBaseOffsetChange_Bcl()
    {
        var tz = DateTimeZoneProviders.Bcl["Russian Standard Time"];
        var dt = Instant.FromUtc(2013, 6, 1, 0, 0, 0).InZone(tz).LocalDateTime;
        var expected = new LocalDateTime(2013, 6, 1, 4, 0, 0);
        Assert.AreEqual(expected, dt);
    }

    [Test]
    public void CanHandleBaseOffsetChange_Tzi()
    {
        var tz = TimeZoneInfo.FindSystemTimeZoneById("Russian Standard Time");
        var dt = TimeZoneInfo.ConvertTimeFromUtc(new DateTime(2013, 6, 1), tz);
        var expected = new DateTime(2013, 6, 1, 4, 0, 0);
        Assert.AreEqual(expected, dt);
    }

Only the TZDB test pases.  The TZI test fails due to the fact that 
TimeZoneInfo.AdjustmentRule doesn't track year-to-year changes to the base 
offset.  This is reported in https://support.microsoft.com/kb/3012229 and fixed 
in .Net 4.6 preview (coreclr).

NodaTime's BclDateTimeZone implementation has the same issue, because it loads 
its data from TimeZoneInfo.  In order to work around the issue, we would need 
to load BCL data either using Win32 APIs, or by reading directly from the 
registry.

The base offset changes ARE in the registry, so there's no reason that we would 
need to rely on the TZI fix.  Even if we did, we'd have to use reflection to 
get at the new internal field that was added to TimeZoneInfo.AdjustmentRule.

Original issue reported on code.google.com by mj1856 on 8 Feb 2015 at 6:46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants