Skip to content

Commit

Permalink
support datatime whose kind is Local
Browse files Browse the repository at this point in the history
  • Loading branch information
QingshuChen committed Aug 23, 2016
1 parent 7acc926 commit 696bebe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ public override ODataPrimitiveValue CreateODataPrimitiveValue(
if (primitiveType != null && primitiveType.IsDateTimeOffset() && graph is DateTime)
{
// If DateTime.Kind equals Local, offset should equal the offset of the system's local time zone
graph = new DateTimeOffset((DateTime)graph,
((DateTime)graph).Kind == DateTimeKind.Local ?
TimeZoneInfo.Local.GetUtcOffset((DateTime)graph) : TimeSpan.Zero);
if (((DateTime)graph).Kind == DateTimeKind.Local)
{
graph = new DateTimeOffset((DateTime)graph, TimeZoneInfo.Local.GetUtcOffset((DateTime)graph));
}
else
{
graph = new DateTimeOffset((DateTime)graph, TimeSpan.Zero);
}
}

return base.CreateODataPrimitiveValue(graph, primitiveType, writeContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public override object ConvertToPayloadValue(object value, IEdmTypeReference edm

// System.DateTime[SqlType = DateTime or DateTime2] => Edm.DateTimeOffset
// If DateTime.Kind equals Local, offset should equal the offset of the system's local time zone
return new DateTimeOffset(dateTimeValue, dateTimeValue.Kind == DateTimeKind.Local ?
TimeZoneInfo.Local.GetUtcOffset(dateTimeValue) : TimeSpan.Zero);
if (dateTimeValue.Kind == DateTimeKind.Local)
{
return new DateTimeOffset(dateTimeValue, TimeZoneInfo.Local.GetUtcOffset(dateTimeValue));
}

return new DateTimeOffset(dateTimeValue, TimeSpan.Zero);
}

// System.TimeSpan is shared by *Edm.TimeOfDay and Edm.Duration:
Expand Down

0 comments on commit 696bebe

Please sign in to comment.