-Changed time zone conversions to use new TimeZoneInfo instead of TimeZone
This commit is contained in:
@@ -73,7 +73,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
d = new DateTime(2000, 12, 15, 22, 11, 3, 55, DateTimeKind.Local);
|
||||
result = JsonConvert.SerializeObject(d, converter);
|
||||
Assert.AreEqual(@"""2000-12-15T22:11:03.055" + d.GetLocalOffset() + @"""", result);
|
||||
Assert.AreEqual(@"""2000-12-15T22:11:03.055" + d.GetUtcOffsetText() + @"""", result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -272,13 +272,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
c.DateTimeField = new DateTime(2008, 1, 1, 1, 1, 1, 0, DateTimeKind.Utc);
|
||||
string json2 = JsonConvert.SerializeObject(c, new IsoDateTimeConverter() { DateTimeStyles = DateTimeStyles.AssumeUniversal });
|
||||
|
||||
TimeSpan offset;
|
||||
|
||||
#if SILVERLIGHT
|
||||
offset = TimeZoneInfo.Local.GetUtcOffset(localDateTime);
|
||||
#else
|
||||
offset = TimeZone.CurrentTimeZone.GetUtcOffset(localDateTime);
|
||||
#endif
|
||||
TimeSpan offset = localDateTime.GetUtcOffset();
|
||||
|
||||
// if the current timezone is utc then local already equals utc
|
||||
if (offset == TimeSpan.Zero)
|
||||
|
||||
@@ -44,13 +44,6 @@ namespace Newtonsoft.Json.Tests
|
||||
//Thread.CurrentThread.CurrentUICulture = turkey;
|
||||
}
|
||||
|
||||
//public string GetOffset(DateTime value)
|
||||
//{
|
||||
// TimeSpan utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(value.ToLocalTime());
|
||||
|
||||
// return utcOffset.Hours.ToString("+00;-00") + utcOffset.Minutes.ToString("00;00");
|
||||
//}
|
||||
|
||||
protected void WriteEscapedJson(string json)
|
||||
{
|
||||
Console.WriteLine(EscapeJson(json));
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
using (StringWriter writer = StringUtils.CreateStringWriter(64))
|
||||
{
|
||||
WriteDateTimeString(writer, value, GetUtcOffset(value), value.Kind);
|
||||
WriteDateTimeString(writer, value, value.GetUtcOffset(), value.Kind);
|
||||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
@@ -108,18 +108,9 @@ namespace Newtonsoft.Json
|
||||
}
|
||||
#endif
|
||||
|
||||
private static TimeSpan GetUtcOffset(DateTime dateTime)
|
||||
{
|
||||
#if SILVERLIGHT
|
||||
return TimeZoneInfo.Local.GetUtcOffset(dateTime);
|
||||
#else
|
||||
return TimeZone.CurrentTimeZone.GetUtcOffset(dateTime);
|
||||
#endif
|
||||
}
|
||||
|
||||
internal static void WriteDateTimeString(TextWriter writer, DateTime value)
|
||||
{
|
||||
WriteDateTimeString(writer, value, GetUtcOffset(value), value.Kind);
|
||||
WriteDateTimeString(writer, value, value.GetUtcOffset(), value.Kind);
|
||||
}
|
||||
|
||||
internal static void WriteDateTimeString(TextWriter writer, DateTime value, TimeSpan offset, DateTimeKind kind)
|
||||
@@ -154,7 +145,7 @@ namespace Newtonsoft.Json
|
||||
if (dateTime.Kind == DateTimeKind.Utc)
|
||||
return dateTime.Ticks;
|
||||
|
||||
return ToUniversalTicks(dateTime, GetUtcOffset(dateTime));
|
||||
return ToUniversalTicks(dateTime, dateTime.GetUtcOffset());
|
||||
}
|
||||
|
||||
private static long ToUniversalTicks(DateTime dateTime, TimeSpan offset)
|
||||
|
||||
@@ -9,18 +9,22 @@ namespace Newtonsoft.Json.Utilities
|
||||
{
|
||||
internal static class DateTimeUtils
|
||||
{
|
||||
public static string GetLocalOffset(this DateTime d)
|
||||
public static string GetUtcOffsetText(this DateTime d)
|
||||
{
|
||||
TimeSpan utcOffset;
|
||||
#if PocketPC || NET20
|
||||
utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(d);
|
||||
#else
|
||||
utcOffset = TimeZoneInfo.Local.GetUtcOffset(d);
|
||||
#endif
|
||||
TimeSpan utcOffset = d.GetUtcOffset();
|
||||
|
||||
return utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public static TimeSpan GetUtcOffset(this DateTime d)
|
||||
{
|
||||
#if PocketPC || NET20
|
||||
return TimeZone.CurrentTimeZone.GetUtcOffset(d);
|
||||
#else
|
||||
return TimeZoneInfo.Local.GetUtcOffset(d);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static XmlDateTimeSerializationMode ToSerializationMode(DateTimeKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
|
||||
Reference in New Issue
Block a user