Update JsonWriter.cs

This commit is contained in:
wybb
2018-09-23 13:57:43 -07:00
committed by James Newton-King
parent eb0cf43e9a
commit 70dabfb409
+19 -15
View File
@@ -696,27 +696,31 @@ namespace Newtonsoft.Json
private void WriteConstructorDate(JsonReader reader)
{
if (!reader.Read())
List<long> DateParams = new List<long>();
while (true)
{
throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
if (!reader.Read())
throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
if (reader.TokenType == JsonToken.EndConstructor)
break;
if (reader.TokenType != JsonToken.Integer)
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected Integer, got " + reader.TokenType, null);
DateParams.Add((long)reader.Value);
if (DateParams.Count > 7)
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Wrong number of arguments", null);
}
if (reader.TokenType != JsonToken.Integer)
DateTime date;
if (DateParams.Count == 1)
{
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected Integer, got " + reader.TokenType, null);
date = DateTimeUtils.ConvertJavaScriptTicksToDateTime(DateParams[0]);
}
long ticks = (long)reader.Value;
DateTime date = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);
if (!reader.Read())
else if (DateParams.Count == 7) //Add support: new Date(2018,5,26,11,14,31,36)
{
throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
date = new DateTime((int)DateParams[0], (int)DateParams[1] + 1, (int)DateParams[2], (int)DateParams[3],
(int)DateParams[4], (int)DateParams[5], (int)DateParams[6]);
}
if (reader.TokenType != JsonToken.EndConstructor)
{
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected EndConstructor, got " + reader.TokenType, null);
}
else
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Wrong number of arguments", null);
WriteValue(date);
}