From f7dba764d57feae1c94fe7690b477883c43a6855 Mon Sep 17 00:00:00 2001 From: Jeffery Thompson Date: Fri, 13 Jul 2018 16:25:13 -0400 Subject: [PATCH] feat: add parameter to extensions for inclusivity --- ICD.Common.Utils/Extensions/DateTimeExtensions.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs index 3fe9e92..bb32197 100644 --- a/ICD.Common.Utils/Extensions/DateTimeExtensions.cs +++ b/ICD.Common.Utils/Extensions/DateTimeExtensions.cs @@ -34,15 +34,16 @@ namespace ICD.Common.Utils.Extensions /// Returns the closest DateTime to the target time that is greater than the target time /// /// + /// Whether or not to include times equal to the target time /// /// - public static DateTime? NextEarliestTime(this DateTime target, params DateTime[] times) + public static DateTime? NextEarliestTime(this DateTime target, bool inclusive, params DateTime[] times) { if (times == null) throw new ArgumentNullException("times"); DateTime earliestTime; - bool success = times.OrderBy(dt => dt).TryFirst(dt => target < dt, out earliestTime); + bool success = times.OrderBy(dt => dt).TryFirst(dt => inclusive ? target <= dt : target < dt, out earliestTime); return success ? earliestTime : (DateTime?) null; } @@ -50,15 +51,16 @@ namespace ICD.Common.Utils.Extensions /// Returns the closest DateTime to the target time that is less than the target time /// /// + /// Whether or not to include times equal to the target time /// /// - public static DateTime? PreviousLatestTime(this DateTime target, params DateTime[] times) + public static DateTime? PreviousLatestTime(this DateTime target, bool inclusive, params DateTime[] times) { if (times == null) throw new ArgumentNullException("null"); DateTime latestTime; - bool success = times.OrderByDescending(dt => dt).TryFirst(dt => target > dt, out latestTime); + bool success = times.OrderByDescending(dt => dt).TryFirst(dt => inclusive ? target >= dt : target > dt, out latestTime); return success ? latestTime : (DateTime?) null; } }