예제 #1
1
        /// <summary>
        /// This is used to find the starting point for the weekly frequency
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="start">The recurrence start date</param>
        /// <param name="end">The recurrence end date</param>
        /// <param name="from">The start date of the range limiting the instances generated</param>
        /// <param name="to">The end date of the range limiting the instances generated</param>
        /// <returns>The first instance date or null if there are no more instances</returns>
        public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from,
          RecurDateTime to)
        {
            RecurDateTime rdtWeek, rdt = new RecurDateTime(start);
            int adjust;

            // Get the difference between the recurrence start and the limiting range start
            DateTime dtStart = start.ToDateTime().Date.AddDays(0 - r.weekdayOffset);

            DateTime dtFrom = from.ToDateTime().Date;
            dtFrom = dtFrom.AddDays(0 - ((int)dtFrom.DayOfWeek + 7 - (int)r.WeekStart) % 7);

            // Adjust the date so that it's in range
            if(dtStart < dtFrom)
            {
                TimeSpan ts = dtFrom - dtStart;

                adjust = (ts.Days / 7) + r.Interval - 1;
                rdt.AddDays((adjust - (adjust % r.Interval)) * 7);
            }

            // If the start of the week is after the ranges, stop now
            rdtWeek = new RecurDateTime(rdt);
            rdtWeek.AddDays(0 - r.weekdayOffset);

            if(RecurDateTime.Compare(rdtWeek, end, RecurDateTime.DateTimePart.Day) > 0 ||
              RecurDateTime.Compare(rdtWeek, to, RecurDateTime.DateTimePart.Day) > 0)
                return null;

            return rdt;
        }
예제 #2
0
        /// <summary>
        /// This is used to find the starting point for the secondly frequency
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="start">The recurrence start date</param>
        /// <param name="end">The recurrence end date</param>
        /// <param name="from">The start date of the range limiting the instances generated</param>
        /// <param name="to">The end date of the range limiting the instances generated</param>
        /// <returns>The first instance date or null if there are no more instances</returns>
        public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from,
                                       RecurDateTime to)
        {
            RecurDateTime rdt = new RecurDateTime(start);
            int           adjust;

            if (RecurDateTime.Compare(start, from, RecurDateTime.DateTimePart.Hour) < 0)
            {
                // Get the difference between the recurrence start and the limiting range start
                DateTime dtStart = start.ToDateTime(), dtFrom = from.ToDateTime();

                // Adjust the date/time so that it's in range
                TimeSpan ts = dtFrom - dtStart;

                adjust = (int)ts.TotalSeconds + r.Interval - 1;
                rdt.AddSeconds(adjust - (adjust % r.Interval));
            }

            if (RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Hour) > 0 ||
                RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Hour) > 0)
            {
                return(null);
            }

            return(rdt);
        }
예제 #3
0
파일: DailyFrequency.cs 프로젝트: ywscr/PDI
        /// <summary>
        /// This is used to find the starting point for the daily frequency
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="start">The recurrence start date</param>
        /// <param name="end">The recurrence end date</param>
        /// <param name="from">The start date of the range limiting the instances generated</param>
        /// <param name="to">The end date of the range limiting the instances generated</param>
        /// <returns>The first instance date or null if there are no more instances</returns>
        public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from,
                                       RecurDateTime to)
        {
            RecurDateTime rdt = new RecurDateTime(start);
            int           adjust;

            // Get the difference between the recurrence start and the limiting range start
            DateTime dtStart = start.ToDateTime().Date, dtFrom = from.ToDateTime().Date;

            // Adjust the date so that it's in range
            if (dtStart < dtFrom)
            {
                TimeSpan ts = dtFrom - dtStart;

                adjust = ts.Days + r.Interval - 1;
                rdt.AddDays(adjust - (adjust % r.Interval));
            }

            if (RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Day) > 0 ||
                RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Day) > 0)
            {
                return(null);
            }

            return(rdt);
        }
예제 #4
0
        /// <summary>
        /// This is used to find the starting point for the weekly frequency
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="start">The recurrence start date</param>
        /// <param name="end">The recurrence end date</param>
        /// <param name="from">The start date of the range limiting the instances generated</param>
        /// <param name="to">The end date of the range limiting the instances generated</param>
        /// <returns>The first instance date or null if there are no more instances</returns>
        public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from,
                                       RecurDateTime to)
        {
            RecurDateTime rdtWeek, rdt = new RecurDateTime(start);
            int           adjust;

            // Get the difference between the recurrence start and the limiting range start
            DateTime dtStart = start.ToDateTime().Date.AddDays(0 - r.weekdayOffset);

            DateTime dtFrom = from.ToDateTime().Date;

            dtFrom = dtFrom.AddDays(0 - ((int)dtFrom.DayOfWeek + 7 - (int)r.WeekStart) % 7);

            // Adjust the date so that it's in range
            if (dtStart < dtFrom)
            {
                TimeSpan ts = dtFrom - dtStart;

                adjust = (ts.Days / 7) + r.Interval - 1;
                rdt.AddDays((adjust - (adjust % r.Interval)) * 7);
            }

            // If the start of the week is after the ranges, stop now
            rdtWeek = new RecurDateTime(rdt);
            rdtWeek.AddDays(0 - r.weekdayOffset);

            if (RecurDateTime.Compare(rdtWeek, end, RecurDateTime.DateTimePart.Day) > 0 ||
                RecurDateTime.Compare(rdtWeek, to, RecurDateTime.DateTimePart.Day) > 0)
            {
                return(null);
            }

            return(rdt);
        }
예제 #5
0
        /// <summary>
        /// This is used to find the starting point for the minutely frequency
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="start">The recurrence start date</param>
        /// <param name="end">The recurrence end date</param>
        /// <param name="from">The start date of the range limiting the instances generated</param>
        /// <param name="to">The end date of the range limiting the instances generated</param>
        /// <returns>The first instance date or null if there are no more instances</returns>
        public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from,
          RecurDateTime to)
        {
            RecurDateTime rdt = new RecurDateTime(start);
            int adjust;

            if(RecurDateTime.Compare(start, from, RecurDateTime.DateTimePart.Hour) < 0)
            {
                // Get the difference between the recurrence start and the limiting range start
                DateTime dtStart = start.ToDateTime().AddSeconds(0 - start.Second),
                         dtFrom = from.ToDateTime().AddSeconds(0 - from.Second);

                // Adjust the date/time so that it's in range
                TimeSpan ts = dtFrom - dtStart;

                adjust = (int)ts.TotalMinutes + r.Interval - 1;
                rdt.AddMinutes(adjust - (adjust % r.Interval));
            }

            if(RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Hour) > 0 ||
              RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Hour) > 0)
                return null;

            return rdt;
        }
예제 #6
0
        /// <summary>
        /// This is used to find the starting point for the daily frequency
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="start">The recurrence start date</param>
        /// <param name="end">The recurrence end date</param>
        /// <param name="from">The start date of the range limiting the instances generated</param>
        /// <param name="to">The end date of the range limiting the instances generated</param>
        /// <returns>The first instance date or null if there are no more instances</returns>
        public RecurDateTime FindStart(Recurrence r, RecurDateTime start, RecurDateTime end, RecurDateTime from,
          RecurDateTime to)
        {
            RecurDateTime rdt = new RecurDateTime(start);
            int adjust;

            // Get the difference between the recurrence start and the limiting range start
            DateTime dtStart = start.ToDateTime().Date, dtFrom = from.ToDateTime().Date;

            // Adjust the date so that it's in range
            if(dtStart < dtFrom)
            {
                TimeSpan ts = dtFrom - dtStart;

                adjust = ts.Days + r.Interval - 1;
                rdt.AddDays(adjust - (adjust % r.Interval));
            }

            if(RecurDateTime.Compare(rdt, end, RecurDateTime.DateTimePart.Day) > 0 ||
              RecurDateTime.Compare(rdt, to, RecurDateTime.DateTimePart.Day) > 0)
                return null;

            return rdt;
        }