Beispiel #1
0
        /// <summary>
        /// This is used to expand the yearly frequency by month
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="dates">A reference to the collection of current instances that have been generated</param>
        /// <returns>The number of instances in the collection.  If zero, subsequent rules don't have to be
        /// checked as there's nothing else to do.</returns>
        /// <remarks>This may generate invalid dates (i.e. June 31st).  These will be removed later.</remarks>
        public int ByMonth(Recurrence r, RecurDateTimeCollection dates)
        {
            RecurDateTime rdt, rdtNew;

            int expIdx, count = dates.Count;

            UniqueIntegerCollection byMonth = r.ByMonth;

            // Don't bother if either collection is empty
            if (count != 0 && byMonth.Count != 0)
            {
                for (int idx = 0; idx < count; idx++)
                {
                    rdt = dates[0];
                    dates.RemoveAt(0);

                    // Expand the date/time by adding a new entry for each month specified
                    for (expIdx = 0; expIdx < byMonth.Count; expIdx++)
                    {
                        rdtNew = new RecurDateTime(rdt)
                        {
                            Month = byMonth[expIdx] - 1
                        };
                        dates.Add(rdtNew);
                    }
                }
            }

            return(dates.Count);
        }
Beispiel #2
0
        /// <summary>
        /// This is used to expand by second
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="dates">A reference to the collection of current instances that have been generated</param>
        /// <returns>The number of instances in the collection.  If zero, subsequent rules don't have to be
        /// checked as there's nothing else to do.</returns>
        /// <remarks>If a date in the collection is invalid, it will be discarded</remarks>
        public static int BySecond(Recurrence r, RecurDateTimeCollection dates)
        {
            RecurDateTime rdt, rdtNew;
            int           expIdx, count = dates.Count;

            UniqueIntegerCollection bySecond = r.BySecond;

            // Don't bother if either collection is empty
            if (count != 0 && bySecond.Count != 0)
            {
                for (int idx = 0; idx < count; idx++)
                {
                    rdt = dates[0];
                    dates.RemoveAt(0);

                    // If not valid, discard it
                    if (!rdt.IsValidDate())
                    {
                        continue;
                    }

                    // Expand the date/time by adding a new entry for each second specified
                    for (expIdx = 0; expIdx < bySecond.Count; expIdx++)
                    {
                        rdtNew        = new RecurDateTime(rdt);
                        rdtNew.Second = bySecond[expIdx];
                        dates.Add(rdtNew);
                    }
                }
            }

            return(dates.Count);
        }
Beispiel #3
0
        /// <summary>
        /// Copy constructor
        /// </summary>
        /// <param name="values">The <c>UniqueIntegerCollection</c> to copy.  The range and zero exclusion
        /// setting are inherited from the copied collection.</param>
        public UniqueIntegerCollection(UniqueIntegerCollection values)
        {
            if (values != null)
            {
                this.MinimumValue = values.MinimumValue;
                this.MaximumValue = values.MaximumValue;
                this.AllowZero    = values.AllowZero;

                this.AddRange(values);
            }
        }
Beispiel #4
0
        /// <summary>
        /// This is used to expand the yearly frequency by week number
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="dates">A reference to the collection of current instances that have been generated</param>
        /// <returns>The number of instances in the collection.  If zero, subsequent rules don't have to be
        /// checked as there's nothing else to do.</returns>
        /// <remarks>If an expanded date is invalid, it will be discarded</remarks>
        public int ByWeekNo(Recurrence r, RecurDateTimeCollection dates)
        {
            RecurDateTime rdt, rdtNew;

            int expIdx, week, yearWeeks, count = dates.Count;

            UniqueIntegerCollection byWeekNo = r.ByWeekNo;

            // Don't bother if either collection is empty
            if (count != 0 && byWeekNo.Count != 0)
            {
                for (int idx = 0; idx < count; idx++)
                {
                    rdt       = dates[0];
                    yearWeeks = DateUtils.WeeksInYear(rdt.Year, r.WeekStart);
                    dates.RemoveAt(0);

                    // Expand the date/time by adding a new entry for each week number specified
                    for (expIdx = 0; expIdx < byWeekNo.Count; expIdx++)
                    {
                        week = byWeekNo[expIdx];

                        // If not in the year, discard it
                        if ((week == 53 || week == -53) && yearWeeks == 52)
                        {
                            continue;
                        }

                        if (week > 0)
                        {
                            rdtNew = new RecurDateTime(DateUtils.DateFromWeek(rdt.Year, week, r.WeekStart,
                                                                              r.weekdayOffset));
                        }
                        else
                        {
                            rdtNew = new RecurDateTime(DateUtils.DateFromWeek(rdt.Year, yearWeeks + week + 1,
                                                                              r.WeekStart, r.weekdayOffset));
                        }

                        rdtNew.Hour   = rdt.Hour;
                        rdtNew.Minute = rdt.Minute;
                        rdtNew.Second = rdt.Second;

                        dates.Add(rdtNew);
                    }
                }
            }

            return(dates.Count);
        }
Beispiel #5
0
        /// <summary>
        /// This is used to expand the yearly frequency by year day
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="dates">A reference to the collection of current instances that have been generated</param>
        /// <returns>The number of instances in the collection.  If zero, subsequent rules don't have to be
        /// checked as there's nothing else to do.</returns>
        /// <remarks>If an expanded date is invalid, it will be discarded</remarks>
        public int ByYearDay(Recurrence r, RecurDateTimeCollection dates)
        {
            RecurDateTime rdt, rdtNew;

            int expIdx, yearDay, count = dates.Count;

            UniqueIntegerCollection byYearDay = r.ByYearDay;

            // Don't bother if either collection is empty
            if (count != 0 && byYearDay.Count != 0)
            {
                for (int idx = 0; idx < count; idx++)
                {
                    rdt = dates[0];
                    dates.RemoveAt(0);

                    // Expand the date/time by adding a new entry for each year day specified
                    for (expIdx = 0; expIdx < byYearDay.Count; expIdx++)
                    {
                        yearDay = byYearDay[expIdx];
                        rdtNew  = new RecurDateTime(rdt)
                        {
                            Month = 0, Day = 1
                        };

                        // From start of year or end of year?
                        if (yearDay > 0)
                        {
                            rdtNew.AddDays(yearDay - 1);
                        }
                        else
                        {
                            rdtNew.Year++;
                            rdtNew.AddDays(yearDay);
                        }

                        // If not in the year, discard it
                        if (rdtNew.Year != rdt.Year)
                        {
                            continue;
                        }

                        dates.Add(rdtNew);
                    }
                }
            }

            return(dates.Count);
        }
Beispiel #6
0
        /// <summary>
        /// This is used to expand by month day
        /// </summary>
        /// <param name="r">A reference to the recurrence</param>
        /// <param name="dates">A reference to the collection of current instances that have been generated</param>
        /// <returns>The number of instances in the collection.  If zero, subsequent rules don't have to be
        /// checked as there's nothing else to do.</returns>
        /// <remarks>If an expanded date is invalid, it will be discarded</remarks>
        public static int ByMonthDay(Recurrence r, RecurDateTimeCollection dates)
        {
            RecurDateTime rdt, rdtNew;
            int           expIdx, monthDay, count = dates.Count;

            UniqueIntegerCollection byMonthDay = r.ByMonthDay;

            // Don't bother if either collection is empty
            if (count != 0 && byMonthDay.Count != 0)
            {
                for (int idx = 0; idx < count; idx++)
                {
                    rdt = dates[0];
                    dates.RemoveAt(0);

                    // Expand the date/time by adding a new entry for each month day specified
                    for (expIdx = 0; expIdx < byMonthDay.Count; expIdx++)
                    {
                        monthDay = byMonthDay[expIdx];
                        rdtNew   = new RecurDateTime(rdt)
                        {
                            Day = 1
                        };

                        // From start of month or end of month?
                        if (monthDay > 0)
                        {
                            rdtNew.AddDays(monthDay - 1);
                        }
                        else
                        {
                            rdtNew.AddMonths(1);
                            rdtNew.AddDays(monthDay);
                        }

                        // If not in the month, discard it
                        if (rdtNew.Month != rdt.Month)
                        {
                            continue;
                        }

                        dates.Add(rdtNew);
                    }
                }
            }

            return(dates.Count);
        }