mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
Merge remote-tracking branch 'origin/MetLife_v5.4' into Telemetry
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
@@ -16,9 +15,6 @@ namespace ICD.Common.Utils.Json
|
|||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static class JsonUtils
|
public static class JsonUtils
|
||||||
{
|
{
|
||||||
// 2016-02-26T19:24:59
|
|
||||||
private const string DATE_FORMAT = @"yyyy-MM-dd\THH:mm:ss";
|
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
@@ -44,6 +40,16 @@ namespace ICD.Common.Utils.Json
|
|||||||
JsonConvert.DeserializeObject(serialized, type);
|
JsonConvert.DeserializeObject(serialized, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the data as a DateTime value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DateTime ParseDateTime(string data)
|
||||||
|
{
|
||||||
|
return DateTime.Parse(data);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the token as a DateTime value.
|
/// Gets the token as a DateTime value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -55,11 +61,7 @@ namespace ICD.Common.Utils.Json
|
|||||||
if (token == null)
|
if (token == null)
|
||||||
throw new ArgumentNullException("token");
|
throw new ArgumentNullException("token");
|
||||||
|
|
||||||
#if SIMPLSHARP
|
return ParseDateTime((string)token);
|
||||||
return DateTime.ParseExact((string)token, DATE_FORMAT, CultureInfo.CurrentCulture);
|
|
||||||
#else
|
|
||||||
return (DateTime)token;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -81,6 +83,10 @@ namespace ICD.Common.Utils.Json
|
|||||||
output = ParseDateTime(token);
|
output = ParseDateTime(token);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
catch (FormatException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
catch (InvalidCastException)
|
catch (InvalidCastException)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user