AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

Avoiding return DateTime.Kind=Unspecified when converting from DateTimeOffset to DateTime (issues 378, 384 and others)

Open darkeagle76 opened this issue 1 year ago • 5 comments

fixes #378 , fixes #384 With this modification we would avoid getting a DateTime value (derived from a conversion from a DateTimeOffset value) that has Kind=Unspecified. The problem is mainly evident when passing Dates as parameters of the ODATA $filter option. With this change the conversion will aways return an UTC datetime when it is originated from a DateTimeOffset value.

I already provided additional details here: but my original comment remained without answer.

Thanks in advance for considering my request. D

darkeagle76 avatar Aug 29 '23 14:08 darkeagle76

With this modification we would avoid getting a DateTime value (derived from a conversion from a DateTimeOffset value) that has Kind=Unspecified. The problem is mainly evident when passing Dates as parameters of the ODATA $filter option. With this change the conversion will aways return an UTC datetime when it is originated from a DateTimeOffset value.

I already provided additional details here: but my original comment remained without answer.

Thanks in advance for considering my request. D

@microsoft-github-policy-service agree

darkeagle76 avatar Aug 29 '23 14:08 darkeagle76

Thank you @darkeagle76 for your contribution. The build was triggered and tests are failing after your change. Please check that out In addition, please add tests to validate your change.

gathogojr avatar Sep 25 '23 07:09 gathogojr

Is there a reason this hasn't been addressed? This problem breaks any usage of odata with newer Postgres/EFcore with date filtering.

Perhaps if there's concern about breaking existing usages, we just need another option on query settings like this that can default to the old way:

            options.TimeZone = TimeZoneInfo.Utc;
            options.DateTimeOffsetToDateTimeTransform = (DateTimeOffset dto) => dto.UtcDateTime;

jusbuc2k avatar Aug 01 '24 15:08 jusbuc2k