fix: Using UTC for tracking durations

This commit is contained in:
Chris Cameron
2020-03-11 13:02:34 -04:00
parent ed2cf84a7e
commit e99a7f313f
4 changed files with 14 additions and 13 deletions

View File

@@ -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 - Simplifying ANSI color methods, better cross-platform color support
- Console uses unicode for table drawing on Net Standard - Console uses unicode for table drawing on Net Standard
- Using UTC for tracking scheduled events, fixes issues with DST - Using UTC for tracking scheduled events, fixes issues with DST
- Using UTC for tracking durations
## [10.3.0] - 2020-01-20 ## [10.3.0] - 2020-01-20
### Changed ### Changed

View File

@@ -21,8 +21,8 @@ namespace ICD.Common.Utils
private static string s_VersionResult; private static string s_VersionResult;
private static DateTime? s_SystemUptimeStartTime; private static DateTime? s_SystemUptimeStartTimeUtc;
private static DateTime? s_ProgramUptimeStartTime; private static DateTime? s_ProgramUptimeStartTimeUtc;
#region Properties #region Properties
@@ -237,7 +237,7 @@ namespace ICD.Common.Utils
[PublicAPI] [PublicAPI]
public static TimeSpan GetSystemUptime() public static TimeSpan GetSystemUptime()
{ {
if (s_SystemUptimeStartTime == null) if (s_SystemUptimeStartTimeUtc == null)
{ {
string uptime = GetSystemUptimeFeedback(); string uptime = GetSystemUptimeFeedback();
Match match = Regex.Match(uptime, UPTIME_REGEX); Match match = Regex.Match(uptime, UPTIME_REGEX);
@@ -251,10 +251,10 @@ namespace ICD.Common.Utils
int milliseconds = int.Parse(match.Groups["milliseconds"].Value); int milliseconds = int.Parse(match.Groups["milliseconds"].Value);
TimeSpan span = new TimeSpan(days, hours, minutes, seconds, milliseconds); 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;
} }
/// <summary> /// <summary>
@@ -264,7 +264,7 @@ namespace ICD.Common.Utils
[PublicAPI] [PublicAPI]
public static TimeSpan GetProgramUptime() public static TimeSpan GetProgramUptime()
{ {
if (s_ProgramUptimeStartTime == null) if (s_ProgramUptimeStartTimeUtc == null)
{ {
string uptime = GetProgramUptimeFeedback((int)ProgramUtils.ProgramNumber); string uptime = GetProgramUptimeFeedback((int)ProgramUtils.ProgramNumber);
Match match = Regex.Match(uptime, UPTIME_REGEX); Match match = Regex.Match(uptime, UPTIME_REGEX);
@@ -278,10 +278,10 @@ namespace ICD.Common.Utils
int milliseconds = int.Parse(match.Groups["milliseconds"].Value); int milliseconds = int.Parse(match.Groups["milliseconds"].Value);
TimeSpan span = new TimeSpan(days, hours, minutes, seconds, milliseconds); 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 #endregion

View File

@@ -43,7 +43,7 @@ namespace ICD.Common.Utils.Services.Logging
{ {
m_Severity = severity; m_Severity = severity;
m_Message = message; m_Message = message;
m_Timestamp = IcdEnvironment.GetLocalTime().ToUniversalTime(); m_Timestamp = IcdEnvironment.GetUtcTime();
} }
#endregion #endregion

View File

@@ -41,11 +41,11 @@ namespace ICD.Common.Utils
if (condition == null) if (condition == null)
throw new ArgumentNullException("condition"); throw new ArgumentNullException("condition");
DateTime end = IcdEnvironment.GetLocalTime().AddMilliseconds(timeout); DateTime end = IcdEnvironment.GetUtcTime().AddMilliseconds(timeout);
while (!condition()) while (!condition())
{ {
if (IcdEnvironment.GetLocalTime() >= end) if (IcdEnvironment.GetUtcTime() >= end)
return false; return false;
} }
@@ -137,7 +137,7 @@ namespace ICD.Common.Utils
{ {
try try
{ {
state.Started = IcdEnvironment.GetLocalTime(); state.Started = IcdEnvironment.GetUtcTime();
callback(param); callback(param);
RemoveThreadState(state); RemoveThreadState(state);
@@ -190,7 +190,7 @@ namespace ICD.Common.Utils
/// <summary> /// <summary>
/// Gets the duration of the thread. /// Gets the duration of the thread.
/// </summary> /// </summary>
public TimeSpan? Duration { get { return IcdEnvironment.GetLocalTime() - Started; } } public TimeSpan? Duration { get { return IcdEnvironment.GetUtcTime() - Started; } }
/// <summary> /// <summary>
/// Threads can be garbage collected before they execute so we keep a reference. /// Threads can be garbage collected before they execute so we keep a reference.