diff --git a/CHANGELOG.md b/CHANGELOG.md index 0920713..d5d9606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a bug where color formatted console output on Net Standard was not raising the OnConsolePrint event - 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 ## [10.3.0] - 2020-01-20 ### Changed diff --git a/ICD.Common.Utils/Services/Scheduler/AbstractScheduledAction.cs b/ICD.Common.Utils/Services/Scheduler/AbstractScheduledAction.cs index 891d06c..bcfc6fd 100644 --- a/ICD.Common.Utils/Services/Scheduler/AbstractScheduledAction.cs +++ b/ICD.Common.Utils/Services/Scheduler/AbstractScheduledAction.cs @@ -7,17 +7,17 @@ namespace ICD.Common.Utils.Services.Scheduler { public event EventHandler OnScheduledRunTimeChanged; - private DateTime? m_NextRunTime; + private DateTime? m_NextRunTimeUtc; - public DateTime? NextRunTime + public DateTime? NextRunTimeUtc { - get { return m_NextRunTime; } + get { return m_NextRunTimeUtc; } private set { - if (m_NextRunTime == value) + if (m_NextRunTimeUtc == value) return; - m_NextRunTime = value; + m_NextRunTimeUtc = value; OnScheduledRunTimeChanged.Raise(this); } @@ -26,12 +26,12 @@ namespace ICD.Common.Utils.Services.Scheduler public void Run() { RunFinal(); - NextRunTime = GetNextRunTime(); + NextRunTimeUtc = GetNextRunTimeUtc(); } public void UpdateNextRunTime() { - NextRunTime = GetNextRunTime(); + NextRunTimeUtc = GetNextRunTimeUtc(); } /// @@ -42,6 +42,6 @@ namespace ICD.Common.Utils.Services.Scheduler /// /// Runs after RunFinal in order to set the next run time of this action /// - public abstract DateTime? GetNextRunTime(); + public abstract DateTime? GetNextRunTimeUtc(); } } \ No newline at end of file diff --git a/ICD.Common.Utils/Services/Scheduler/ActionSchedulerService.cs b/ICD.Common.Utils/Services/Scheduler/ActionSchedulerService.cs index 33b0b2e..868eee1 100644 --- a/ICD.Common.Utils/Services/Scheduler/ActionSchedulerService.cs +++ b/ICD.Common.Utils/Services/Scheduler/ActionSchedulerService.cs @@ -39,7 +39,7 @@ namespace ICD.Common.Utils.Services.Scheduler try { Subscribe(action); - m_Actions.InsertSorted(action, a => a.NextRunTime); + m_Actions.InsertSorted(action, a => a.NextRunTimeUtc); } finally { @@ -96,15 +96,15 @@ namespace ICD.Common.Utils.Services.Scheduler private void TimerCallback() { - DateTime currentTime = IcdEnvironment.GetLocalTime(); + DateTime currentTime = IcdEnvironment.GetUtcTime(); IScheduledAction[] actionsToRun; m_CriticalSection.Enter(); try { actionsToRun = m_Actions - .Where(a => a.NextRunTime <= currentTime && a.NextRunTime > m_LastRunTime) - .OrderBy(a => a.NextRunTime) + .Where(a => a.NextRunTimeUtc <= currentTime && a.NextRunTimeUtc > m_LastRunTime) + .OrderBy(a => a.NextRunTimeUtc) .ToArray(); } finally @@ -135,14 +135,14 @@ namespace ICD.Common.Utils.Services.Scheduler m_CriticalSection.Enter(); try { - var action = m_Actions.FirstOrDefault(a => a.NextRunTime != null && a.NextRunTime > m_LastRunTime); - if (action == null || action.NextRunTime == null) + var action = m_Actions.FirstOrDefault(a => a.NextRunTimeUtc != null && a.NextRunTimeUtc > m_LastRunTime); + if (action == null || action.NextRunTimeUtc == null) { m_Timer.Stop(); return; } - long msToNextAction = (long)(action.NextRunTime.Value - IcdEnvironment.GetLocalTime()).TotalMilliseconds; + long msToNextAction = (long)(action.NextRunTimeUtc.Value - IcdEnvironment.GetUtcTime()).TotalMilliseconds; if (msToNextAction < 0) msToNextAction = 0; m_Timer.Reset(msToNextAction); @@ -195,7 +195,7 @@ namespace ICD.Common.Utils.Services.Scheduler try { m_Actions.Remove(action); - m_Actions.InsertSorted(action, a => a.NextRunTime); + m_Actions.InsertSorted(action, a => a.NextRunTimeUtc); } finally { diff --git a/ICD.Common.Utils/Services/Scheduler/IScheduledAction.cs b/ICD.Common.Utils/Services/Scheduler/IScheduledAction.cs index 16753b9..9254c0e 100644 --- a/ICD.Common.Utils/Services/Scheduler/IScheduledAction.cs +++ b/ICD.Common.Utils/Services/Scheduler/IScheduledAction.cs @@ -12,7 +12,7 @@ namespace ICD.Common.Utils.Services.Scheduler /// /// Gets the next time this action should be run /// - DateTime? NextRunTime { get; } + DateTime? NextRunTimeUtc { get; } void Run(); }