AspNetCoreOData
AspNetCoreOData copied to clipboard
Avoiding return DateTime.Kind=Unspecified when converting from DateTimeOffset to DateTime (issues 378, 384 and others)
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
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
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.
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;