mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 05:05:05 +00:00
feat: Better handling of JSON DateTimes in Net Standard
This commit is contained in:
@@ -5,7 +5,6 @@ using ICD.Common.Properties;
|
||||
using ICD.Common.Utils.Extensions;
|
||||
using ICD.Common.Utils.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ICD.Common.Utils.Json
|
||||
{
|
||||
@@ -18,63 +17,6 @@ namespace ICD.Common.Utils.Json
|
||||
private const string MESSAGE_NAME_PROPERTY = "m";
|
||||
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.Parse(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the token as a DateTime value.
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static DateTime ParseDateTime(JToken token)
|
||||
{
|
||||
if (token == null)
|
||||
throw new ArgumentNullException("token");
|
||||
|
||||
#if SIMPLSHARP
|
||||
return ParseDateTime((string)token);
|
||||
#else
|
||||
return (DateTime)token;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the token as a DateTime value.
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <param name="output"></param>
|
||||
/// <returns></returns>
|
||||
[PublicAPI]
|
||||
public static bool TryParseDateTime(JToken token, out DateTime output)
|
||||
{
|
||||
if (token == null)
|
||||
throw new ArgumentNullException("token");
|
||||
|
||||
output = default(DateTime);
|
||||
|
||||
try
|
||||
{
|
||||
output = ParseDateTime(token);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serializes the given item and formats the JSON into a human-readable form.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user