diff --git a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj index b67c586..b086fa6 100644 --- a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj @@ -1,6 +1,6 @@  - 10.0.20 + 10.0.21 1.0.0.0 OData Provider The Odata Provider lets you fetch and map data from or to any OData endpoint. diff --git a/src/ODataWriter.cs b/src/ODataWriter.cs index 493d9ef..17fbd42 100644 --- a/src/ODataWriter.cs +++ b/src/ODataWriter.cs @@ -8,6 +8,7 @@ using Dynamicweb.Logging; using System; using System.Collections.Generic; +using System.Data.SqlTypes; using System.Globalization; using System.Linq; using System.Net; @@ -269,7 +270,7 @@ internal List GetKeyColumnValuesForFilter(Dictionary row } else if (keyMapping.DestinationColumn.Type == typeof(DateTime)) { - keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {keyMapping.ConvertInputValueToOutputValue(GetTheDateTimeInZeroTimeZone(row[keyMapping.SourceColumn?.Name], false))}"); + keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {GetTheDateTimeInZeroTimeZone(keyMapping.ConvertInputValueToOutputValue(row[keyMapping.SourceColumn?.Name]), false)}"); } else { @@ -318,14 +319,25 @@ internal string MapValuesToJSon(Dictionary row, bool isPatchRequ public static string GetTheDateTimeInZeroTimeZone(object dateTimeObject, bool isEdmDate) { var dateTime = Converter.ToDateTime(dateTimeObject); - DateTime dateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime); + DateTime dateTimeInUtc; + if (SqlDateTime.MinValue.Value == dateTime || DateTime.MinValue == dateTime) + { + return null; + } + else if (SqlDateTime.MaxValue.Value == dateTime || DateTime.MaxValue == dateTime) + { + return DateTime.MaxValue.ToString("yyyy-MM-dd"); + } + + dateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime); + if (dateTimeInUtc.TimeOfDay.TotalMilliseconds > 0 && !isEdmDate) { return dateTimeInUtc.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture) + "z"; } else { - return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "z"; + return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); } }