From 8c5ba5ad4d766304192bcbb26fca2d281348ba4f Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Mon, 15 Apr 2024 14:51:59 +0200 Subject: [PATCH 1/3] Added convertion of SqlDateTime.MinValue.Value to 0001-01-01 and skipped the "z" at the end when we export data to OData. --- ...ataIntegration.Providers.ODataProvider.csproj | 2 +- src/ODataWriter.cs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) 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..8f601c8 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,7 +319,18 @@ 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 DateTime.MinValue.ToString("yyyy-MM-dd"); + } + 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"; From 6984284d67e1fe1b7f2eae2cbee1656e6884b264 Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Tue, 16 Apr 2024 10:13:04 +0200 Subject: [PATCH 2/3] removed "z" from dates in "yyyy-MM-dd" format --- src/ODataWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ODataWriter.cs b/src/ODataWriter.cs index 8f601c8..b8d9f61 100644 --- a/src/ODataWriter.cs +++ b/src/ODataWriter.cs @@ -337,7 +337,7 @@ public static string GetTheDateTimeInZeroTimeZone(object dateTimeObject, bool is } else { - return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "z"; + return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); } } From 3263001c981f4225a7cca2e400cfdee9c9c18759 Mon Sep 17 00:00:00 2001 From: Matthias Sebastian Sort Date: Tue, 16 Apr 2024 10:13:50 +0200 Subject: [PATCH 3/3] changed DateTime minvalue to return null instead. --- src/ODataWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ODataWriter.cs b/src/ODataWriter.cs index b8d9f61..17fbd42 100644 --- a/src/ODataWriter.cs +++ b/src/ODataWriter.cs @@ -322,7 +322,7 @@ public static string GetTheDateTimeInZeroTimeZone(object dateTimeObject, bool is DateTime dateTimeInUtc; if (SqlDateTime.MinValue.Value == dateTime || DateTime.MinValue == dateTime) { - return DateTime.MinValue.ToString("yyyy-MM-dd"); + return null; } else if (SqlDateTime.MaxValue.Value == dateTime || DateTime.MaxValue == dateTime) {