public void CombineNonOverlappingWorks() { DateRange range1 = (Date(1), Date(5)); DateRange range3 = (Date(7), Date(8)); range1.Combine(range3).ShouldBe((range1, range3)); range3.Combine(range1).ShouldBe((range3, range1)); }
public void CombineSameWorks() { DateRange range1 = (Date(1), Date(5)); DateRange range2 = (Date(1), Date(5)); var(actualResult, nullResult) = range1.Combine(range2); actualResult.ShouldBe(range1); nullResult.ShouldBeNull(); }
public void CombineMultipleWorks() { var start = Date(1); var end = Date(5); DateRange range1 = (start, Date(3)); DateRange range2 = (Date(2), end); DateRange range3 = (Date(7), Date(8)); DateRange.Combine(new[] { range1, range2, range3 }) .ShouldBe(new[] { new DateRange(start, end), range3 }); }
public void CombineOverlappingWorks() { var expectedStart = Date(1); var expectedEnd = Date(5); DateRange range1 = (expectedStart, Date(3)); DateRange range2 = (Date(2), expectedEnd); var(actualResult, nullResult) = range1.Combine(range2); actualResult.ShouldBe(new DateRange(expectedStart, expectedEnd)); nullResult.ShouldBeNull(); }
public static TimeSpan ServiceLength(IEnumerable <PersonRole> validRoles, int schoolYear) { var totalServiceTime = TimeSpan.Zero; var ranges = validRoles.Select(role => { var startDate = role.StartDate; var endDate = role.Active ? schoolYear.EndOfSchoolYear() : role.EndDate ?? throw new ArgumentException("unknown end date for role:" + role.Id); return(new DateRange(startDate, endDate)); }); ranges = DateRange.Combine(ranges); foreach (var dateRange in ranges) { totalServiceTime += dateRange.Length; } return(totalServiceTime); }