mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 13:45:05 +00:00
feat : added a StartofDay and EndofDay DateTime methods.
This commit is contained in:
@@ -63,5 +63,25 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
bool success = times.OrderByDescending(dt => dt).TryFirst(dt => inclusive ? target >= 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;
|
return success ? latestTime : (DateTime?) null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the DateTime representing the very start of the current day.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DateTime StartOfDay(this DateTime extends)
|
||||||
|
{
|
||||||
|
return new DateTime(extends.Year, extends.Month, extends.Day, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the DateTime representing the very end of the current day.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DateTime EndOfDay(this DateTime extends)
|
||||||
|
{
|
||||||
|
return extends.StartOfDay() + new TimeSpan(24, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user