diff --git a/src/Microsoft.Restier.Publishers.OData/Formatter/Serialization/RestierPrimitiveSerializer.cs b/src/Microsoft.Restier.Publishers.OData/Formatter/Serialization/RestierPrimitiveSerializer.cs index d5ee4068..ddc7d4cb 100644 --- a/src/Microsoft.Restier.Publishers.OData/Formatter/Serialization/RestierPrimitiveSerializer.cs +++ b/src/Microsoft.Restier.Publishers.OData/Formatter/Serialization/RestierPrimitiveSerializer.cs @@ -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); diff --git a/src/Microsoft.Restier.Publishers.OData/RestierPayloadValueConverter.cs b/src/Microsoft.Restier.Publishers.OData/RestierPayloadValueConverter.cs index ee9cb9b5..2fac72a1 100644 --- a/src/Microsoft.Restier.Publishers.OData/RestierPayloadValueConverter.cs +++ b/src/Microsoft.Restier.Publishers.OData/RestierPayloadValueConverter.cs @@ -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: