Skip to content

DateTime in filter expression gets parsed as local DateTime when using "Z" designator #1528

Closed
@max-maurice

Description

@max-maurice

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:

public partial class Item : IIdentifiable<Guid>
{
  // ...

  [Column(TypeName = "datetime")]
  [Attr(PublicName = "changedAt")]
  public DateTime? ChangedAt { get; set; }
}

Create test data:

item.ChangedAt = new DateTime(2024, 4, 8, 10, 0, 5, DateTimeKind.Local); // Local is CEST, which is +2h on April, 8th
  1. Send a request to /items?filter=equals(changedAt,'2024-04-08T08:00:05Z')
  2. JADNC returns no results (wrong)
  3. Send a request to /items?filter=equals(changedAt,'2024-04-08T08:00:05+00:00')
  4. JADNC returns 1 result (correct)
  5. Send a request to /items?filter=equals(changedAt,'2024-04-08T10:00:05+02:00')
  6. JADNC returns 1 result (correct)

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

  • JsonApiDotNetCore version: 5.5.1
  • ASP.NET Core version: 7.0.15
  • Entity Framework Core version: 7.0.15
  • Database provider: SqlServer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions