From e99a7f313f0701a4e8defaf40d66ef55f6de75e0 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Wed, 11 Mar 2020 13:02:34 -0400 Subject: [PATCH] fix: Using UTC for tracking durations --- CHANGELOG.md | 1 + ICD.Common.Utils/ProcessorUtils.SimplSharp.cs | 16 ++++++++-------- ICD.Common.Utils/Services/Logging/LogItem.cs | 2 +- ICD.Common.Utils/ThreadingUtils.cs | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5d9606..40c6ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Simplifying ANSI color methods, better cross-platform color support - Console uses unicode for table drawing on Net Standard - Using UTC for tracking scheduled events, fixes issues with DST + - Using UTC for tracking durations ## [10.3.0] - 2020-01-20 ### Changed diff --git a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs index 8a09ee7..2f84851 100644 --- a/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs +++ b/ICD.Common.Utils/ProcessorUtils.SimplSharp.cs @@ -21,8 +21,8 @@ namespace ICD.Common.Utils private static string s_VersionResult; - private static DateTime? s_SystemUptimeStartTime; - private static DateTime? s_ProgramUptimeStartTime; + private static DateTime? s_SystemUptimeStartTimeUtc; + private static DateTime? s_ProgramUptimeStartTimeUtc; #region Properties @@ -237,7 +237,7 @@ namespace ICD.Common.Utils [PublicAPI] public static TimeSpan GetSystemUptime() { - if (s_SystemUptimeStartTime == null) + if (s_SystemUptimeStartTimeUtc == null) { string uptime = GetSystemUptimeFeedback(); Match match = Regex.Match(uptime, UPTIME_REGEX); @@ -251,10 +251,10 @@ namespace ICD.Common.Utils int milliseconds = int.Parse(match.Groups["milliseconds"].Value); TimeSpan span = new TimeSpan(days, hours, minutes, seconds, milliseconds); - s_SystemUptimeStartTime = IcdEnvironment.GetLocalTime() - span; + s_SystemUptimeStartTimeUtc = IcdEnvironment.GetUtcTime() - span; } - return IcdEnvironment.GetLocalTime() - s_SystemUptimeStartTime.Value; + return IcdEnvironment.GetUtcTime() - s_SystemUptimeStartTimeUtc.Value; } /// @@ -264,7 +264,7 @@ namespace ICD.Common.Utils [PublicAPI] public static TimeSpan GetProgramUptime() { - if (s_ProgramUptimeStartTime == null) + if (s_ProgramUptimeStartTimeUtc == null) { string uptime = GetProgramUptimeFeedback((int)ProgramUtils.ProgramNumber); Match match = Regex.Match(uptime, UPTIME_REGEX); @@ -278,10 +278,10 @@ namespace ICD.Common.Utils int milliseconds = int.Parse(match.Groups["milliseconds"].Value); TimeSpan span = new TimeSpan(days, hours, minutes, seconds, milliseconds); - s_ProgramUptimeStartTime = IcdEnvironment.GetLocalTime() - span; + s_ProgramUptimeStartTimeUtc = IcdEnvironment.GetUtcTime() - span; } - return IcdEnvironment.GetLocalTime() - s_ProgramUptimeStartTime.Value; + return IcdEnvironment.GetUtcTime() - s_ProgramUptimeStartTimeUtc.Value; } #endregion diff --git a/ICD.Common.Utils/Services/Logging/LogItem.cs b/ICD.Common.Utils/Services/Logging/LogItem.cs index fe45131..0d217a1 100644 --- a/ICD.Common.Utils/Services/Logging/LogItem.cs +++ b/ICD.Common.Utils/Services/Logging/LogItem.cs @@ -43,7 +43,7 @@ namespace ICD.Common.Utils.Services.Logging { m_Severity = severity; m_Message = message; - m_Timestamp = IcdEnvironment.GetLocalTime().ToUniversalTime(); + m_Timestamp = IcdEnvironment.GetUtcTime(); } #endregion diff --git a/ICD.Common.Utils/ThreadingUtils.cs b/ICD.Common.Utils/ThreadingUtils.cs index 51a72af..55645b7 100644 --- a/ICD.Common.Utils/ThreadingUtils.cs +++ b/ICD.Common.Utils/ThreadingUtils.cs @@ -41,11 +41,11 @@ namespace ICD.Common.Utils if (condition == null) throw new ArgumentNullException("condition"); - DateTime end = IcdEnvironment.GetLocalTime().AddMilliseconds(timeout); + DateTime end = IcdEnvironment.GetUtcTime().AddMilliseconds(timeout); while (!condition()) { - if (IcdEnvironment.GetLocalTime() >= end) + if (IcdEnvironment.GetUtcTime() >= end) return false; } @@ -137,7 +137,7 @@ namespace ICD.Common.Utils { try { - state.Started = IcdEnvironment.GetLocalTime(); + state.Started = IcdEnvironment.GetUtcTime(); callback(param); RemoveThreadState(state); @@ -190,7 +190,7 @@ namespace ICD.Common.Utils /// /// Gets the duration of the thread. /// - public TimeSpan? Duration { get { return IcdEnvironment.GetLocalTime() - Started; } } + public TimeSpan? Duration { get { return IcdEnvironment.GetUtcTime() - Started; } } /// /// Threads can be garbage collected before they execute so we keep a reference.