-Fixed deserializing certain Microsoft formated dates

This commit is contained in:
James Newton-King
2015-11-28 21:48:10 +13:00
parent 7d4790589f
commit c96779dc10
4 changed files with 31 additions and 2 deletions
@@ -198,6 +198,18 @@ namespace Newtonsoft.Json.Tests.Serialization
}
#endif
#if !NET20
[Test]
public void DeserializeMSDateTimeOffset()
{
DateTimeOffset d = JsonConvert.DeserializeObject<DateTimeOffset>(@"""/Date(1418924498000+0800)/""");
long initialTicks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(d.DateTime, d.Offset);
Assert.AreEqual(1418924498000, initialTicks);
Assert.AreEqual(8, d.Offset.Hours);
}
#endif
[Test]
public void CaseInsensitiveRequiredPropertyConstructorCreation()
{
@@ -177,6 +177,21 @@ namespace Newtonsoft.Json.Tests.Utilities
}
#if !NET20
[Test]
public void ReadOffsetMSDateTimeOffset()
{
char[] c = @"12345/Date(1418924498000+0800)/12345".ToCharArray();
StringReference reference = new StringReference(c, 5, c.Length - 10);
DateTimeOffset d;
DateTimeUtils.TryParseDateTimeOffset(reference, null, CultureInfo.InvariantCulture, out d);
long initialTicks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(d.DateTime, d.Offset);
Assert.AreEqual(1418924498000, initialTicks);
Assert.AreEqual(8, d.Offset.Hours);
}
[Test]
public void NewDateTimeOffsetParse()
{
+2
View File
@@ -1286,7 +1286,9 @@ namespace Newtonsoft.Json
// this is here because adding a WriteValue(BigInteger) to JsonWriter will
// mean the user has to add a reference to System.Numerics.dll
if (value is BigInteger)
{
throw CreateUnsupportedTypeException(this, value);
}
#endif
WriteValue(this, ConvertUtils.GetTypeCode(value.GetType()), value);
@@ -482,7 +482,7 @@ namespace Newtonsoft.Json.Utilities
{
kind = DateTimeKind.Local;
if (!TryReadOffset(text, index, out offset))
if (!TryReadOffset(text, index + text.StartIndex, out offset))
{
ticks = 0;
return false;
@@ -494,7 +494,7 @@ namespace Newtonsoft.Json.Utilities
index = text.Length - 2;
}
return (ConvertUtils.Int64TryParse(text.Chars, 6, index - 6, out ticks) == ParseResult.Success);
return (ConvertUtils.Int64TryParse(text.Chars, 6 + text.StartIndex, index - 6, out ticks) == ParseResult.Success);
}
private static bool TryParseDateTimeMicrosoft(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)