Update JsonWriter.cs
This commit is contained in:
@@ -696,27 +696,31 @@ namespace Newtonsoft.Json
|
|||||||
|
|
||||||
private void WriteConstructorDate(JsonReader reader)
|
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]);
|
||||||
}
|
}
|
||||||
|
else if (DateParams.Count == 7) //Add support: new Date(2018,5,26,11,14,31,36)
|
||||||
long ticks = (long)reader.Value;
|
|
||||||
DateTime date = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);
|
|
||||||
|
|
||||||
if (!reader.Read())
|
|
||||||
{
|
{
|
||||||
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)
|
else
|
||||||
{
|
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Wrong number of arguments", null);
|
||||||
throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected EndConstructor, got " + reader.TokenType, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
WriteValue(date);
|
WriteValue(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user