feat: Adding shims for converting DateTimes to/from XML

This commit is contained in:
Chris Cameron
2020-01-28 16:18:26 -05:00
parent 8d2321c350
commit 13d1072d10

View File

@@ -314,6 +314,11 @@ namespace ICD.Common.Utils.Xml
return XmlConvert.ToString(value); return XmlConvert.ToString(value);
} }
public static string ToString(DateTime value)
{
return value.ToString("o");
}
public static string ToString(TimeSpan value) public static string ToString(TimeSpan value)
{ {
return XmlConvert.ToString(value); return XmlConvert.ToString(value);
@@ -351,6 +356,8 @@ namespace ICD.Common.Utils.Xml
return ToString((sbyte)child); return ToString((sbyte)child);
if (child is short) if (child is short)
return ToString((short)child); return ToString((short)child);
if (child is DateTime)
return ToString((DateTime)child);
if (child is TimeSpan) if (child is TimeSpan)
return ToString((TimeSpan)child); return ToString((TimeSpan)child);
if (child is uint) if (child is uint)
@@ -395,6 +402,8 @@ namespace ICD.Common.Utils.Xml
return ToSByte(value); return ToSByte(value);
if (type == typeof(short)) if (type == typeof(short))
return ToInt16(value); return ToInt16(value);
if (type == typeof(DateTime))
return ToDateTime(value);
if (type == typeof(TimeSpan)) if (type == typeof(TimeSpan))
return ToTimeSpan(value); return ToTimeSpan(value);
if (type == typeof(uint)) if (type == typeof(uint))
@@ -422,6 +431,11 @@ namespace ICD.Common.Utils.Xml
return XmlConvert.ToChar(data); return XmlConvert.ToChar(data);
} }
public static DateTime ToDateTime(string data)
{
return DateTime.Parse(data);
}
public static DateTime ToDateTime(string data, string format) public static DateTime ToDateTime(string data, string format)
{ {
return XmlConvert.ToDateTime(data, format); return XmlConvert.ToDateTime(data, format);