mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-12 11:15:12 +00:00
feat: timer rescheduling, abstract scheduled action, datetime and dayofweek extensions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user