feat: timer rescheduling, abstract scheduled action, datetime and dayofweek extensions

This commit is contained in:
Jeffery Thompson
2018-07-12 13:33:02 -04:00
parent 928f8e5e04
commit 465ac7c42c
6 changed files with 123 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.Linq;
namespace ICD.Common.Utils.Extensions
{
@@ -28,5 +29,22 @@ namespace ICD.Common.Utils.Extensions
// Todo - Better handle different cultures
return extends.ToString("HH:mm:ss:fff");
}
/// <summary>
/// Returns the closest DateTime to the target time that is greater than the target time
/// </summary>
/// <param name="target"></param>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static DateTime? NextEarliestTime(this DateTime target, params DateTime[] times)
{
if (times.Length == 0)
return null;
DateTime[] orderedTimes = times.OrderBy(dt => dt).ToArray();
var time = orderedTimes.FirstOrDefault(dt => target < dt);
return time == default(DateTime) ? (DateTime?) null : time;
}
}
}