-Fixed deserializing certain Microsoft formated dates
This commit is contained in:
@@ -198,6 +198,18 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
}
|
}
|
||||||
#endif
|
#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]
|
[Test]
|
||||||
public void CaseInsensitiveRequiredPropertyConstructorCreation()
|
public void CaseInsensitiveRequiredPropertyConstructorCreation()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -177,6 +177,21 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !NET20
|
#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]
|
[Test]
|
||||||
public void NewDateTimeOffsetParse()
|
public void NewDateTimeOffsetParse()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1286,7 +1286,9 @@ namespace Newtonsoft.Json
|
|||||||
// this is here because adding a WriteValue(BigInteger) to JsonWriter will
|
// this is here because adding a WriteValue(BigInteger) to JsonWriter will
|
||||||
// mean the user has to add a reference to System.Numerics.dll
|
// mean the user has to add a reference to System.Numerics.dll
|
||||||
if (value is BigInteger)
|
if (value is BigInteger)
|
||||||
|
{
|
||||||
throw CreateUnsupportedTypeException(this, value);
|
throw CreateUnsupportedTypeException(this, value);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WriteValue(this, ConvertUtils.GetTypeCode(value.GetType()), value);
|
WriteValue(this, ConvertUtils.GetTypeCode(value.GetType()), value);
|
||||||
|
|||||||
@@ -482,7 +482,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
{
|
{
|
||||||
kind = DateTimeKind.Local;
|
kind = DateTimeKind.Local;
|
||||||
|
|
||||||
if (!TryReadOffset(text, index, out offset))
|
if (!TryReadOffset(text, index + text.StartIndex, out offset))
|
||||||
{
|
{
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
return false;
|
return false;
|
||||||
@@ -494,7 +494,7 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
index = text.Length - 2;
|
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)
|
private static bool TryParseDateTimeMicrosoft(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)
|
||||||
|
|||||||
Reference in New Issue
Block a user