From 2a98d3de8e962be0de60129859813ed011d5b054 Mon Sep 17 00:00:00 2001 From: darkeagle76 <41543959+darkeagle76@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:47:42 +0200 Subject: [PATCH] Avoiding return DateTime.Kind=Unspecified when converting from DateTimeOffset to DateTime 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. --- src/Microsoft.AspNetCore.OData/Edm/EdmPrimitiveHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.OData/Edm/EdmPrimitiveHelper.cs b/src/Microsoft.AspNetCore.OData/Edm/EdmPrimitiveHelper.cs index 4226f0a08..3d266f2d7 100644 --- a/src/Microsoft.AspNetCore.OData/Edm/EdmPrimitiveHelper.cs +++ b/src/Microsoft.AspNetCore.OData/Edm/EdmPrimitiveHelper.cs @@ -106,7 +106,7 @@ public static object ConvertPrimitiveValue(object value, Type type, TimeZoneInfo DateTimeOffset dateTimeOffsetValue = (DateTimeOffset)value; TimeZoneInfo timeZone = timeZoneInfo ?? TimeZoneInfo.Local; dateTimeOffsetValue = TimeZoneInfo.ConvertTime(dateTimeOffsetValue, timeZone); - return dateTimeOffsetValue.DateTime; + return dateTimeOffsetValue.UtcDateTime; } if (value is Date)