Skip to content

Commit ee5e356

Browse files
author
Chris Santero
committed
convert incoming DateTime values to UTC
1 parent bbc19fb commit ee5e356

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

JSONAPI.Tests/Core/ResourceTypeRegistrarTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ public void BuildRegistration_sets_up_correct_attribute_for_DateTime_field()
636636
var reg = registrar.BuildRegistration(typeof(AttributeGrabBag));
637637

638638
// Assert
639-
AssertAttribute(reg, "date-time-field", "1776-07-04", new DateTime(1776, 07, 04), "1776-07-04T00:00:00", g => g.DateTimeField);
640-
AssertAttribute(reg, "date-time-field", "1776-07-04T00:00:00", new DateTime(1776, 07, 04), "1776-07-04T00:00:00", g => g.DateTimeField);
639+
AssertAttribute(reg, "date-time-field", "1776-07-04", new DateTime(1776, 07, 04, 0, 0, 0, DateTimeKind.Utc), "1776-07-04T00:00:00", g => g.DateTimeField);
640+
AssertAttribute(reg, "date-time-field", "1776-07-04T00:00:00", new DateTime(1776, 07, 04, 0, 0, 0, DateTimeKind.Utc), "1776-07-04T00:00:00", g => g.DateTimeField);
641641
AssertAttribute(reg, "date-time-field", null, new DateTime(), "0001-01-01T00:00:00", g => g.DateTimeField);
642642
}
643643

@@ -651,8 +651,8 @@ public void BuildRegistration_sets_up_correct_attribute_for_nullable_DateTime_fi
651651
var reg = registrar.BuildRegistration(typeof(AttributeGrabBag));
652652

653653
// Assert
654-
AssertAttribute(reg, "nullable-date-time-field", "1776-07-04", new DateTime(1776, 07, 04), "1776-07-04T00:00:00", g => g.NullableDateTimeField);
655-
AssertAttribute(reg, "nullable-date-time-field", "1776-07-04T00:00:00", new DateTime(1776, 07, 04), "1776-07-04T00:00:00", g => g.NullableDateTimeField);
654+
AssertAttribute(reg, "nullable-date-time-field", "1776-07-04", new DateTime(1776, 07, 04, 0, 0, 0, DateTimeKind.Utc), "1776-07-04T00:00:00", g => g.NullableDateTimeField);
655+
AssertAttribute(reg, "nullable-date-time-field", "1776-07-04T00:00:00", new DateTime(1776, 07, 04, 0, 0, 0, DateTimeKind.Utc), "1776-07-04T00:00:00", g => g.NullableDateTimeField);
656656
AssertAttribute(reg, "nullable-date-time-field", null, null, (DateTime?)null, g => g.NullableDateTimeField);
657657
}
658658

JSONAPI/Core/DateTimeAttributeValueConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public void SetValue(object resource, JToken value)
4141
else
4242
{
4343
var dateTimeValue = value.Value<DateTime>();
44+
if (dateTimeValue.Kind == DateTimeKind.Local) dateTimeValue = dateTimeValue.ToUniversalTime();
4445
_property.SetValue(resource, dateTimeValue);
4546
}
4647
}

0 commit comments

Comments
 (0)