summaryrefslogtreecommitdiffabout
path: root/libical/src/libical/icalrecur.c
authorzautrix <zautrix>2004-06-29 11:59:46 (UTC)
committer zautrix <zautrix>2004-06-29 11:59:46 (UTC)
commitda43dbdc6c82453228f34766fc74585615cba938 (patch) (side-by-side diff)
tree16576932cea08bf117b2d0320b0d5f66ee8ad093 /libical/src/libical/icalrecur.c
parent627489ea2669d3997676bc3cee0f5d0d0c16c4d4 (diff)
downloadkdepimpi-da43dbdc6c82453228f34766fc74585615cba938.zip
kdepimpi-da43dbdc6c82453228f34766fc74585615cba938.tar.gz
kdepimpi-da43dbdc6c82453228f34766fc74585615cba938.tar.bz2
New lib ical.Some minor changes as well.
Diffstat (limited to 'libical/src/libical/icalrecur.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libical/icalrecur.c789
1 files changed, 433 insertions, 356 deletions
diff --git a/libical/src/libical/icalrecur.c b/libical/src/libical/icalrecur.c
index 203ce70..d5a59c6 100644
--- a/libical/src/libical/icalrecur.c
+++ b/libical/src/libical/icalrecur.c
@@ -21,3 +21,7 @@
the License at http://www.mozilla.org/MPL/
+*/
+/**
+ @file icalrecur.c
+ @brief Implementation of routines for dealing with recurring time
@@ -132,11 +136,10 @@
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include "icalrecur.h"
-#ifdef ICAL_NO_LIBICAL
-#define icalerror_set_errno(x)
-#define icalerror_check_arg_rv(x,y)
-#else
#include "icalerror.h"
#include "icalmemory.h"
-#endif
@@ -150,2 +153,6 @@
+/** This is the last year we will go up to, since 32-bit time_t values
+ only go up to the start of 2038. */
+#define MAX_TIME_T_YEAR 2037
+
#define TEMP_MAX 1024
@@ -172,3 +179,2 @@ icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str);
-
/*********************** Rule parsing routines ************************/
@@ -255,3 +261,3 @@ void icalrecur_add_byrules(struct icalrecur_parser *parser, short *array,
int sign = 1;
- short v;
+ int v;
@@ -282,2 +288,4 @@ void icalrecur_add_byrules(struct icalrecur_parser *parser, short *array,
t++;
+ } else {
+ sign = 1;
}
@@ -287,3 +295,3 @@ void icalrecur_add_byrules(struct icalrecur_parser *parser, short *array,
- array[i++] = v;
+ array[i++] = (short)v;
array[i] = ICAL_RECURRENCE_ARRAY_MAX;
@@ -334,13 +342,10 @@ void icalrecur_add_bydayrules(struct icalrecur_parser *parser, const char* vals)
- weekno = 0;
/* Get Optional weekno */
- if( sscanf(t,"%d",&weekno) != 0){
- if (n != 0){
- int weeknolen = (n-t)-3; /* 3 -> one for \0, 2 for day name */
- /* could use abs(log10(weekno))+1, but that needs libm */
- t += weeknolen;
- } else {
- t = end -2;
- }
- }
+ weekno = strtol(t,&t,10);
+
+ /* Outlook/Exchange generate "BYDAY=MO, FR" and "BYDAY=2 TH".
+ * Cope with that.
+ */
+ if (*t == ' ')
+ t++;
@@ -348,3 +353,3 @@ void icalrecur_add_bydayrules(struct icalrecur_parser *parser, const char* vals)
- array[i++] = sign* ((int)wd + 8*weekno);
+ array[i++] = (short)(sign* (wd + 8*weekno));
array[i] = ICAL_RECURRENCE_ARRAY_MAX;
@@ -389,2 +394,3 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
icalrecurrencetype_clear(&parser.rt);
+ free(parser.copy);
return parser.rt;
@@ -399,3 +405,3 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
} else if (strcmp(name,"INTERVAL") == 0){
- parser.rt.interval = atoi(value);
+ parser.rt.interval = (short)atoi(value);
} else if (strcmp(name,"WKST") == 0){
@@ -431,2 +437,3 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
icalrecurrencetype_clear(&parser.rt);
+ free(parser.copy);
return parser.rt;
@@ -442,5 +449,3 @@ struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
-#ifndef ICAL_NO_LIBICAL
-
-struct { char* str;size_t offset; short limit; } recurmap[] =
+static struct { char* str;size_t offset; int limit; } recurmap[] =
{
@@ -459,2 +464,3 @@ struct { char* str;size_t offset; short limit; } recurmap[] =
/* A private routine in icalvalue.c */
+void print_date_to_string(char* str, struct icaltimetype *data);
void print_datetime_to_string(char* str, struct icaltimetype *data);
@@ -483,3 +489,6 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur)
temp[0] = 0;
- print_datetime_to_string(temp,&(recur->until));
+ if (recur->until.is_date)
+ print_date_to_string(temp,&(recur->until));
+ else
+ print_datetime_to_string(temp,&(recur->until));
@@ -503,3 +512,3 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur)
short* array = (short*)(recurmap[j].offset+ (size_t)recur);
- short limit = recurmap[j].limit;
+ int limit = recurmap[j].limit;
@@ -514,5 +523,5 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur)
if (j == 3) { /* BYDAY */
- short dow = icalrecurrencetype_day_day_of_week(array[i]);
- const char *daystr = icalrecur_weekday_to_string(dow);
- short pos;
+ const char *daystr = icalrecur_weekday_to_string(
+ icalrecurrencetype_day_day_of_week(array[i]));
+ int pos;
@@ -542,4 +551,2 @@ char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur)
}
-#endif
-
@@ -575,6 +582,6 @@ struct icalrecur_iterator_impl {
short by_indices[9];
- short orig_data[9]; /* 1 if there was data in the byrule */
+ short orig_data[9]; /**< 1 if there was data in the byrule */
- short *by_ptrs[9]; /* Pointers into the by_* array elements of the rule */
+ short *by_ptrs[9]; /**< Pointers into the by_* array elements of the rule */
@@ -582,2 +589,4 @@ struct icalrecur_iterator_impl {
+static void increment_year(icalrecur_iterator* impl, int inc);
+
int icalrecur_iterator_sizeof_byarray(short* byarray)
@@ -601,6 +610,9 @@ enum expand_table {
-/* The split map indicates, for a particular interval, wether a BY_*
- rule part expands the number of instances in the occcurrence set or
- contracts it. 1=> contract, 2=>expand, and 3 means the pairing is
- not allowed. */
+/**
+ * The split map indicates, for a particular interval, wether a BY_*
+ * rule part expands the number of instances in the occcurrence set or
+ * contracts it. 1=> contract, 2=>expand, and 3 means the pairing is
+ * not allowed.
+ */
+
struct expand_split_map_struct
@@ -615,3 +627,3 @@ struct expand_split_map_struct
-struct expand_split_map_struct expand_map[] =
+static struct expand_split_map_struct expand_map[] =
{
@@ -630,4 +642,5 @@ struct expand_split_map_struct expand_map[] =
-/* Check that the rule has only the two given interday byrule parts. */
-int icalrecur_two_byrule(struct icalrecur_iterator_impl* impl,
+/** Check that the rule has only the two given interday byrule parts. */
+static
+int icalrecur_two_byrule(icalrecur_iterator* impl,
enum byrule one,enum byrule two)
@@ -638,3 +651,3 @@ int icalrecur_two_byrule(struct icalrecur_iterator_impl* impl,
- memset(test_array,0,9);
+ memset(test_array,0,sizeof(test_array));
@@ -661,4 +674,4 @@ int icalrecur_two_byrule(struct icalrecur_iterator_impl* impl,
-/* Check that the rule has only the one given interdat byrule parts. */
-int icalrecur_one_byrule(struct icalrecur_iterator_impl* impl,enum byrule one)
+/** Check that the rule has only the one given interdat byrule parts. */
+static int icalrecur_one_byrule(icalrecur_iterator* impl,enum byrule one)
{
@@ -678,3 +691,3 @@ int icalrecur_one_byrule(struct icalrecur_iterator_impl* impl,enum byrule one)
-int count_byrules(struct icalrecur_iterator_impl* impl)
+static int count_byrules(icalrecur_iterator* impl)
{
@@ -693,5 +706,5 @@ int count_byrules(struct icalrecur_iterator_impl* impl)
-void setup_defaults(struct icalrecur_iterator_impl* impl,
+static void setup_defaults(icalrecur_iterator* impl,
enum byrule byrule, icalrecurrencetype_frequency req,
- short deftime, int *timepart)
+ int deftime, int *timepart)
{
@@ -706,3 +719,3 @@ void setup_defaults(struct icalrecur_iterator_impl* impl,
expand_map[freq].map[byrule] != CONTRACT){
- impl->by_ptrs[byrule][0] = deftime;
+ impl->by_ptrs[byrule][0] = (short)deftime;
}
@@ -717,3 +730,3 @@ void setup_defaults(struct icalrecur_iterator_impl* impl,
-int has_by_data(struct icalrecur_iterator_impl* impl, enum byrule byrule){
+static int has_by_data(icalrecur_iterator* impl, enum byrule byrule){
@@ -723,3 +736,3 @@ int has_by_data(struct icalrecur_iterator_impl* impl, enum byrule byrule){
-int expand_year_days(struct icalrecur_iterator_impl* impl,short year);
+static int expand_year_days(icalrecur_iterator* impl, int year);
@@ -729,9 +742,7 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
{
- struct icalrecur_iterator_impl* impl;
+ icalrecur_iterator* impl;
icalrecurrencetype_frequency freq;
- short days_in_month;
-
- if ( ( impl = (struct icalrecur_iterator_impl *)
- malloc(sizeof(struct icalrecur_iterator_impl))) == 0) {
+ if ( ( impl = (icalrecur_iterator*)
+ malloc(sizeof(icalrecur_iterator))) == 0) {
icalerror_set_errno(ICAL_NEWFAILED_ERROR);
@@ -740,3 +751,3 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
- memset(impl,0,sizeof(struct icalrecur_iterator_impl));
+ memset(impl,0,sizeof(icalrecur_iterator));
@@ -762,3 +773,3 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
- memset(impl->orig_data,0,9);
+ memset(impl->orig_data,0,9*sizeof(short));
@@ -770,19 +781,19 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
impl->orig_data[BY_MONTH]
- = (impl->rule.by_month[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ = (short)(impl->rule.by_month[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_WEEK_NO]
- =(impl->rule.by_week_no[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ =(short)(impl->rule.by_week_no[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_YEAR_DAY]
- =(impl->rule.by_year_day[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ =(short)(impl->rule.by_year_day[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_MONTH_DAY]
- =(impl->rule.by_month_day[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ =(short)(impl->rule.by_month_day[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_DAY]
- = (impl->rule.by_day[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ = (short)(impl->rule.by_day[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_HOUR]
- = (impl->rule.by_hour[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ = (short)(impl->rule.by_hour[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_MINUTE]
- = (impl->rule.by_minute[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ = (short)(impl->rule.by_minute[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_SECOND]
- = (impl->rule.by_second[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ = (short)(impl->rule.by_second[0]!=ICAL_RECURRENCE_ARRAY_MAX);
impl->orig_data[BY_SET_POS]
- = (impl->rule.by_set_pos[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ = (short)(impl->rule.by_set_pos[0]!=ICAL_RECURRENCE_ARRAY_MAX);
@@ -854,15 +865,20 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
- setup_defaults(impl,BY_SECOND,ICAL_SECONDLY_RECURRENCE,impl->dtstart.second,
+ setup_defaults(impl,BY_SECOND,ICAL_SECONDLY_RECURRENCE,
+ impl->dtstart.second,
&(impl->last.second));
- setup_defaults(impl,BY_MINUTE,ICAL_MINUTELY_RECURRENCE,impl->dtstart.minute,
+ setup_defaults(impl,BY_MINUTE,ICAL_MINUTELY_RECURRENCE,
+ impl->dtstart.minute,
&(impl->last.minute));
- setup_defaults(impl,BY_HOUR,ICAL_HOURLY_RECURRENCE,impl->dtstart.hour,
+ setup_defaults(impl,BY_HOUR,ICAL_HOURLY_RECURRENCE,
+ impl->dtstart.hour,
&(impl->last.hour));
- setup_defaults(impl,BY_MONTH_DAY,ICAL_DAILY_RECURRENCE,impl->dtstart.day,
+ setup_defaults(impl,BY_MONTH_DAY,ICAL_DAILY_RECURRENCE,
+ impl->dtstart.day,
&(impl->last.day));
- setup_defaults(impl,BY_MONTH,ICAL_MONTHLY_RECURRENCE,impl->dtstart.month,
+ setup_defaults(impl,BY_MONTH,ICAL_MONTHLY_RECURRENCE,
+ impl->dtstart.month,
&(impl->last.month));
@@ -876,3 +892,3 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
same day of the week as the start time . */
- impl->by_ptrs[BY_DAY][0] = icaltime_day_of_week(impl->dtstart);
+ impl->by_ptrs[BY_DAY][0] = (short)icaltime_day_of_week(impl->dtstart);
@@ -890,3 +906,3 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
- short dow = impl->by_ptrs[BY_DAY][0]-icaltime_day_of_week(impl->last);
+ short dow = (short)(impl->by_ptrs[BY_DAY][0]-icaltime_day_of_week(impl->last));
@@ -903,6 +919,20 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
- /* For YEARLY rule, begin by setting up the year days array */
+ /* 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){
- expand_year_days(impl,impl->last.year);
+ struct icaltimetype next;
+
+ for (;;) {
+ expand_year_days(impl, impl->last.year);
+ if (impl->days[0] != ICAL_RECURRENCE_ARRAY_MAX)
+ break; /* break when no days are expanded */
+ increment_year(impl,impl->rule.interval);
+ }
+
+ /* Copy the first day into last. */
+ next = icaltime_from_day_of_year(impl->days[0], impl->last.year);
+
+ impl->last.day = next.day;
+ impl->last.month = next.month;
}
@@ -916,9 +946,9 @@ icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
- short dow = icalrecurrencetype_day_day_of_week(
+ int dow = icalrecurrencetype_day_day_of_week(
impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]);
- short pos = icalrecurrencetype_day_position(
+ int pos = icalrecurrencetype_day_position(
impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]);
- short poscount = 0;
- days_in_month =
+ int poscount = 0;
+ int days_in_month =
icaltime_days_in_month(impl->last.month, impl->last.year);
@@ -971,9 +1001,5 @@ void icalrecur_iterator_free(icalrecur_iterator* i)
{
+ icalerror_check_arg_rv((i!=0),"impl");
- struct icalrecur_iterator_impl* impl =
- (struct icalrecur_iterator_impl*)i;
-
- icalerror_check_arg_rv((impl!=0),"impl");
-
- free(impl);
+ free(i);
@@ -981,4 +1007,3 @@ void icalrecur_iterator_free(icalrecur_iterator* i)
-
-void increment_year(struct icalrecur_iterator_impl* impl, int inc)
+static void increment_year(icalrecur_iterator* impl, int inc)
{
@@ -987,6 +1012,6 @@ void increment_year(struct icalrecur_iterator_impl* impl, int inc)
-/* Increment month is different that the other incement_* routines --
+/** Increment month is different that the other incement_* routines --
it figures out the interval for itself, and uses BYMONTH data if
available. */
-void increment_month(struct icalrecur_iterator_impl* impl)
+static void increment_month(icalrecur_iterator* impl)
{
@@ -1037,3 +1062,3 @@ void increment_month(struct icalrecur_iterator_impl* impl)
-void increment_monthday(struct icalrecur_iterator_impl* impl, int inc)
+static void increment_monthday(icalrecur_iterator* impl, int inc)
{
@@ -1043,4 +1068,4 @@ void increment_monthday(struct icalrecur_iterator_impl* impl, int inc)
- short days_in_month =
- icaltime_days_in_month(impl->last.month,impl->last.year);
+ int days_in_month =
+ icaltime_days_in_month(impl->last.month, impl->last.year);
@@ -1056,5 +1081,5 @@ void increment_monthday(struct icalrecur_iterator_impl* impl, int inc)
-void increment_hour(struct icalrecur_iterator_impl* impl, int inc)
+static void increment_hour(icalrecur_iterator* impl, int inc)
{
- short days;
+ int days;
@@ -1070,5 +1095,5 @@ void increment_hour(struct icalrecur_iterator_impl* impl, int inc)
-void increment_minute(struct icalrecur_iterator_impl* impl, int inc)
+static void increment_minute(icalrecur_iterator* impl, int inc)
{
- short hours;
+ int hours;
@@ -1085,5 +1110,5 @@ void increment_minute(struct icalrecur_iterator_impl* impl, int inc)
-void increment_second(struct icalrecur_iterator_impl* impl, int inc)
+static void increment_second(icalrecur_iterator* impl, int inc)
{
- short minutes;
+ int minutes;
@@ -1104,3 +1129,3 @@ void test_increment()
{
- struct icalrecur_iterator_impl impl;
+ icalrecur_iterator impl;
@@ -1134,13 +1159,13 @@ void test_increment()
-short next_second(struct icalrecur_iterator_impl* impl)
+static int next_second(icalrecur_iterator* impl)
{
- short has_by_data = (impl->by_ptrs[BY_SECOND][0]!=ICAL_RECURRENCE_ARRAY_MAX);
- short this_frequency = (impl->rule.freq == ICAL_SECONDLY_RECURRENCE);
+ int has_by_second = (impl->by_ptrs[BY_SECOND][0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ int this_frequency = (impl->rule.freq == ICAL_SECONDLY_RECURRENCE);
- short end_of_data = 0;
+ int end_of_data = 0;
- assert(has_by_data || this_frequency);
+ assert(has_by_second || this_frequency);
- if( has_by_data ){
+ if( has_by_second ){
/* Ignore the frequency and use the byrule data */
@@ -1161,3 +1186,3 @@ short next_second(struct icalrecur_iterator_impl* impl)
- } else if( !has_by_data && this_frequency ){
+ } else if( !has_by_second && this_frequency ){
/* Compute the next value from the last time and the frequency interval*/
@@ -1170,3 +1195,3 @@ short next_second(struct icalrecur_iterator_impl* impl)
- if(has_by_data && end_of_data && this_frequency ){
+ if(has_by_second && end_of_data && this_frequency ){
increment_minute(impl,1);
@@ -1178,11 +1203,11 @@ short next_second(struct icalrecur_iterator_impl* impl)
-int next_minute(struct icalrecur_iterator_impl* impl)
+static int next_minute(icalrecur_iterator* impl)
{
- short has_by_data = (impl->by_ptrs[BY_MINUTE][0]!=ICAL_RECURRENCE_ARRAY_MAX);
- short this_frequency = (impl->rule.freq == ICAL_MINUTELY_RECURRENCE);
+ int has_by_minute = (impl->by_ptrs[BY_MINUTE][0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ int this_frequency = (impl->rule.freq == ICAL_MINUTELY_RECURRENCE);
- short end_of_data = 0;
+ int end_of_data = 0;
- assert(has_by_data || this_frequency);
+ assert(has_by_minute || this_frequency);
@@ -1193,3 +1218,3 @@ int next_minute(struct icalrecur_iterator_impl* impl)
- if( has_by_data ){
+ if( has_by_minute ){
/* Ignore the frequency and use the byrule data */
@@ -1209,3 +1234,3 @@ int next_minute(struct icalrecur_iterator_impl* impl)
- } else if( !has_by_data && this_frequency ){
+ } else if( !has_by_minute && this_frequency ){
/* Compute the next value from the last time and the frequency interval*/
@@ -1217,3 +1242,3 @@ int next_minute(struct icalrecur_iterator_impl* impl)
- if(has_by_data && end_of_data && this_frequency ){
+ if(has_by_minute && end_of_data && this_frequency ){
increment_hour(impl,1);
@@ -1224,11 +1249,11 @@ int next_minute(struct icalrecur_iterator_impl* impl)
-int next_hour(struct icalrecur_iterator_impl* impl)
+static int next_hour(icalrecur_iterator* impl)
{
- short has_by_data = (impl->by_ptrs[BY_HOUR][0]!=ICAL_RECURRENCE_ARRAY_MAX);
- short this_frequency = (impl->rule.freq == ICAL_HOURLY_RECURRENCE);
+ int has_by_hour = (impl->by_ptrs[BY_HOUR][0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ int this_frequency = (impl->rule.freq == ICAL_HOURLY_RECURRENCE);
- short end_of_data = 0;
+ int end_of_data = 0;
- assert(has_by_data || this_frequency);
+ assert(has_by_hour || this_frequency);
@@ -1238,3 +1263,3 @@ int next_hour(struct icalrecur_iterator_impl* impl)
- if( has_by_data ){
+ if( has_by_hour ){
/* Ignore the frequency and use the byrule data */
@@ -1253,3 +1278,3 @@ int next_hour(struct icalrecur_iterator_impl* impl)
- } else if( !has_by_data && this_frequency ){
+ } else if( !has_by_hour && this_frequency ){
/* Compute the next value from the last time and the frequency interval*/
@@ -1262,3 +1287,3 @@ int next_hour(struct icalrecur_iterator_impl* impl)
- if(has_by_data && end_of_data && this_frequency ){
+ if(has_by_hour && end_of_data && this_frequency ){
increment_monthday(impl,1);
@@ -1270,9 +1295,9 @@ int next_hour(struct icalrecur_iterator_impl* impl)
-int next_day(struct icalrecur_iterator_impl* impl)
+static int next_day(icalrecur_iterator* impl)
{
- short has_by_data = (impl->by_ptrs[BY_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX);
- short this_frequency = (impl->rule.freq == ICAL_DAILY_RECURRENCE);
+ int has_by_day = (impl->by_ptrs[BY_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ int this_frequency = (impl->rule.freq == ICAL_DAILY_RECURRENCE);
- assert(has_by_data || this_frequency);
+ assert(has_by_day || this_frequency);
@@ -1298,10 +1323,10 @@ int next_day(struct icalrecur_iterator_impl* impl)
-int next_yearday(struct icalrecur_iterator_impl* impl)
+static int next_yearday(icalrecur_iterator* impl)
{
- short has_by_data = (impl->by_ptrs[BY_YEAR_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX);
+ int has_by_yearday = (impl->by_ptrs[BY_YEAR_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX);
- short end_of_data = 0;
+ int end_of_data = 0;
- assert(has_by_data );
+ assert(has_by_yearday );
@@ -1323,3 +1348,3 @@ int next_yearday(struct icalrecur_iterator_impl* impl)
- if(has_by_data && end_of_data){
+ if(has_by_yearday && end_of_data){
increment_year(impl,1);
@@ -1331,58 +1356,11 @@ int next_yearday(struct icalrecur_iterator_impl* impl)
-/* This routine is only called by next_week. It is certain that BY_DAY
-has data */
-
-int next_weekday_by_week(struct icalrecur_iterator_impl* impl)
-{
-
- short end_of_data = 0;
- short start_of_week, dow;
- struct icaltimetype next;
-
- if (next_hour(impl) == 0){
- return 0;
- }
-
- assert( impl->by_ptrs[BY_DAY][0]!=ICAL_RECURRENCE_ARRAY_MAX);
-
- while(1) {
-
- impl->by_indices[BY_DAY]++; /* Look at next elem in BYDAY array */
-
- /* Are we at the end of the BYDAY array? */
- if (impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]]
- ==ICAL_RECURRENCE_ARRAY_MAX){
-
- impl->by_indices[BY_DAY] = 0; /* Reset to 0 */
- end_of_data = 1; /* Signal that we're at the end */
- }
-
- /* Add the day of week offset to to the start of this week, and use
- that to get the next day */
- dow = impl->by_ptrs[BY_DAY][impl->by_indices[BY_DAY]];
- start_of_week = icaltime_start_doy_of_week(impl->last);
-
- dow--; /*Sun is 1, not 0 */
-
- if(dow+start_of_week <1 && !end_of_data){
- /* The selected date is in the previous year. */
- continue;
- }
-
- next = icaltime_from_day_of_year(start_of_week + dow,impl->last.year);
-
- impl->last.day = next.day;
- impl->last.month = next.month;
- impl->last.year = next.year;
-
- return end_of_data;
- }
-}
+/* Returns the day of the month for the current month of t that is the
+ pos'th instance of the day-of-week dow */
-int nth_weekday(short dow, short pos, struct icaltimetype t){
+static int nth_weekday(int dow, int pos, struct icaltimetype t){
- short days_in_month = icaltime_days_in_month(t.month,t.year);
- short end_dow, start_dow;
- short wd;
+ int days_in_month = icaltime_days_in_month(t.month, t.year);
+ int end_dow, start_dow;
+ int wd;
@@ -1430,4 +1408,21 @@ int nth_weekday(short dow, short pos, struct icaltimetype t){
+static int is_day_in_byday(icalrecur_iterator* impl,struct icaltimetype tt){
+
+ int idx;
-int next_month(struct icalrecur_iterator_impl* impl)
+ for(idx = 0; BYDAYPTR[idx] != ICAL_RECURRENCE_ARRAY_MAX; idx++){
+ int dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[idx]);
+ int pos = icalrecurrencetype_day_position(BYDAYPTR[idx]);
+ int this_dow = icaltime_day_of_week(tt);
+
+ if( (pos == 0 && dow == this_dow ) || /* Just a dow, like "TU" or "FR" */
+ (nth_weekday(dow,pos,tt) == tt.day)){ /*pos+wod: "3FR" or -1TU" */
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static int next_month(icalrecur_iterator* impl)
{
@@ -1435,3 +1430,3 @@ int next_month(struct icalrecur_iterator_impl* impl)
- short this_frequency = (impl->rule.freq == ICAL_MONTHLY_RECURRENCE);
+ int this_frequency = (impl->rule.freq == ICAL_MONTHLY_RECURRENCE);
@@ -1447,10 +1442,13 @@ int next_month(struct icalrecur_iterator_impl* impl)
-
/* Now iterate through the occurrences within a month -- by days,
weeks or weekdays. */
+
+ /*
+ * Case 1:
+ * Rules Like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR;BYMONTHDAY=13
+ */
if(has_by_data(impl,BY_DAY) && has_by_data(impl,BY_MONTH_DAY)){
- /* Cases like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR;BYMONTHDAY=13 */
- short day, idx,j;
- short days_in_month = icaltime_days_in_month(impl->last.month,
+ int day, idx,j;
+ int days_in_month = icaltime_days_in_month(impl->last.month,
impl->last.year);
@@ -1465,7 +1463,7 @@ int next_month(struct icalrecur_iterator_impl* impl)
for(j = 0; BYMDPTR[j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){
- short dow =
+ int dow =
icalrecurrencetype_day_day_of_week(BYDAYPTR[idx]);
- short pos = icalrecurrencetype_day_position(BYDAYPTR[idx]);
- short mday = BYMDPTR[j];
- short this_dow;
+ int pos = icalrecurrencetype_day_position(BYDAYPTR[idx]);
+ int mday = BYMDPTR[j];
+ int this_dow;
@@ -1490,5 +1488,9 @@ int next_month(struct icalrecur_iterator_impl* impl)
-
+
+ /*
+ * Case 2:
+ * Rules Like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR
+ */
+
} else if(has_by_data(impl,BY_DAY)){
- /* Cases like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR */
/* For this case, the weekdays are relative to the
@@ -1496,27 +1498,18 @@ int next_month(struct icalrecur_iterator_impl* impl)
- short day, idx;
- short days_in_month = icaltime_days_in_month(impl->last.month,
- impl->last.year);
+ /* This code iterates through the remaining days in the month
+ and checks if each day is listed in the BY_DAY array. This
+ seems very inneficient, but I think it is the simplest way to
+ account for both BYDAY=1FR (First friday in month) and
+ BYDAY=FR ( every friday in month ) */
+ int day;
+ int days_in_month = icaltime_days_in_month(impl->last.month,
+ impl->last.year);
assert( BYDAYPTR[0]!=ICAL_RECURRENCE_ARRAY_MAX);
- /* Iterate through the remaining days in the month and check if
- each day is listed in the BY_DAY array. This seems very
- inneficient, but I think it is the simplest way to account
- for both BYDAY=1FR (First friday in month) and BYDAY=FR (
- every friday in month ) */
-
for(day = impl->last.day+1; day <= days_in_month; day++){
- for(idx = 0; BYDAYPTR[idx] != ICAL_RECURRENCE_ARRAY_MAX; idx++){
- short dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[idx]);
- short pos = icalrecurrencetype_day_position(BYDAYPTR[idx]);
- short this_dow;
-
- impl->last.day = day;
- this_dow = icaltime_day_of_week(impl->last);
-
- if( (pos == 0 && dow == this_dow ) ||
- (nth_weekday(dow,pos,impl->last) == day)){
- goto DEND;
- }
+ impl->last.day = day;
+ if(is_day_in_byday(impl,impl->last)){
+ data_valid = 1;
+ break;
}
@@ -1524,4 +1517,2 @@ int next_month(struct icalrecur_iterator_impl* impl)
- DEND:
-
if ( day > days_in_month){
@@ -1529,8 +1520,21 @@ int next_month(struct icalrecur_iterator_impl* impl)
increment_month(impl);
- data_valid = 0; /* signal that impl->last is invalid */
+
+ /* Did moving to the next month put us on a valid date? if
+ so, note that the new data is valid, if, not, mark it
+ invalid */
+
+ if(is_day_in_byday(impl,impl->last)){
+ data_valid = 1;
+ } else {
+ data_valid = 0; /* signal that impl->last is invalid */
+ }
}
+ /*
+ * Case 3
+ * Rules Like: FREQ=MONTHLY;COUNT=10;BYMONTHDAY=-3
+ */
+
} else if (has_by_data(impl,BY_MONTH_DAY)) {
- /* Cases like: FREQ=MONTHLY;COUNT=10;BYMONTHDAY=-3 */
- short day;
+ int day;
@@ -1550,4 +1554,3 @@ int next_month(struct icalrecur_iterator_impl* impl)
if (day < 0) {
- day = icaltime_days_in_month(impl->last.month,impl->last.year)+
- day + 1;
+ day = icaltime_days_in_month(impl->last.month, impl->last.year) + day + 1;
}
@@ -1560,3 +1563,3 @@ int next_month(struct icalrecur_iterator_impl* impl)
- return data_valid; /* Signal that the data is valid */
+ return data_valid;
@@ -1564,10 +1567,64 @@ int next_month(struct icalrecur_iterator_impl* impl)
+static int next_weekday_by_week(icalrecur_iterator* impl)
+{
+
+ int end_of_data = 0;
+ int start_of_week, dow;
+ struct icaltimetype next;
+
+ if (next_hour(impl) == 0){
+ return 0;
+ }
+
+ if(!has_by_data(impl,BY_DAY)){
+ return 1;
+ }
+
+ /* If we get here, we need to step to tne next day */
+
+ for (;;) {
+ struct icaltimetype tt = icaltime_null_time();
+ BYDAYIDX++; /* Look at next elem in BYDAY array */
+
+ /* Are we at the end of the BYDAY array? */
+ if (BYDAYPTR[BYDAYIDX]==ICAL_RECURRENCE_ARRAY_MAX){
+ BYDAYIDX = 0; /* Reset to 0 */
+ end_of_data = 1; /* Signal that we're at the end */
+ }
+
+ /* Add the day of week offset to to the start of this week, and use
+ that to get the next day */
+ /* ignore position of dow ("4FR"), only use dow ("FR")*/
+ dow = icalrecurrencetype_day_day_of_week(BYDAYPTR[BYDAYIDX]);
+ tt.year = impl->last.year;
+ tt.day = impl->last.day;
+ tt.month = impl->last.month;
+
+ start_of_week = icaltime_start_doy_of_week(tt);
+
+ dow--; /* Set Sunday to be 0 */
+
+ if(dow+start_of_week <1){
+ /* The selected date is in the previous year. */
+ if(!end_of_data){
+ continue;
+ }
+ }
+
+ next = icaltime_from_day_of_year(start_of_week + dow,impl->last.year);
+
+ impl->last.day = next.day;
+ impl->last.month = next.month;
+ impl->last.year = next.year;
+
+ return end_of_data;
+ }
+
+}
-int next_week(struct icalrecur_iterator_impl* impl)
+static int next_week(icalrecur_iterator* impl)
{
- short has_by_data = (impl->by_ptrs[BY_WEEK_NO][0]!=ICAL_RECURRENCE_ARRAY_MAX);
- short this_frequency = (impl->rule.freq == ICAL_WEEKLY_RECURRENCE);
- short end_of_data = 0;
+ int end_of_data = 0;
- /* Increment to the next week day */
+ /* Increment to the next week day, if there is data at a level less than a week */
if (next_weekday_by_week(impl) == 0){
@@ -1579,4 +1636,4 @@ int next_week(struct icalrecur_iterator_impl* impl)
-
- if( has_by_data){
+ if( has_by_data(impl,BY_WEEK_NO)){
+ /*FREQ=WEEKLY;BYWEEK=20*/
/* Use the Week Number byrule data */
@@ -1604,4 +1661,4 @@ int next_week(struct icalrecur_iterator_impl* impl)
- } else if( !has_by_data && this_frequency ){
- /* If there is no BY_WEEK_NO data, just jump forward 7 days. */
+ } else {
+ /* Jump to the next week */
increment_monthday(impl,7*impl->rule.interval);
@@ -1609,4 +1666,3 @@ int next_week(struct icalrecur_iterator_impl* impl)
-
- if(has_by_data && end_of_data && this_frequency ){
+ if( has_by_data(impl,BY_WEEK_NO) && end_of_data){
increment_year(impl,1);
@@ -1618,4 +1674,4 @@ int next_week(struct icalrecur_iterator_impl* impl)
-/* Expand the BYDAY rule part and return a pointer to a newly allocated list of days. */
-pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
+/** Expand the BYDAY rule part and return a pointer to a newly allocated list of days. */
+static pvl_list expand_by_day(icalrecur_iterator* impl, int year)
{
@@ -1625,3 +1681,3 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
- short start_dow, end_dow, end_year_day, start_doy;
+ int start_dow, end_dow, end_year_day;
struct icaltimetype tmp = impl->last;
@@ -1633,10 +1689,10 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
+ /* Find the day that 1st Jan falls on, 1 (Sun) to 7 (Sat). */
start_dow = icaltime_day_of_week(tmp);
- start_doy = icaltime_start_doy_of_week(tmp);
/* Get the last day of the year*/
- tmp.year++;
- tmp = icaltime_normalize(tmp);
- tmp.day--;
- tmp = icaltime_normalize(tmp);
+ tmp.year= year;
+ tmp.month = 12;
+ tmp.day = 31;
+ tmp.is_date = 1;
@@ -1646,5 +1702,6 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
for(i = 0; BYDAYPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){
- short dow =
+ /* This is 1 (Sun) to 7 (Sat). */
+ int dow =
icalrecurrencetype_day_day_of_week(BYDAYPTR[i]);
- short pos = icalrecurrencetype_day_position(BYDAYPTR[i]);
+ int pos = icalrecurrencetype_day_position(BYDAYPTR[i]);
@@ -1654,12 +1711,9 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
days of the year with this day-of-week*/
- int week;
- for(week = 0; week < 52 ; week ++){
- short doy = start_doy + (week * 7) + dow-1;
+ int doy, tmp_start_doy;
- if(doy > end_year_day){
- break;
- } else {
+ tmp_start_doy = ((dow + 7 - start_dow) % 7) + 1;
+
+ for (doy = tmp_start_doy; doy <= end_year_day; doy += 7)
pvl_push(days_list,(void*)(int)doy);
- }
- }
+
} else if ( pos > 0) {
@@ -1673,3 +1727,3 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
- /* THen just multiple the position times 7 to get the pos'th day in the year */
+ /* Then just multiple the position times 7 to get the pos'th day in the year */
pvl_push(days_list,(void*)(first+ (pos-1) * 7));
@@ -1698,3 +1752,3 @@ pvl_list expand_by_day(struct icalrecur_iterator_impl* impl,short year)
-int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
+static int expand_year_days(icalrecur_iterator* impl, int year)
{
@@ -1705,3 +1759,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- t = icaltime_null_time();
+ t = icaltime_null_date();
@@ -1709,7 +1763,8 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- t.is_date = 1; /* Needed to make day_of_year routines work property */
-
- memset(&t,0,sizeof(t));
memset(impl->days,ICAL_RECURRENCE_ARRAY_MAX_BYTE,sizeof(impl->days));
+ /* The flags and the following switch statement select which code
+ to use to expand the yers days, based on which BY-rules are
+ present. */
+
flags = (HBD(BY_DAY) ? 1<<BY_DAY : 0) +
@@ -1725,3 +1780,7 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
/* FREQ=YEARLY; */
+ t = impl->dtstart;
+ t.year = impl->last.year;
+ impl->days[days_index++] = (short)icaltime_day_of_year(t);
+
break;
@@ -1732,5 +1791,4 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(j=0;impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){
- struct icaltimetype t;
- short month = impl->by_ptrs[BY_MONTH][j];
- short doy;
+ int month = impl->by_ptrs[BY_MONTH][j];
+ int doy;
@@ -1743,3 +1801,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- impl->days[days_index++] = doy;
+ impl->days[days_index++] = (short)doy;
@@ -1753,4 +1811,4 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
{
- short month_day = impl->by_ptrs[BY_MONTH_DAY][k];
- short doy;
+ int month_day = impl->by_ptrs[BY_MONTH_DAY][k];
+ int doy;
@@ -1763,3 +1821,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- impl->days[days_index++] = doy;
+ impl->days[days_index++] = (short)doy;
@@ -1775,5 +1833,5 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
{
- short month = impl->by_ptrs[BY_MONTH][j];
- short month_day = impl->by_ptrs[BY_MONTH_DAY][k];
- short doy;
+ int month = impl->by_ptrs[BY_MONTH][j];
+ int month_day = impl->by_ptrs[BY_MONTH_DAY][k];
+ int doy;
@@ -1786,3 +1844,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- impl->days[days_index++] = doy;
+ impl->days[days_index++] = (short)doy;
@@ -1797,4 +1855,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- struct icaltimetype t;
- short dow;
+ int dow;
@@ -1821,3 +1878,2 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
/*FREQ=YEARLY; BYDAY=TH,20MO,-10FR*/
- int days_index = 0;
pvl_elem i;
@@ -1827,3 +1883,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(i=pvl_head(days);i!=0;i=pvl_next(i)){
- short day = (short)(int)pvl_data(i);
+ short day = (short)(*((int*)pvl_data(i)));
impl->days[days_index++] = day;
@@ -1839,27 +1895,55 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- int days_index = 0;
- pvl_elem itr;
- pvl_list days = expand_by_day(impl,year);
- for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){
- short doy = (short)(int)pvl_data(itr);
- struct icaltimetype tt;
- short j;
+ for(j=0;impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){
+ int month = impl->by_ptrs[BY_MONTH][j];
+ int days_in_month = icaltime_days_in_month(month,year);
+ int first_dow, last_dow, doy_offset;
- tt = icaltime_from_day_of_year(doy,year);
+ t.year = year;
+ t.month = month;
+ t.day = 1;
+ t.is_date = 1;
- for(j=0;
- impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX;
- j++){
- short month = impl->by_ptrs[BY_MONTH][j];
+ first_dow = icaltime_day_of_week(t);
- if(tt.month == month){
- impl->days[days_index++] = doy;
- }
- }
+ /* This holds the day offset used to calculate the day of the year
+ from the month day. Just add the month day to this. */
+ doy_offset = icaltime_day_of_year(t) - 1;
- }
+ t.day = days_in_month;
+ last_dow = icaltime_day_of_week(t);
- pvl_free(days);
+ for(k=0;impl->by_ptrs[BY_DAY][k]!=ICAL_RECURRENCE_ARRAY_MAX;k++){
+ short day_coded = impl->by_ptrs[BY_DAY][k];
+ enum icalrecurrencetype_weekday dow =
+ icalrecurrencetype_day_day_of_week(day_coded);
+ int pos = icalrecurrencetype_day_position(day_coded);
+ int first_matching_day, last_matching_day, day, month_day;
+
+ /* Calculate the first day in the month with the given weekday,
+ and the last day. */
+ first_matching_day = ((dow + 7 - first_dow) % 7) + 1;
+ last_matching_day = days_in_month - ((last_dow + 7 - dow) % 7);
+
+ if (pos == 0) {
+ /* Add all of instances of the weekday within the month. */
+ for (day = first_matching_day; day <= days_in_month; day += 7)
+ impl->days[days_index++] = (short)(doy_offset + day);
+
+ } else if (pos > 0) {
+ /* Add the nth instance of the weekday within the month. */
+ month_day = first_matching_day + (pos - 1) * 7;
+
+ if (month_day <= days_in_month)
+ impl->days[days_index++] = (short)(doy_offset + month_day);
+ } else {
+ /* Add the -nth instance of the weekday within the month.*/
+ month_day = last_matching_day + (pos + 1) * 7;
+
+ if (month_day > 0)
+ impl->days[days_index++] = (short)(doy_offset + month_day);
+ }
+ }
+ }
break;
@@ -1870,3 +1954,2 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- int days_index = 0;
pvl_elem itr;
@@ -1875,5 +1958,4 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){
- short day = (short)(int)pvl_data(itr);
+ short day = (short)(*((int*)pvl_data(itr)));
struct icaltimetype tt;
- short j;
@@ -1882,3 +1964,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(j = 0; BYMDPTR[j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){
- short mday = BYMDPTR[j];
+ int mday = BYMDPTR[j];
@@ -1899,3 +1981,2 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- int days_index = 0;
pvl_elem itr;
@@ -1904,5 +1985,5 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){
- short day = (short)(int)pvl_data(itr);
+ short day = (short)(*((int*)pvl_data(itr)));
struct icaltimetype tt;
- short i,j;
+ int i;
@@ -1912,4 +1993,4 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(j = 0; BYMDPTR[j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){
- short mday = BYMDPTR[j];
- short month = BYMONPTR[i];
+ int mday = BYMDPTR[j];
+ int month = BYMONPTR[i];
@@ -1932,3 +2013,2 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
- int days_index = 0;
pvl_elem itr;
@@ -1937,5 +2017,5 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(itr=pvl_head(days);itr!=0;itr=pvl_next(itr)){
- short day = (short)(int)pvl_data(itr);
+ short day = (short)(*((int*)pvl_data(itr)));
struct icaltimetype tt;
- short i;
+ int i;
@@ -1944,5 +2024,5 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(i = 0; BYWEEKPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){
- short weekno = BYWEEKPTR[i];
-
- if(weekno== icaltime_week_number(tt)){
+ int weekno = BYWEEKPTR[i];
+ int this_weekno = icaltime_week_number(tt);
+ if(weekno== this_weekno){
impl->days[days_index++] = day;
@@ -1965,4 +2045,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
for(j=0;impl->by_ptrs[BY_YEAR_DAY][j]!=ICAL_RECURRENCE_ARRAY_MAX;j++){
- short doy = impl->by_ptrs[BY_YEAR_DAY][j];
- impl->days[days_index++] = doy;
+ impl->days[days_index++] = impl->by_ptrs[BY_YEAR_DAY][j];
}
@@ -1982,3 +2061,3 @@ int expand_year_days(struct icalrecur_iterator_impl* impl,short year)
-int next_year(struct icalrecur_iterator_impl* impl)
+static int next_year(icalrecur_iterator* impl)
{
@@ -1986,5 +2065,4 @@ int next_year(struct icalrecur_iterator_impl* impl)
- /* Next_year does it's own interatio in days, so the next level down is hours */
if (next_hour(impl) == 0){
- return 1;
+ return 0;
}
@@ -1993,11 +2071,12 @@ int next_year(struct icalrecur_iterator_impl* impl)
impl->days_index = 0;
+
+ for (;;) {
increment_year(impl,impl->rule.interval);
expand_year_days(impl,impl->last.year);
+ if (impl->days[0] != ICAL_RECURRENCE_ARRAY_MAX)
+ break;
}
-
- if(impl->days[0] == ICAL_RECURRENCE_ARRAY_MAX) {
- return 0;
}
- next = icaltime_from_day_of_year(impl->days[impl->days_index],impl->last.year);
+ next = icaltime_from_day_of_year(impl->days[impl->days_index], impl->last.year);
@@ -2009,4 +2088,4 @@ int next_year(struct icalrecur_iterator_impl* impl)
-int icalrecur_check_rulepart(struct icalrecur_iterator_impl* impl,
- short v, enum byrule byrule)
+int icalrecur_check_rulepart(icalrecur_iterator* impl,
+ int v, enum byrule byrule)
{
@@ -2025,4 +2104,4 @@ int icalrecur_check_rulepart(struct icalrecur_iterator_impl* impl,
-int check_contract_restriction(struct icalrecur_iterator_impl* impl,
- enum byrule byrule, short v)
+static int check_contract_restriction(icalrecur_iterator* impl,
+ enum byrule byrule, int v)
{
@@ -2050,18 +2129,18 @@ int check_contract_restriction(struct icalrecur_iterator_impl* impl,
-int check_contracting_rules(struct icalrecur_iterator_impl* impl)
+static int check_contracting_rules(icalrecur_iterator* impl)
{
- int day_of_week=0;
- int week_no=0;
- int year_day=0;
+ int day_of_week = icaltime_day_of_week(impl->last);
+ int week_no = icaltime_week_number(impl->last);
+ int year_day = icaltime_day_of_year(impl->last);
if (
- check_contract_restriction(impl,BY_SECOND,impl->last.second) &&
- check_contract_restriction(impl,BY_MINUTE,impl->last.minute) &&
- check_contract_restriction(impl,BY_HOUR,impl->last.hour) &&
- check_contract_restriction(impl,BY_DAY,day_of_week) &&
- check_contract_restriction(impl,BY_WEEK_NO,week_no) &&
- check_contract_restriction(impl,BY_MONTH_DAY,impl->last.day) &&
- check_contract_restriction(impl,BY_MONTH,impl->last.month) &&
- check_contract_restriction(impl,BY_YEAR_DAY,year_day) )
+ check_contract_restriction(impl,BY_SECOND, impl->last.second) &&
+ check_contract_restriction(impl,BY_MINUTE, impl->last.minute) &&
+ check_contract_restriction(impl,BY_HOUR, impl->last.hour) &&
+ check_contract_restriction(impl,BY_DAY, day_of_week) &&
+ check_contract_restriction(impl,BY_WEEK_NO, week_no) &&
+ check_contract_restriction(impl,BY_MONTH_DAY, impl->last.day) &&
+ check_contract_restriction(impl,BY_MONTH, impl->last.month) &&
+ check_contract_restriction(impl,BY_YEAR_DAY, year_day) )
{
@@ -2074,7 +2153,5 @@ int check_contracting_rules(struct icalrecur_iterator_impl* impl)
-struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *itr)
+struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *impl)
{
int valid = 1;
- struct icalrecur_iterator_impl* impl =
- (struct icalrecur_iterator_impl*)itr;
@@ -2122,3 +2199,3 @@ struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *itr)
case ICAL_YEARLY_RECURRENCE:{
- valid = next_year(impl);
+ next_year(impl);
break;
@@ -2137,3 +2214,3 @@ struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *itr)
} while(!check_contracting_rules(impl)
- || icaltime_compare(impl->last,impl->dtstart) <= 0
+ || icaltime_compare(impl->last,impl->dtstart) < 0
|| valid == 0);
@@ -2168,12 +2245,11 @@ void icalrecurrencetype_clear(struct icalrecurrencetype *recur)
-/* The 'day' element of icalrecurrencetype_weekday is encoded to allow
-reporesentation of both the day of the week ( Monday, Tueday), but
-also the Nth day of the week ( First tuesday of the month, last
-thursday of the year) These routines decode the day values.
-
-The day's position in the period ( Nth-ness) and the numerical value
-of the day are encoded together as: pos*7 + dow
-
-A position of 0 means 'any' or 'every'
-
+/** The 'day' element of icalrecurrencetype_weekday is encoded to
+ * allow representation of both the day of the week ( Monday, Tueday),
+ * but also the Nth day of the week ( First tuesday of the month, last
+ * thursday of the year) These routines decode the day values.
+ *
+ * The day's position in the period ( Nth-ness) and the numerical
+ * value of the day are encoded together as: pos*7 + dow
+ *
+ * A position of 0 means 'any' or 'every'
*/
@@ -2185,5 +2261,5 @@ enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day)
-short icalrecurrencetype_day_position(short day)
+int icalrecurrencetype_day_position(short day)
{
- short wd, pos;
+ int wd, pos;
@@ -2200,3 +2276,3 @@ short icalrecurrencetype_day_position(short day)
-struct {icalrecurrencetype_weekday wd; const char * str; }
+static struct {icalrecurrencetype_weekday wd; const char * str; }
wd_map[] = {
@@ -2240,3 +2316,3 @@ icalrecurrencetype_weekday icalrecur_string_to_weekday(const char* str)
-struct {
+static struct {
icalrecurrencetype_frequency kind;
@@ -2278,6 +2354,7 @@ icalrecurrencetype_frequency icalrecur_string_to_freq(const char* str)
-/* Fill an array with the 'count' number of occurrences generated by
- the rrule. Note that the times are returned in UTC, but the times
- are calculated in local time. YOu will have to convert the results
- back into local time before using them. */
+/** Fill an array with the 'count' number of occurrences generated by
+ * the rrule. Note that the times are returned in UTC, but the times
+ * are calculated in local time. YOu will have to convert the results
+ * back into local time before using them.
+ */
@@ -2294,3 +2371,3 @@ int icalrecur_expand_recurrence(char* rule, time_t start,
- icstart = icaltime_from_timet(start,0);
+ icstart = icaltime_from_timet_with_zone(start,0,0);