Skip to content

Commit

Permalink
fix the bug that dateTime.Kind equals Local and offset does not equal…
Browse files Browse the repository at this point in the history
… the offset of the system's local time zone when invoke the DateTimeOffset constructor
  • Loading branch information
QingshuChen committed Aug 22, 2016
1 parent e2343a2 commit 7acc926
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public override ODataPrimitiveValue CreateODataPrimitiveValue(
// zone when converting the "graph" to a DateTimeOffset.
if (primitiveType != null && primitiveType.IsDateTimeOffset() && graph is DateTime)
{
graph = new DateTimeOffset((DateTime)graph, TimeSpan.Zero);
// 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);
}

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

// System.DateTime[SqlType = DateTime or DateTime2] => Edm.DateTimeOffset
return new DateTimeOffset(dateTimeValue, TimeSpan.Zero);
// 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);
}

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

0 comments on commit 7acc926

Please sign in to comment.