Exemple #1
0
        public void test_compare_ranges2()
        {
            CompleteDateRange range_full_2015 = new CompleteDateRange(new CompleteDate(2015, 1, 1), new CompleteDate(2015, 12, 31));
            CompleteDateRange range_late_2014 = new CompleteDateRange(new CompleteDate(2014, 12, 30), new CompleteDate(2014, 12, 31));

            Assert.False(range_full_2015.Overlaps(range_late_2014));
        }
Exemple #2
0
        /// <summary>
        ///   x--------x
        /// x----x
        ///
        ///   x---------x
        ///         x------x
        ///
        ///   x----------x
        ///       x----x
        ///
        ///    x-----x
        /// x-----------x
        ///
        /// 4 checks needed -> if any point is within the other ranges endpoints, an overlap occurs.
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        public bool Overlaps(CompleteDateRange range)
        {
            //d1 start
            if (range.DateStart.Sortable <= this.DateStart.Sortable && this.DateStart.Sortable <= range.DateEnd.Sortable)
            {
                return(true);
            }

            //d1 end
            if (range.DateStart.Sortable <= this.DateEnd.Sortable && this.DateEnd.Sortable <= range.DateEnd.Sortable)
            {
                return(true);
            }

            //d2 start
            if (this.DateStart.Sortable <= range.DateStart.Sortable && range.DateStart.Sortable <= this.DateEnd.Sortable)
            {
                return(true);
            }

            //d2 end
            if (this.DateStart.Sortable <= range.DateEnd.Sortable && range.DateEnd.Sortable <= this.DateEnd.Sortable)
            {
                return(true);
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Convert to Complete date ranges. The complete date ranges might reoccur once, monthly or yearly.
        /// </summary>
        /// <param name="yearStart"></param>
        /// <param name="yearEnd"></param>
        /// <returns></returns>
        public CompleteDateRange[] ToCompleteDateRanges(int yearStart, int yearEnd)
        {
            var periodOfInterest = new CompleteDateRange(new CompleteDate(yearStart, 1, 1), new CompleteDate(yearEnd, 12, 31));

            CompleteDate completeStart, completeEnd;
            var          count          = 1;
            var          completeRanges = new CompleteDateRange[count];

            switch (this.dateStart.TruncationType)
            {
            case 4:
            case 6:
            case 7:
                //only one period
                completeStart = dateStart.MakeCompleteUsing(new CompleteDate(yearStart, 1, 1));
                completeEnd   = dateEnd.MakeCompleteUsing(new CompleteDate(yearEnd, 12, 31));
                //max range is start of first occurence and end of last
                completeRanges[0] = new CompleteDateRange(completeStart, completeEnd);
                return(completeRanges[0].Overlaps(periodOfInterest) ? completeRanges : null);

            case 1:
            case 5:
                //one period each month ( month missing )
                //TODO Monthly period not implemented!
                throw new NotImplementedException("TruncatedDateRange.cs line 74");
                return(null);

            case 2:
            case 3:
                //yearly period
                count          = yearEnd - yearStart + 1;
                completeRanges = new CompleteDateRange[count];

                for (var i = 0; i < count; i++)
                {
                    completeStart     = dateStart.MakeCompleteUsing(new CompleteDate(yearStart + i, 1, 1));
                    completeEnd       = dateEnd.MakeCompleteUsing(new CompleteDate(yearStart + i, 12, 31));
                    completeRanges[i] = new CompleteDateRange(completeStart, completeEnd);
                }

                return(completeRanges);
            }

            return(null);
        }