From 07835cd779cac5169151eb4d18a205fdebf4f356 Mon Sep 17 00:00:00 2001 From: MatthiasSort Date: Tue, 14 Nov 2023 09:36:52 +0100 Subject: [PATCH] Added general function for converting datetime to UTC-ZeroDateTime and added calls to the that function on places where we can lookup the column-type. bump version to 10.0.11 --- ...Integration.Providers.ODataProvider.csproj | 2 +- src/ODataSourceReader.cs | 6 ++-- src/ODataWriter.cs | 33 +++++++++++++------ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj index 0881fc8..6a59465 100644 --- a/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj +++ b/src/Dynamicweb.DataIntegration.Providers.ODataProvider.csproj @@ -1,6 +1,6 @@  - 10.0.10 + 10.0.11 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/ODataSourceReader.cs b/src/ODataSourceReader.cs index b817b5b..26d9e2f 100644 --- a/src/ODataSourceReader.cs +++ b/src/ODataSourceReader.cs @@ -244,7 +244,6 @@ private string GetModeAsParameters() DateTime? lastRunDateTime = _mapping.Job.LastSuccessfulRun; if (lastRunDateTime != null) { - DateTime dateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(lastRunDateTime.Value); string dateTimeFilterName = ""; bool isEdmDate = false; @@ -290,13 +289,14 @@ private string GetModeAsParameters() if (!string.IsNullOrWhiteSpace(dateTimeFilterName)) { + var theDateTime = ODataWriter.GetTheDateTimeInZeroTimeZone(lastRunDateTime.Value.ToString(CultureInfo.InvariantCulture), isEdmDate); if (isEdmDate) { - dateTimeFilterName += " ge " + dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "z"; + dateTimeFilterName += " ge " + theDateTime; } else { - dateTimeFilterName += " gt " + dateTimeInUtc.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture) + "z"; + dateTimeFilterName += " gt " + theDateTime; } result = dateTimeFilterName; } diff --git a/src/ODataWriter.cs b/src/ODataWriter.cs index 2e1898d..8cc4349 100644 --- a/src/ODataWriter.cs +++ b/src/ODataWriter.cs @@ -110,6 +110,10 @@ public void Write(Dictionary Row) { primaryKeyColumnValuesForPatch.Add($"{item.Key}='{item.Value}'"); } + else if (columnKeyType == typeof(DateTime)) + { + primaryKeyColumnValuesForPatch.Add($"{item.Key}={GetTheDateTimeInZeroTimeZone(item.Value, false)}"); + } else { primaryKeyColumnValuesForPatch.Add($"{item.Key}={item.Value}"); @@ -232,6 +236,10 @@ internal List GetKeyColumnValuesForFilter(Dictionary row { keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq '{keyMapping.ConvertInputValueToOutputValue(row[keyMapping.SourceColumn?.Name] ?? null)}'"); } + else if (keyMapping.DestinationColumn.Type == typeof(DateTime)) + { + keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {keyMapping.ConvertInputValueToOutputValue(GetTheDateTimeInZeroTimeZone(row[keyMapping.SourceColumn?.Name], false))}"); + } else { keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {keyMapping.ConvertInputValueToOutputValue(row[keyMapping.SourceColumn?.Name] ?? null)}"); @@ -265,16 +273,7 @@ internal string MapValuesToJSon(ColumnMappingCollection columnMappings, Dictiona jsonObject.Add(columnMapping.DestinationColumn.Name, Converter.ToDecimal(columnValue)); break; case "datetime": - var dateTime = Converter.ToDateTime(columnValue); - DateTime dateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime); - if (dateTimeInUtc.TimeOfDay.TotalMilliseconds > 0) - { - jsonObject.Add(columnMapping.DestinationColumn.Name, dateTimeInUtc.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture) + "z"); - } - else - { - jsonObject.Add(columnMapping.DestinationColumn.Name, dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "z"); - } + jsonObject.Add(columnMapping.DestinationColumn.Name, GetTheDateTimeInZeroTimeZone(columnValue, false)); break; default: jsonObject.Add(columnMapping.DestinationColumn.Name, Converter.ToString(columnValue)); @@ -285,6 +284,20 @@ internal string MapValuesToJSon(ColumnMappingCollection columnMappings, Dictiona return jsonObject.ToString(); } + public static string GetTheDateTimeInZeroTimeZone(object dateTimeObject, bool isEdmDate) + { + var dateTime = Converter.ToDateTime(dateTimeObject); + DateTime 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"; + } + } + public void Dispose() { } public void Close() { }