From 5756d9654b9fa6f2bf95fbdc7c7528bab50ec725 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 3 Apr 2019 16:19:53 -0400 Subject: [PATCH 1/2] fix: Fixing FormatException when parsing some JSON DateTimes --- ICD.Common.Utils/Json/JsonUtils.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/ICD.Common.Utils/Json/JsonUtils.cs b/ICD.Common.Utils/Json/JsonUtils.cs index 56270bb..e6e6d9d 100644 --- a/ICD.Common.Utils/Json/JsonUtils.cs +++ b/ICD.Common.Utils/Json/JsonUtils.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; using System.Linq; using System.Text; using ICD.Common.Properties; @@ -16,9 +15,6 @@ namespace ICD.Common.Utils.Json [PublicAPI] 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_DATA_PROPERTY = "d"; @@ -44,6 +40,16 @@ namespace ICD.Common.Utils.Json JsonConvert.DeserializeObject(serialized, type); } + /// + /// Gets the data as a DateTime value. + /// + /// + /// + public static DateTime ParseDateTime(string data) + { + return DateTime.Parse(data); + } + /// /// Gets the token as a DateTime value. /// @@ -55,11 +61,7 @@ namespace ICD.Common.Utils.Json if (token == null) throw new ArgumentNullException("token"); -#if SIMPLSHARP - return DateTime.ParseExact((string)token, DATE_FORMAT, CultureInfo.CurrentCulture); -#else - return (DateTime)token; -#endif + return ParseDateTime((string)token); } /// @@ -81,6 +83,10 @@ namespace ICD.Common.Utils.Json output = ParseDateTime(token); return true; } + catch (FormatException) + { + return false; + } catch (InvalidCastException) { return false; From 736c2aee3332547b3f03c85ac491b49af0cd45c7 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Fri, 5 Apr 2019 14:29:44 -0400 Subject: [PATCH 2/2] chore: Updating changelog, incrementing patch version --- CHANGELOG.md | 4 ++++ ICD.Common.Utils/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5adbe94..805e241 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [8.3.1] - 2019-04-05 +### Changed + - Fixed FormatException when parsing some JSON DateTimes + ## [8.3.0] - 2019-01-25 ### Added - Added SimplSharpProMono to eRuntimeEnvironment enum diff --git a/ICD.Common.Utils/Properties/AssemblyInfo.cs b/ICD.Common.Utils/Properties/AssemblyInfo.cs index 6df4043..a70fc82 100644 --- a/ICD.Common.Utils/Properties/AssemblyInfo.cs +++ b/ICD.Common.Utils/Properties/AssemblyInfo.cs @@ -3,5 +3,5 @@ using System.Reflection; [assembly: AssemblyTitle("ICD.Common.Utils")] [assembly: AssemblyCompany("ICD Systems")] [assembly: AssemblyProduct("ICD.Common.Utils")] -[assembly: AssemblyCopyright("Copyright © ICD Systems 2018")] -[assembly: AssemblyVersion("8.3.0.0")] +[assembly: AssemblyCopyright("Copyright © ICD Systems 2019")] +[assembly: AssemblyVersion("8.3.1.0")]