Giter Site home page Giter Site logo

Comments (3)

max-maurice avatar max-maurice commented on June 16, 2024 1

Thanks Bart, you're right! It's not JsonApiDotNetCore, but my implementation of a ValueConverter. I had

public class LocalDateTimeConverter : ValueConverter<DateTime, DateTime>
{
  public LocalDateTimeConverter()
      : base(v => v /* <- WRONG! */, v => DateTime.SpecifyKind(v, DateTimeKind.Local))
  {
  }
}

where the first ctor parameter was missing the conversion .ToLocalTime() and should read v => v.ToLocalTime().

Sorry for the troubles!

from jsonapidotnetcore.

bkoelman avatar bkoelman commented on June 16, 2024

From what I can tell, JsonApiDotNetCore parses the "Z" designator correctly:

image

It's then up to the database driver to convert that to SQL. And that's where it gets tricky.

For example, Npgsql took a breaking change in 2020 and decided to fail on any DateTime or DateTimeOffset that isn't UTC because of all the non-intuitive behavior during conversions. We have several integration tests (1, 2, 3, 4) to verify that a local or UTC DateTime roundtrips properly, with PostgreSQL at least.

For SQL Server, there's a workaround described here, that deals with the fact that the underlying column type is unable to store whether the value is local or UTC. The consensus from the EF Core team is described at dotnet/efcore#4711 (comment), which comes down to: when using SQL Server, use DateTimeOffset instead of DateTime.

Would using DateTimeOffset (with the appropriate DATETIMEOFFSET underlying column type) work for you?

from jsonapidotnetcore.

bkoelman avatar bkoelman commented on June 16, 2024

In case you're interested, there's a fun video at https://www.youtube.com/watch?v=ZLJLfImuFqM&list=PLdo4fOcmZ0oX-DBuRG4u58ZTAJgBAeQ-t discussing dates, offsets, and time zones. It has some interesting details, for example: did you know that DateTimeKind actually has four values internally?

from jsonapidotnetcore.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.