diff --git a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs index 77f0b14..8a95078 100644 --- a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs +++ b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs @@ -46,5 +46,22 @@ namespace ICD.Common.Utils.Extensions var time = orderedTimes.FirstOrDefault(dt => target < dt); return time == default(DateTime) ? (DateTime?) null : time; } + + /// + /// Returns the closest DateTime to the target time that is less than the target time + /// + /// + /// + /// + /// + public static DateTime? PreviousLatestTime(this DateTime target, params DateTime[] times) + { + if (times.Length == 0) + return null; + + DateTime[] orderedTimes = times.OrderByDescending(dt => dt).ToArray(); + var time = orderedTimes.FirstOrDefault(dt => target > dt); + return time == default(DateTime) ? (DateTime?) null : time; + } } }