correct naming (#1696)

This commit is contained in:
bocus
2018-05-21 10:06:37 +12:00
committed by James Newton-King
parent 851af6b84b
commit aa4062d586
2 changed files with 12 additions and 12 deletions
@@ -55,11 +55,11 @@ namespace Newtonsoft.Json.Tests.Converters
public void SerializeDateTimeNow() public void SerializeDateTimeNow()
{ {
DateTime now = DateTime.Now; DateTime now = DateTime.Now;
long nowTicks = (long)(now.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds; long nowSeconds = (long)(now.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalSeconds;
string result = JsonConvert.SerializeObject(now, new UnixDateTimeConverter()); string result = JsonConvert.SerializeObject(now, new UnixDateTimeConverter());
Assert.AreEqual(nowTicks + "", result); Assert.AreEqual(nowSeconds + "", result);
} }
[Test] [Test]
@@ -44,16 +44,16 @@ namespace Newtonsoft.Json.Converters
/// <param name="serializer">The calling serializer.</param> /// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{ {
long ticks; long seconds;
if (value is DateTime dateTime) if (value is DateTime dateTime)
{ {
ticks = (long)(dateTime.ToUniversalTime() - UnixEpoch).TotalSeconds; seconds = (long)(dateTime.ToUniversalTime() - UnixEpoch).TotalSeconds;
} }
#if HAVE_DATE_TIME_OFFSET #if HAVE_DATE_TIME_OFFSET
else if (value is DateTimeOffset dateTimeOffset) else if (value is DateTimeOffset dateTimeOffset)
{ {
ticks = (long)(dateTimeOffset.ToUniversalTime() - UnixEpoch).TotalSeconds; seconds = (long)(dateTimeOffset.ToUniversalTime() - UnixEpoch).TotalSeconds;
} }
#endif #endif
else else
@@ -61,12 +61,12 @@ namespace Newtonsoft.Json.Converters
throw new JsonSerializationException("Expected date object value."); throw new JsonSerializationException("Expected date object value.");
} }
if (ticks < 0) if (seconds < 0)
{ {
throw new JsonSerializationException("Cannot convert date value that is before Unix epoch of 00:00:00 UTC on 1 January 1970."); throw new JsonSerializationException("Cannot convert date value that is before Unix epoch of 00:00:00 UTC on 1 January 1970.");
} }
writer.WriteValue(ticks); writer.WriteValue(seconds);
} }
/// <summary> /// <summary>
@@ -90,15 +90,15 @@ namespace Newtonsoft.Json.Converters
return null; return null;
} }
long ticks; long seconds;
if (reader.TokenType == JsonToken.Integer) if (reader.TokenType == JsonToken.Integer)
{ {
ticks = (long)reader.Value; seconds = (long)reader.Value;
} }
else if (reader.TokenType == JsonToken.String) else if (reader.TokenType == JsonToken.String)
{ {
if (!long.TryParse((string)reader.Value, out ticks)) if (!long.TryParse((string)reader.Value, out seconds))
{ {
throw JsonSerializationException.Create(reader, "Cannot convert invalid value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType)); throw JsonSerializationException.Create(reader, "Cannot convert invalid value to {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
} }
@@ -108,9 +108,9 @@ namespace Newtonsoft.Json.Converters
throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected Integer or String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); throw JsonSerializationException.Create(reader, "Unexpected token parsing date. Expected Integer or String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
} }
if (ticks >= 0) if (seconds >= 0)
{ {
DateTime d = UnixEpoch.AddSeconds(ticks); DateTime d = UnixEpoch.AddSeconds(seconds);
#if HAVE_DATE_TIME_OFFSET #if HAVE_DATE_TIME_OFFSET
Type t = (nullable) Type t = (nullable)