You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
DESCRIPTION
A filter expression containing a DateTime with "Z" instead of "+00:00" gets parsed as local time instead of UTC.
STEPS TO REPRODUCE
Using a model with a
datetime
property like this:Create test data:
/items?filter=equals(changedAt,'2024-04-08T08:00:05Z')
/items?filter=equals(changedAt,'2024-04-08T08:00:05+00:00')
/items?filter=equals(changedAt,'2024-04-08T10:00:05+02:00')
Using DateTimeOffset instead of DateTime or specifying DateTimeKind.Utc instead of Local changes the behavior, but the results are still inconsistent.
EXPECTED BEHAVIOR
The "Z" zone designator should be treated like a "+00:00" offset.
ACTUAL BEHAVIOR
The "Z" designator seems to be ignored and the datetime treated as local time.
VERSIONS USED
The text was updated successfully, but these errors were encountered: