Fixes object extensions for dates with a 'kind' specified.

This commit is contained in:
Shannon
2014-01-29 11:21:35 +11:00
parent f28ae52ae3
commit ccaf82d797
2 changed files with 29 additions and 22 deletions

View File

@@ -283,7 +283,20 @@ namespace Umbraco.Core
else if (destinationType == typeof(DateTime))
{
DateTime value;
return DateTime.TryParse(input, out value) ? Attempt<object>.Succeed(value) : Attempt<object>.Fail();
if (DateTime.TryParse(input, out value))
{
switch (value.Kind)
{
case DateTimeKind.Unspecified:
case DateTimeKind.Utc:
return Attempt<object>.Succeed(value);
case DateTimeKind.Local:
return Attempt<object>.Succeed(value.ToUniversalTime());
default:
throw new ArgumentOutOfRangeException();
}
}
return Attempt<object>.Fail();
}
else if (destinationType == typeof(DateTimeOffset))
{
@@ -516,7 +529,7 @@ namespace Umbraco.Core
if (type == typeof(bool)) return XmlConvert.ToString((bool)value);
if (type == typeof(byte)) return XmlConvert.ToString((byte)value);
if (type == typeof(char)) return XmlConvert.ToString((char)value);
if (type == typeof(DateTime)) return XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind);
if (type == typeof(DateTime)) return XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.Unspecified);
if (type == typeof(DateTimeOffset)) return XmlConvert.ToString((DateTimeOffset)value);
if (type == typeof(decimal)) return XmlConvert.ToString((decimal)value);
if (type == typeof(double)) return XmlConvert.ToString((double)value);