Skip to content

Commit

Permalink
Added general function for converting datetime to UTC-ZeroDateTime an…
Browse files Browse the repository at this point in the history
…d added calls to the that function on places where we can lookup the column-type. bump version to 10.0.11
  • Loading branch information
MatthiasSort committed Nov 14, 2023
1 parent 4f6c632 commit 07835cd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.10</Version>
<Version>10.0.11</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
6 changes: 3 additions & 3 deletions src/ODataSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
33 changes: 23 additions & 10 deletions src/ODataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ public void Write(Dictionary<string, object> 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}");
Expand Down Expand Up @@ -232,6 +236,10 @@ internal List<string> GetKeyColumnValuesForFilter(Dictionary<string, object> 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)}");
Expand Down Expand Up @@ -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));
Expand All @@ -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() { }
Expand Down

0 comments on commit 07835cd

Please sign in to comment.