mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
fix: Fixing format exception when parsing JSON DateTime with timezone info
This commit is contained in:
@@ -18,7 +18,11 @@ namespace ICD.Common.Utils.Tests.Json
|
|||||||
[Test]
|
[Test]
|
||||||
public void ParseDateTimeTest()
|
public void ParseDateTimeTest()
|
||||||
{
|
{
|
||||||
Assert.Inconclusive();
|
const string dataA = "2016-02-26T19:24:59";
|
||||||
|
const string dataB = "2019-04-01T12:41:15-04:00";
|
||||||
|
|
||||||
|
Assert.DoesNotThrow(() => JsonUtils.ParseDateTime(dataA));
|
||||||
|
Assert.DoesNotThrow(() => JsonUtils.ParseDateTime(dataB));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|||||||
@@ -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";
|
||||||
|
|
||||||
@@ -29,7 +25,7 @@ namespace ICD.Common.Utils.Json
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static DateTime ParseDateTime(string data)
|
public static DateTime ParseDateTime(string data)
|
||||||
{
|
{
|
||||||
return DateTime.ParseExact(data, DATE_FORMAT, CultureInfo.CurrentCulture);
|
return DateTime.Parse(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -43,11 +39,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 ParseDateTime((string)token);
|
||||||
#else
|
|
||||||
return (DateTime)token;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user