diff --git a/src/NServiceKit.Text/Common/DateTimeSerializer.cs b/src/NServiceKit.Text/Common/DateTimeSerializer.cs
index f3c32a2..72c8df0 100644
--- a/src/NServiceKit.Text/Common/DateTimeSerializer.cs
+++ b/src/NServiceKit.Text/Common/DateTimeSerializer.cs
@@ -73,18 +73,26 @@ public static class DateTimeSerializer
/// The XSD UTC suffix.
private const string XsdUtcSuffix = "Z";
- /// If AlwaysUseUtc is set to true then convert all DateTime to UTC.
+ ///
+ /// If AssumeUtc, assume DateTimeKind.Unspecified dates are really UTC.
+ /// If AlwaysUseUtc is set to true then convert all DateTime to UTC.
+ ///
/// Date Time to be "Prepared".
/// true to parsed as UTC.
/// The Prepared DateTime.
private static DateTime Prepare(this DateTime dateTime, bool parsedAsUtc = false)
{
+ if (dateTime.Kind == DateTimeKind.Unspecified && JsConfig.DateHandler != JsonDateHandler.TimestampOffset)
+ {
+ dateTime = DateTime.SpecifyKind(dateTime, JsConfig.AssumeUtc ? DateTimeKind.Utc : DateTimeKind.Local);
+ }
+
if (JsConfig.AlwaysUseUtc)
{
return dateTime.Kind != DateTimeKind.Utc ? dateTime.ToStableUniversalTime() : dateTime;
}
- return parsedAsUtc ? dateTime.ToLocalTime() : dateTime;
+ return parsedAsUtc && !JsConfig.AssumeUtc ? dateTime.ToLocalTime() : dateTime;
}
/// Parses a date time string and returns a nullable datetime.
@@ -155,7 +163,7 @@ public static DateTime ParseShortestXsdDateTime(string dateTimeStr)
try
{
- return DateTime.Parse(dateTimeStr, null, DateTimeStyles.AssumeLocal).Prepare();
+ return DateTime.Parse(dateTimeStr).Prepare();
}
catch (FormatException)
{
diff --git a/tests/NServiceKit.Text.Tests/JsonTests/JsonDateTimeTests.cs b/tests/NServiceKit.Text.Tests/JsonTests/JsonDateTimeTests.cs
index f12b171..a7732ef 100644
--- a/tests/NServiceKit.Text.Tests/JsonTests/JsonDateTimeTests.cs
+++ b/tests/NServiceKit.Text.Tests/JsonTests/JsonDateTimeTests.cs
@@ -383,16 +383,16 @@ public void Can_deserialize_json_date_iso8601_withZOffset_asUtc()
JsConfig.Reset();
}
- /// Can deserialize JSON date ISO 8601 without offset as unspecified.
+ /// Can deserialize JSON date ISO 8601 without offset as Local (per the ISO 8601 spec).
[Test]
- public void Can_deserialize_json_date_iso8601_withoutOffset_asUnspecified()
+ public void Can_deserialize_json_date_iso8601_withoutOffset_asLocal()
{
JsConfig.DateHandler = JsonDateHandler.ISO8601;
const string json = @"""1994-11-24T12:34:56""";
var fromJson = JsonSerializer.DeserializeFromString(json);
- var dateTime = new DateTime(1994, 11, 24, 12, 34, 56, DateTimeKind.Unspecified);
+ var dateTime = new DateTime(1994, 11, 24, 12, 34, 56, DateTimeKind.Local);
Assert.That(fromJson, Is.EqualTo(dateTime));
Assert.That(fromJson.Kind, Is.EqualTo(dateTime.Kind));
JsConfig.Reset();
diff --git a/tests/NServiceKit.Text.Tests/NServiceKit.Text.Tests.csproj b/tests/NServiceKit.Text.Tests/NServiceKit.Text.Tests.csproj
index e337a2c..5b210ea 100644
--- a/tests/NServiceKit.Text.Tests/NServiceKit.Text.Tests.csproj
+++ b/tests/NServiceKit.Text.Tests/NServiceKit.Text.Tests.csproj
@@ -122,9 +122,6 @@
..\..\lib\tests\NServiceKit.ServiceInterface.dll
-
- ..\..\src\NServiceKit.Text\bin\Release\NServiceKit.Text.dll
-
@@ -132,23 +129,10 @@
-
-
-
-
..\..\lib\tests\nunit.framework.dll
-
- ..\..\lib\tests\Platform.dll
-
-
- ..\..\lib\tests\protobuf-net.dll
-
-
- ..\..\lib\tests\protobuf-net.Extensions.dll
-
@@ -265,6 +249,12 @@
+
+
+ {579b3fdb-cdad-44e1-8417-885c38e49a0e}
+ NServiceKit.Text
+
+