Exemplo n.º 1
0
        public List <DateTime> GetAllDates(DateTime toDate)
        {
            if (cachedDates.ContainsKey(toDate))
            {
                return(cachedDates[toDate]);
            }

            HashSet <DateTime> dates = new HashSet <DateTime>();

            int      repeats      = 1;
            DateTime iterator     = StartDate;
            DateTime adjustedDate = BusinessDayCalculator.GetCalculatedBusinessDay(iterator, this.BusinessDayCalculation);

            while (!IsCompleted(repeats, adjustedDate, toDate))
            {
                dates.Add(adjustedDate);

                iterator = GetNextDate(repeats, iterator);

                adjustedDate = BusinessDayCalculator.GetCalculatedBusinessDay(iterator, this.BusinessDayCalculation);

                repeats++;
            }

            foreach (ScheduleDate includeDate in this.IncludeDates)
            {
                if (!dates.Contains(includeDate.Value))
                {
                    dates.Add(includeDate.Value);
                }
            }

            foreach (ScheduleDate excludeDate in this.ExcludeDates)
            {
                if (dates.Contains(excludeDate.Value))
                {
                    dates.Remove(excludeDate.Value);
                }
            }

            List <DateTime> sortedDates = dates.OrderBy(d => d).ToList();

            cachedDates[toDate] = sortedDates;

            return(sortedDates);
        }
Exemplo n.º 2
0
        public void SuccessAnyDayNoAdjustment()
        {
            BusinessDayCalculator calendar = TestUtility.CreateEuroZoneCalendar();

            DateTime nextDay = calendar.GetCalculatedBusinessDay(new DateTime(2024, 3, 30), BusinessDayCalculation.AnyDay);

            Assert.AreEqual(new DateTime(2024, 3, 30), nextDay);
        }
Exemplo n.º 3
0
        public void SuccessPreviousBusinessDaySkipWeekend()
        {
            BusinessDayCalculator calendar = TestUtility.CreateEuroZoneCalendar();

            //3 Jan is Sunday, therefore previous working day Monday 31st Dec 2020
            DateTime previousDay = calendar.GetCalculatedBusinessDay(new DateTime(2021, 1, 3), BusinessDayCalculation.PreviousBusinessDay);

            Assert.AreEqual(new DateTime(2020, 12, 31), previousDay);
        }
Exemplo n.º 4
0
        public void SuccessNextBusinessDaySkipWeekend()
        {
            BusinessDayCalculator calendar = TestUtility.CreateEuroZoneCalendar();

            //1 Jan is Friday, therefore next working day Monday 4th Jan 2021
            DateTime nextDay = calendar.GetCalculatedBusinessDay(new DateTime(2021, 1, 1), BusinessDayCalculation.NextBusinessDay);

            Assert.AreEqual(new DateTime(2021, 1, 4), nextDay);
        }
Exemplo n.º 5
0
        public void SuccessNextBusinessDayThisMonthOrPrevious()
        {
            BusinessDayCalculator calendar = TestUtility.CreateEuroZoneCalendar();

            //March 29th 2024 is Good Friday. Next working day is on Tuesday 2nd,
            //Therefore previous working day should be selected (28th March 2024)
            DateTime nextDay = calendar.GetCalculatedBusinessDay(new DateTime(2024, 3, 29), BusinessDayCalculation.NextBusinessDayThisMonthOrPrevious);

            Assert.AreEqual(new DateTime(2024, 3, 28), nextDay);
        }
Exemplo n.º 6
0
        public void SuccessClosestOrNext()
        {
            BusinessDayCalculator calendar = TestUtility.CreateEuroZoneCalendar();

            //31 Dec W | 1 Jan N | 2 Jan N | 3 Jan N | 4 Jan W
            //For 2 Jan both 31 Dec and 4 Jan are same distance, hence 4 Jan as next shoud be selected
            DateTime nextDay = calendar.GetCalculatedBusinessDay(new DateTime(2021, 1, 2), BusinessDayCalculation.ClosestBusinessDayOrNext);

            Assert.AreEqual(new DateTime(2021, 1, 4), nextDay);
        }
Exemplo n.º 7
0
        public virtual IEnumerable <DateTime> GetAllDates(DateTime toDate)
        {
            if (_cachedDates.ContainsKey(toDate))
            {
                return(_cachedDates[toDate]);
            }

            List <DateTime> dates = new List <DateTime>();

            int      repeats      = 1;
            var      iterator     = StartDate;
            DateTime adjustedDate = BusinessDayCalculator.GetCalculatedBusinessDay(iterator, this.BusinessDayCalculation);

            while (!IsCompleted(repeats, adjustedDate, toDate))
            {
                dates.Add(adjustedDate);

                iterator = GetNextDate(repeats, iterator);

                adjustedDate = BusinessDayCalculator.GetCalculatedBusinessDay(iterator, this.BusinessDayCalculation);

                repeats++;
            }


            dates.AddRange(from d in this.IncludeDates
                           select d.Value);


            foreach (var excludeDate in this.ExcludeDates)
            {
                dates.Remove(excludeDate.Value);
            }

            dates.Sort();

            _cachedDates[toDate] = dates;

            return(dates);
        }