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

Blazor: DateTime.ToString("o") and JsonSerializer.Serialize(DateTime) has a different result in wasm runtime #54343

Open
Tracked by #64598
anranruye opened this issue Jun 17, 2021 · 7 comments
Labels
arch-wasm WebAssembly architecture area-System.Buffers
Milestone

Comments

@anranruye
Copy link

Describe the bug

For local DateTime values which are smaller than 1900-12-31 23:59:17, System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime(+08:05 vs +08:00).

To Reproduce

<button @onclick="Click">Click</button>

@code{
    void Click()
    {
        DateTime dateTime1 = new DateTime(1900, 12, 31, 23, 59, 16, DateTimeKind.Local);
        DateTime dateTime2 = new DateTime(1900, 12, 31, 23, 59, 17, DateTimeKind.Local);
        //Output: "1900-12-31T23:59:16+08:05"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime1));
        Console.WriteLine(dateTime1.ToString("o"));
        //Output: "1900-12-31T23:59:17+08:00"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime2));
        Console.WriteLine(dateTime2.ToString("o"));
    }
}

Exceptions (if any)

Further technical details

  • ASP.NET Core version 5.0.0
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
@anranruye anranruye changed the title Blazor: System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime Blazor: JsonSerializer.Serialize(DateTime) has a different result in wasm runtime Jun 17, 2021
@anranruye anranruye changed the title Blazor: JsonSerializer.Serialize(DateTime) has a different result in wasm runtime Blazor: DateTime.ToString("o") and JsonSerializer.Serialize(DateTime) has a different result in wasm runtime Jun 17, 2021
@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore Jun 17, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Jun 17, 2021
@ghost
Copy link

ghost commented Jun 17, 2021

Tagging subscribers to this area: @eiriktsarpalis, @layomia
See info in area-owners.md if you want to be subscribed.

Issue Details

Describe the bug

For local DateTime values which are smaller than 1900-12-31 23:59:17, System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime(+08:05 vs +08:00).

To Reproduce

<button @onclick="Click">Click</button>

@code{
    void Click()
    {
        DateTime dateTime1 = new DateTime(1900, 12, 31, 23, 59, 16, DateTimeKind.Local);
        DateTime dateTime2 = new DateTime(1900, 12, 31, 23, 59, 17, DateTimeKind.Local);
        //Output: "1900-12-31T23:59:16+08:05"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime1));
        Console.WriteLine(dateTime1.ToString("o"));
        //Output: "1900-12-31T23:59:17+08:00"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime2));
        Console.WriteLine(dateTime2.ToString("o"));
    }
}

Exceptions (if any)

Further technical details

  • ASP.NET Core version 5.0.0
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: anranruye
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@Joe4evr
Copy link
Contributor

Joe4evr commented Jun 18, 2021

This is likely to do with the history of your local timezone. In the late 1800s it wasn't uncommon for certain regions to run both "Railroad time" (which was agreed-upon throughout the country) and "Local time" (which was different between towns/cities, and therefor could be off by a few minutes relative to Railroad time). The key thing to realize here is that at some point in time, the decision has been made to switch every city/town to "Railroad time" so that it'd all be in sync.

Evidently, the timezone data that is consulted for the conversion believes that 1900-12-31 23:59:17 is the moment when that switch happened for your zone.

@anranruye
Copy link
Author

@Joe4evr Thank you.

@anranruye
Copy link
Author

Now I understand why this happened. However, this makes difference between .Net implements. We still want the same behavior in all .Net implements.

@anranruye anranruye reopened this Jun 18, 2021
@lewing lewing added this to the 7.0.0 milestone Jun 28, 2021
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label Jun 28, 2021
@eiriktsarpalis eiriktsarpalis added the arch-wasm WebAssembly architecture label Oct 15, 2021
@ghost
Copy link

ghost commented Oct 15, 2021

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Describe the bug

For local DateTime values which are smaller than 1900-12-31 23:59:17, System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime(+08:05 vs +08:00).

To Reproduce

<button @onclick="Click">Click</button>

@code{
    void Click()
    {
        DateTime dateTime1 = new DateTime(1900, 12, 31, 23, 59, 16, DateTimeKind.Local);
        DateTime dateTime2 = new DateTime(1900, 12, 31, 23, 59, 17, DateTimeKind.Local);
        //Output: "1900-12-31T23:59:16+08:05"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime1));
        Console.WriteLine(dateTime1.ToString("o"));
        //Output: "1900-12-31T23:59:17+08:00"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime2));
        Console.WriteLine(dateTime2.ToString("o"));
    }
}

Exceptions (if any)

Further technical details

  • ASP.NET Core version 5.0.0
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: anranruye
Assignees: -
Labels:

arch-wasm, area-System.Text.Json

Milestone: 7.0.0

@eiriktsarpalis
Copy link
Member

System.Text.Json uses the Utf8Formatter class when serializing date values. I would assume there are semantic differences between that implementation and DateTime.ToString("o") in the case of wasm.

@ghost
Copy link

ghost commented Oct 15, 2021

Tagging subscribers to this area: @GrabYourPitchforks, @dotnet/area-system-buffers
See info in area-owners.md if you want to be subscribed.

Issue Details

Describe the bug

For local DateTime values which are smaller than 1900-12-31 23:59:17, System.Text.Json.JsonSerializer.Serialize(DateTime) has a different result in wasm runtime(+08:05 vs +08:00).

To Reproduce

<button @onclick="Click">Click</button>

@code{
    void Click()
    {
        DateTime dateTime1 = new DateTime(1900, 12, 31, 23, 59, 16, DateTimeKind.Local);
        DateTime dateTime2 = new DateTime(1900, 12, 31, 23, 59, 17, DateTimeKind.Local);
        //Output: "1900-12-31T23:59:16+08:05"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime1));
        Console.WriteLine(dateTime1.ToString("o"));
        //Output: "1900-12-31T23:59:17+08:00"
        Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(dateTime2));
        Console.WriteLine(dateTime2.ToString("o"));
    }
}

Exceptions (if any)

Further technical details

  • ASP.NET Core version 5.0.0
  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Author: anranruye
Assignees: -
Labels:

arch-wasm, area-System.Buffers, area-System.Text.Json

Milestone: 7.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm WebAssembly architecture area-System.Buffers
Projects
None yet
Development

No branches or pull requests

5 participants