示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CalendarOperationProvider"/> class.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="timeUnit">The time unit.</param>
        public CalendarOperationProvider(ICalendar <ICalendarDay> calendar, CalendarTimeUnit timeUnit)
        {
            _calendar = calendar;
            var factory = ClassFactory.Get <CalendarCountTermFactory>();

            _countTerm = factory.GetCountTerm(timeUnit);
        }
示例#2
0
        public DateTime Add(DateTime dateTime, CalendarTimeUnit timeUnit, int value)
        {
            if (value <= 0)
            {
                return(dateTime);
            }
            var           factory           = ClassFactory.Get <CalendarCountTermFactory>();
            BaseCountTerm countTerm         = factory.GetCountTerm(timeUnit);
            IEnumerable <ICalendarDay> days = GetDays(countTerm, dateTime, value);

            return(countTerm.Calculate(days, value));
        }
示例#3
0
        protected IEnumerable <ICalendarDay> GetDays(BaseCountTerm countTerm, DateTime dateTime, int value)
        {
            int weeksCount = countTerm.GetWeeksCount(_calendar.WeekTemplate, value);
            IEnumerable <ICalendarDay> days = GenerateWeeks(dateTime, weeksCount);

            countTerm.ActualizeDays(ref days, dateTime);
            int weekToGenerateCorrectAmount = countTerm.GetWeeksCount(days, value);

            if (weekToGenerateCorrectAmount > weeksCount)
            {
                DateTime            continueToDate = dateTime.AddDays(weeksCount * _calendar.WeekTemplate.Count);
                List <ICalendarDay> extraDays      = GenerateWeeks(continueToDate, weekToGenerateCorrectAmount - weeksCount);
                days = days.Union(extraDays);
            }
            return(days);
        }