-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
DateTime in filter expression gets parsed as local DateTime when using "Z" designator #1528
Comments
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 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 Would using |
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 |
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 Sorry for the troubles! |
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: