-Added DateFormatHandling to control whether dates are written in the MS format or ISO format, with ISO as the default

-Added DateTimeZoneHandling to control reading and writing DateTime time zone details
-Added reader/writer specific Formatting, DateFormatHandling and DateTimeZoneHandling to JsonSerializerSettings
-Added feature of reader/writer specific settings to be set on JsonReader/JsonWriter when serializing
-Added ReadAsDate to JsonReader
-Added ReadAsString to JsonReader
-Changed JsonTextReader to automatically read ISO strings as dates
-Refactored ReadAsXXX methods and reduce code redundancy
-Removed unused JsonDateTimeSerializationMode
This commit is contained in:
James Newton-King
2012-03-04 18:10:20 +06:00
parent fb2a5998bc
commit fd760e3389
43 changed files with 1728 additions and 826 deletions
@@ -107,6 +107,16 @@ namespace Newtonsoft.Json.Converters
return null;
}
if (reader.TokenType == JsonToken.Date)
{
#if !PocketPC && !NET20
if (t == typeof(DateTimeOffset))
return new DateTimeOffset((DateTime)reader.Value);
#endif
return reader.Value;
}
if (reader.TokenType != JsonToken.String)
throw new Exception("Unexpected token parsing date. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Newtonsoft.Json.Converters
{
/// <summary>
/// Specifies whether a DateTime object represents a local time, a Coordinated Universal Time (UTC), or is not specified as either local time or UTC.
/// </summary>
public enum JsonDateTimeSerializationMode
{
/// <summary>
/// The time represented is local time.
/// </summary>
Local,
/// <summary>
/// The time represented is UTC.
/// </summary>
Utc,
/// <summary>
/// The time represented is not specified as either local time or Coordinated Universal Time (UTC).
/// </summary>
Unspecified,
/// <summary>
/// Preserves the DateTimeKind field of a date when a DateTime object is converted to a string and the string is then converted back to a DateTime object.
/// </summary>
RoundtripKind
}
}