Skip to content
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

CalDateTime.Initialize overrides DateTimeKind property on incoming DateTimes when it should not #390

Closed
rianjs opened this issue May 21, 2018 · 1 comment

Comments

@rianjs
Copy link
Collaborator

rianjs commented May 21, 2018

  • Specifying a tzid of "UTC" should ensure that Value.Kind is DateTimeKind.Utc
  • Specifying a non-UTC tzid should ensure that Value.Kind is DateTimeKind.Local
  • Everything else should leave the Kind property alone

Right now, the bug is that Anything that doesn't have an explicit, real, time zone is marked as Unspecified which is wrong. We shouldn't touch it in that case.

[Test, TestCaseSource(nameof(DateTimeKindOverrideTestCases))]
public DateTimeKind DateTimeKindOverrideTests(DateTime dateTime, string tzId)
    => new CalDateTime(dateTime, tzId).Value.Kind;

public static IEnumerable<ITestCaseData> DateTimeKindOverrideTestCases()
{
    const string localTz = "America/New_York";
    var localDt = DateTime.SpecifyKind(DateTime.Parse("2018-05-21T11:35:33"), DateTimeKind.Local);

    yield return new TestCaseData(localDt, "UTC")
        .Returns(DateTimeKind.Utc)
        .SetName("Explicit tzid = UTC time zone returns DateTimeKind.Utc");

    yield return new TestCaseData(DateTime.SpecifyKind(localDt, DateTimeKind.Utc), null)
        .Returns(DateTimeKind.Utc)
        .SetName("DateTime with Kind = Utc and no tzid returns DateTimeKind.Utc");

    yield return new TestCaseData(localDt, localTz)
        .Returns(DateTimeKind.Local)
        .SetName("Local datetime with local tzid returns DateTimeKind.Local");

    yield return new TestCaseData(DateTime.SpecifyKind(localDt, DateTimeKind.Utc), localTz)
        .Returns(DateTimeKind.Local)
        .SetName("DateTime with Kind = Utc with explicit local tzid returns DateTimeKind.Local");

    yield return new TestCaseData(DateTime.SpecifyKind(localDt, DateTimeKind.Unspecified), localTz)
        .Returns(DateTimeKind.Local)
        .SetName("DateTime with Kind = Unspecified with explicit local tzid returns DateTimeKind.Local");

    yield return new TestCaseData(localDt, null)
        .Returns(DateTimeKind.Local)
        .SetName("DateTime with Kind = Local with null tzid returns DateTimeKind.Local");

    yield return new TestCaseData(DateTime.SpecifyKind(localDt, DateTimeKind.Unspecified), null)
        .Returns(DateTimeKind.Unspecified)
        .SetName("DateTime with Kind = Unspecified and null tzid returns DateTimeKind.Unspecified");
}
rianjs added a commit that referenced this issue May 21, 2018
Only override DateTimeKind when we know for sure what it should be #390
@rianjs
Copy link
Collaborator Author

rianjs commented May 21, 2018

@rianjs rianjs closed this as completed May 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant