Skip to content

Commit

Permalink
icalrecur.c: more icalrecur_iterator_new() cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmurchison committed Sep 18, 2015
1 parent d307849 commit 84bd803
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/libical/icalrecur.c
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,8 @@ icalrecur_iterator *icalrecur_iterator_new(struct icalrecurrencetype rule,
return 0;
}

if (impl->rule.freq == ICAL_WEEKLY_RECURRENCE) {
switch (impl->rule.freq) {
case ICAL_WEEKLY_RECURRENCE:

if (impl->by_ptrs[BY_DAY][0] == ICAL_RECURRENCE_ARRAY_MAX) {

Expand Down Expand Up @@ -2052,16 +2053,14 @@ icalrecur_iterator *icalrecur_iterator_new(struct icalrecurrencetype rule,
increment_monthday(impl, dow);
}
}
}
break;

/* For YEARLY rule, begin by setting up the year days array . The
YEARLY rules work by expanding one year at a time. */
case ICAL_YEARLY_RECURRENCE: {
/* For YEARLY rule, begin by setting up the year days array.
The YEARLY rules work by expanding one year at a time. */

if (impl->rule.freq == ICAL_YEARLY_RECURRENCE) {
struct icaltimetype last = occurrence_as_icaltime(impl, 0);

icalerror_clear_errno();

/* Fail after hitting the year 20000 if no expanded days match */
while (last.year < 20000) {
expand_year_days(impl, last.year);
Expand All @@ -2079,33 +2078,40 @@ icalrecur_iterator *icalrecur_iterator_new(struct icalrecurrencetype rule,

/* Copy the first day into last. */
set_day_of_year(impl, impl->days_index);

break;
}

/* If this is a monthly interval with by day data, then we need to
set the last value to the appropriate day of the month */
case ICAL_MONTHLY_RECURRENCE:
/* If this is a monthly interval with by day data, then we need to
set the last value to the appropriate day of the month */

if (impl->rule.freq == ICAL_MONTHLY_RECURRENCE &&
has_by_data(impl, BY_DAY)) {
if (has_by_data(impl, BY_DAY)) {

int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[BYDAYIDX]);
int pos = icalrecurrencetype_day_position(BYDAYPTR[BYDAYIDX]);
int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[BYDAYIDX]);
int pos = icalrecurrencetype_day_position(BYDAYPTR[BYDAYIDX]);

if (set_day_of_week(impl, dow, pos) == 0) {
icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
free(impl);
return 0;
}
if (set_day_of_week(impl, dow, pos) == 0) {
icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
free(impl);
return 0;
}

/* If there is BY_MONTH_DAY data,
and the first day of BY_DAY data != first BY_MONTH_DAY data,
back up one week, so we don't return false data */
if (has_by_data(impl, BY_MONTH_DAY)) {
struct icaltimetype last = occurrence_as_icaltime(impl, 0);
/* If there is BY_MONTH_DAY data,
and the first day of BY_DAY data != first BY_MONTH_DAY data,
back up one week, so we don't return false data */
if (has_by_data(impl, BY_MONTH_DAY)) {
struct icaltimetype last = occurrence_as_icaltime(impl, 0);

if (last.day != impl->by_ptrs[BY_MONTH_DAY][0]) {
increment_monthday(impl, -7);
if (last.day != impl->by_ptrs[BY_MONTH_DAY][0]) {
increment_monthday(impl, -7);
}
}
}
break;

default:
break;
}

impl->last = occurrence_as_icaltime(impl, 1);
Expand Down

0 comments on commit 84bd803

Please sign in to comment.