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

DateTimeOffset loosing Timezone info #525

Closed
oliverjanik opened this issue Apr 2, 2015 · 4 comments
Closed

DateTimeOffset loosing Timezone info #525

oliverjanik opened this issue Apr 2, 2015 · 4 comments

Comments

@oliverjanik
Copy link

Here's the test that fails:

[Fact]
public void JTokenDateTest()
{
    var json = JToken.Parse(@"{ ""lastModifiedAt"": ""2015-04-30T23:59:02.465+12:00"" }");

    Assert.Equal("2015-04-30T23:59:02.465+12:00", json.Value<string>("lastModifiedAt"));

    var dto = (DateTimeOffset)json["lastModifiedAt"];

    Assert.Equal(12, dto.Offset.Hours);
} 

This fails both asserts. The question is WTF? Why does the parser even try to interpret the time information when it's actually a JSON string? I thought I was going crazy. The only interpretation should happen when I cast it to the DateTimeOffset.

@JamesNK
Copy link
Owner

JamesNK commented Apr 12, 2015

JToken.Parse reads dates as DateTime by default. Look at the DateParseHandling setting.

@JamesNK JamesNK closed this as completed Apr 12, 2015
@oliverjanik
Copy link
Author

What about the wrong timezone info? Do you not consider this an issue? Why does it modify the offset in a round-trip conversion?

@JamesNK
Copy link
Owner

JamesNK commented Apr 12, 2015

DateTime doesn't preserve the timezone.

@DaveVdE
Copy link

DaveVdE commented Sep 16, 2015

IMHO, I think it's a crazy default. Especially considering DateTime is such a bad fit for ISO8601.

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

3 participants