Skip to content

Commit

Permalink
Added convertion of SqlDateTime.MinValue.Value to 0001-01-01 and skip…
Browse files Browse the repository at this point in the history
…ped the "z" at the end when we export data to OData.
  • Loading branch information
MatthiasSort committed Apr 15, 2024
1 parent 1f0d79d commit 8c5ba5a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.20</Version>
<Version>10.0.21</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
16 changes: 14 additions & 2 deletions src/ODataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -269,7 +270,7 @@ internal List<string> GetKeyColumnValuesForFilter(Dictionary<string, object> 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
{
Expand Down Expand Up @@ -318,7 +319,18 @@ internal string MapValuesToJSon(Dictionary<string, object> 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";
Expand Down

0 comments on commit 8c5ba5a

Please sign in to comment.