public override bool Equals(object obj)
 {
     if (obj is RecurrencePattern)
     {
         RecurrencePattern r = (RecurrencePattern)obj;
         if (!CollectionEquals(r.ByDay, ByDay) ||
             !CollectionEquals(r.ByHour, ByHour) ||
             !CollectionEquals(r.ByMinute, ByMinute) ||
             !CollectionEquals(r.ByMonth, ByMonth) ||
             !CollectionEquals(r.ByMonthDay, ByMonthDay) ||
             !CollectionEquals(r.BySecond, BySecond) ||
             !CollectionEquals(r.BySetPosition, BySetPosition) ||
             !CollectionEquals(r.ByWeekNo, ByWeekNo) ||
             !CollectionEquals(r.ByYearDay, ByYearDay))
         {
             return(false);
         }
         if (r.Count != Count)
         {
             return(false);
         }
         if (r.Frequency != Frequency)
         {
             return(false);
         }
         if (r.Interval != Interval)
         {
             return(false);
         }
         if (r.Until != DateTime.MinValue)
         {
             if (!r.Until.Equals(Until))
             {
                 return(false);
             }
         }
         else if (Until != DateTime.MinValue)
         {
             return(false);
         }
         if (r.FirstDayOfWeek != FirstDayOfWeek)
         {
             return(false);
         }
         return(true);
     }
     return(base.Equals(obj));
 }
Exemplo n.º 2
0
        private IRecurrencePattern ProcessRecurrencePattern(IDateTime referenceDate)
        {
            RecurrencePattern r = new RecurrencePattern();

            r.CopyFrom(Pattern);

            // Convert the UNTIL value to a local date/time based on the time zone information that
            // is in the reference date
            if (r.Until != DateTime.MinValue)
            {
                // Build an iCalDateTime with the correct time zone & calendar
                var until = new iCalDateTime(r.Until, referenceDate.TZID);
                until.AssociatedObject = referenceDate.AssociatedObject;

                // Convert back to local time so time zone comparisons match
                r.Until = until.Local;
            }

            if (r.Frequency > FrequencyType.Secondly &&
                r.BySecond.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.BySecond.Add(referenceDate.Second);
            }
            if (r.Frequency > FrequencyType.Minutely &&
                r.ByMinute.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.ByMinute.Add(referenceDate.Minute);
            }
            if (r.Frequency > FrequencyType.Hourly &&
                r.ByHour.Count == 0 &&
                referenceDate.HasTime /* NOTE: Fixes a bug where all-day events have BySecond/ByMinute/ByHour added incorrectly */)
            {
                r.ByHour.Add(referenceDate.Hour);
            }

            // If BYDAY, BYYEARDAY, or BYWEEKNO is specified, then
            // we don't default BYDAY, BYMONTH or BYMONTHDAY
            if (r.ByDay.Count == 0)
            {
                // If the frequency is weekly, use the original date's day of week.
                // NOTE: fixes WeeklyCount1() and WeeklyUntil1() handling
                // If BYWEEKNO is specified and BYMONTHDAY/BYYEARDAY is not specified,
                // then let's add BYDAY to BYWEEKNO.
                // NOTE: fixes YearlyByWeekNoX() handling
                if (r.Frequency == FrequencyType.Weekly ||
                    (
                        r.ByWeekNo.Count > 0 &&
                        r.ByMonthDay.Count == 0 &&
                        r.ByYearDay.Count == 0
                    ))
                {
                    r.ByDay.Add(new WeekDay(referenceDate.DayOfWeek));
                }

                // If BYMONTHDAY is not specified,
                // default to the current day of month.
                // NOTE: fixes YearlyByMonth1() handling, added BYYEARDAY exclusion
                // to fix YearlyCountByYearDay1() handling
                if (r.Frequency > FrequencyType.Weekly &&
                    r.ByWeekNo.Count == 0 &&
                    r.ByYearDay.Count == 0 &&
                    r.ByMonthDay.Count == 0)
                {
                    r.ByMonthDay.Add(referenceDate.Day);
                }

                // If BYMONTH is not specified, default to
                // the current month.
                // NOTE: fixes YearlyCountByYearDay1() handling
                if (r.Frequency > FrequencyType.Monthly &&
                    r.ByWeekNo.Count == 0 &&
                    r.ByYearDay.Count == 0 &&
                    r.ByMonth.Count == 0)
                {
                    r.ByMonth.Add(referenceDate.Month);
                }
            }

            return(r);
        }