Comments (3)
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.
From what I can tell, JsonApiDotNetCore parses the "Z" designator correctly:
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.
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)
- Request with query string '=' returns 500 HOT 3
- cleanupcode.ps1 <revision> fails on Linux HOT 1
- Empty string ID is accepted in post resource request HOT 1
- Clarify usage of explicit controllers
- Add tests for submitting meta
- Look into usage of [BindRequired] HOT 1
- Source generation when models are in a separate project HOT 1
- PrimaryResourceType is null and giving error "Expected IJsonApiRequest.PrimaryResourceType not to be null at this point." HOT 6
- Include relations inside custom controller HOT 7
- Attempting to setup sample app with filtering and getting error on filtered call. HOT 3
- Differently encoded URLs in self and first links HOT 1
- Use IResourceService outside of the path of a request HOT 10
- Multiple db context and keeping single resource HOT 10
- Multiple DbContexts seems to conflict each other at runtime HOT 2
- Customize paging for each controller ? HOT 10
- Support JSONB columns HOT 4
- Attribute unavailable & available if request HOT 7
- TopLevelLinks All / Paging does not work as expected HOT 3
- Use form fields in issue template HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonapidotnetcore.