summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Murchison <murch@fastmail.com>2020-11-05 17:24:53 -0500
committerKen Murchison <murch@fastmail.com>2020-11-05 17:24:53 -0500
commit36e2e5b8bc5945c4684d3ff3bafab36d49cbe2ed (patch)
tree8d16ec57b0ec264619d4e616dd7d74ffbac900d5
parent03c8fc0ea5a8f16d807d7bdfbf7ef5281f46f408 (diff)
downloadlibical-git-36e2e5b8bc5945c4684d3ff3bafab36d49cbe2ed.tar.gz
icalrecur.c: index value 0 in the daysmask is the last day of the previous year so set_day_of_year() should use that rather than -1
-rw-r--r--src/libical/icalrecur.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/libical/icalrecur.c b/src/libical/icalrecur.c
index 82793df0..62ce9678 100644
--- a/src/libical/icalrecur.c
+++ b/src/libical/icalrecur.c
@@ -1199,8 +1199,8 @@ static int get_days_in_year(icalrecur_iterator *impl, int year)
static void set_day_of_year(icalrecur_iterator *impl, int doy)
{
- if (doy < 0) {
- doy += get_days_in_year(impl, 0) + 1;
+ if (doy < 1) {
+ doy += get_days_in_year(impl, 0);
}
ucal_set(impl->rscale, UCAL_DAY_OF_YEAR, (int32_t) doy);
@@ -1682,8 +1682,8 @@ static void set_day_of_year(icalrecur_iterator *impl, int doy)
{
struct icaltimetype next;
- if (doy < 0) {
- doy += get_days_in_year(impl, impl->last.year) + 1;
+ if (doy < 1) {
+ doy += get_days_in_year(impl, impl->last.year);
}
next = icaltime_from_day_of_year(doy, impl->last.year);
@@ -2316,7 +2316,7 @@ static int expand_bymonth_days(icalrecur_iterator *impl, int year, int month)
int days_in_month = get_days_in_month(impl, month, year);
for (i = 0; BYMDPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++) {
- short doy = 0, mday = BYMDPTR[i];
+ short doy = ICAL_BY_YEARDAY_SIZE, mday = BYMDPTR[i];
int this_month = month;
if (abs(mday) > days_in_month) {
@@ -2345,7 +2345,7 @@ static int expand_bymonth_days(icalrecur_iterator *impl, int year, int month)
}
if (this_month == 0) {
- doy = -1; /* Last day of prev year */
+ doy = 0; /* Last day of prev year */
} else {
mday = -1; /* Last day of month */
}
@@ -2353,7 +2353,7 @@ static int expand_bymonth_days(icalrecur_iterator *impl, int year, int month)
}
}
- if (!doy) {
+ if (doy == ICAL_BY_YEARDAY_SIZE) {
doy = get_day_of_year(impl, year, this_month, mday, NULL);
}
@@ -2595,7 +2595,6 @@ static int next_weekday_by_week(icalrecur_iterator *impl)
}
increment_year(impl, -1);
- start_of_week--; /* set_day_of_year() assumes last doy == -1 */
}
set_day_of_year(impl, start_of_week + dow);
@@ -2660,7 +2659,6 @@ static int prev_weekday_by_week(icalrecur_iterator *impl)
if (dow + start_of_week < 1) {
/* The selected date is in the previous year. */
increment_year(impl, -1);
- start_of_week--; /* set_day_of_year() assumes last doy == -1 */
}
set_day_of_year(impl, start_of_week + dow);
@@ -2734,7 +2732,7 @@ static int expand_year_days(icalrecur_iterator *impl, int year)
case ICAL_SKIP_BACKWARD:
if (doy < 0) {
- doy = -1; /* Last day of prev year */
+ doy = 0; /* Last day of prev year */
} else {
doy = days_in_year; /* Last day of this year */
}
@@ -3004,7 +3002,7 @@ static int next_yearday(icalrecur_iterator *impl,
}
}
- if (impl->days_index < 0) {
+ if (impl->days_index < 1) {
/* Day is in previous year */
increment_year(impl, -1);
}
@@ -3036,7 +3034,7 @@ static int prev_yearday(icalrecur_iterator *impl,
impl->days_index = daymask_find_prev_bit(impl);
}
- if (impl->days_index < 0) {
+ if (impl->days_index < 1) {
/* Day is in previous year */
increment_year(impl, -1);
}