private long GetDaysDiff(ProjectHistoryEntry empl1, ProjectHistoryEntry empl2) { // Get the total number of days that the employees worked together. // Calculates correctly even for leap years. var startCommonDate = new DateTime(Math.Max(empl1.StartDate.Ticks, empl2.StartDate.Ticks)); var endCommonDate = new DateTime(Math.Min(empl1.EndDate.Ticks, empl2.EndDate.Ticks)); // 1 is added because we need to include the end day. E.g. 10 April to 11 April means people worked together 2 days long daysDiff = (endCommonDate - startCommonDate).Days + 1; return(daysDiff); }
private bool AreDatesOverlapping(ProjectHistoryEntry first, ProjectHistoryEntry second) { return(first.StartDate < second.EndDate && first.EndDate > second.StartDate); }