예제 #1
0
        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));
        }
예제 #2
0
        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();
        }
예제 #3
0
        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 });
        }
예제 #4
0
        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();
        }
예제 #5
0
        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);
        }