OData / OData/WebApi

DateTimeOffset gets converted to DateTime with DateTimeKind.Unspecified.

Open
#804 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3
Dominant language
C#
Stars
864
Forks
467
PR merge metrics
No merged PRs in 30d

Description

DateTimeOffset gets converted to DateTime with DateTimeKind.Unspecified. This makes it hard to know what the time actually is.

Assemblies affected

System.Web.OData, Version=5.9.0.0

Reproduce steps

Define an entity type based on a .NET class with a property of type DateTime using ODataConventionModelBuilder.
Create a simple controller for it with a Post method.
Post and entity to it with the date specified including time zone, say, "2016-09-03T09:36:35.7788542Z"
Look at the value of the property. It has DateTimeKind.Unspecified.

Expected result

Should be Utc or Local.

Actual result

DateTimeKind is Unspecified

Additional details

System.Web.OData.Formatter.EdmPrimitiveHelpers.ConvertPrimitiveValue already offset to local time zone when converting DateTimeOffset to DateTime. Yet, because dateTimeOffsetValue.DateTime is used instead of either dateTimeOffsetValue.LocalDateTime or dateTimeOffsetValue.UtcDateTime the DateTime has the DateTimeKind.Unkown kind.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at System.Web.OData.Formatter.EdmPrimitiveHelpers.ConvertPrimitiveValue and inspect the DateTimeOffset-to-DateTime conversion path described in the report. Verify the resulting DateTime preserves an appropriate Utc or Local kind rather than Unspecified, then run the existing formatter tests covering primitive conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.