mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
feat: Adding JsonReader extension to read current value as DateTime
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
|
using ICD.Common.Utils.Json;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace ICD.Common.Utils.Extensions
|
namespace ICD.Common.Utils.Extensions
|
||||||
@@ -205,6 +206,20 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
return new Guid(stringValue);
|
return new Guid(stringValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the current value as a date.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DateTime GetValueAsDateTime(this JsonReader extends)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
|
string stringValue = extends.GetValueAsString();
|
||||||
|
return JsonUtils.ParseDateTime(stringValue);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deserializes an array of items from the reader's current value.
|
/// Deserializes an array of items from the reader's current value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -22,6 +22,16 @@ namespace ICD.Common.Utils.Json
|
|||||||
private const string MESSAGE_NAME_PROPERTY = "m";
|
private const string MESSAGE_NAME_PROPERTY = "m";
|
||||||
private const string MESSAGE_DATA_PROPERTY = "d";
|
private const string MESSAGE_DATA_PROPERTY = "d";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the data as a DateTime value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DateTime ParseDateTime(string data)
|
||||||
|
{
|
||||||
|
return DateTime.ParseExact(data, DATE_FORMAT, CultureInfo.CurrentCulture);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the token as a DateTime value.
|
/// Gets the token as a DateTime value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,7 +44,7 @@ namespace ICD.Common.Utils.Json
|
|||||||
throw new ArgumentNullException("token");
|
throw new ArgumentNullException("token");
|
||||||
|
|
||||||
#if SIMPLSHARP
|
#if SIMPLSHARP
|
||||||
return DateTime.ParseExact((string)token, DATE_FORMAT, CultureInfo.CurrentCulture);
|
return ParseDateTime((string)token);
|
||||||
#else
|
#else
|
||||||
return (DateTime)token;
|
return (DateTime)token;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user