Skip to content

Commit

Permalink
Merge pull request #33 from dynamicweb/mss/16879
Browse files Browse the repository at this point in the history
Added convertion of SqlDateTime.MinValue.Value to 0001-01-01 and skip…
  • Loading branch information
frederik5480 authored Apr 16, 2024
2 parents 1f0d79d + 3263001 commit ab29cc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 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
18 changes: 15 additions & 3 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,14 +319,25 @@ 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 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);
}
}

Expand Down

0 comments on commit ab29cc2

Please sign in to comment.