Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added convertion of SqlDateTime.MinValue.Value to 0001-01-01 and skip… #33

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
frederik5480 marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "z";
return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
}
}

Expand Down
Loading