128#include "icalerror_p.h"
140#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
142static pthread_mutex_t invalid_rrule_mutex = PTHREAD_MUTEX_INITIALIZER;
147#if defined(HAVE_LIBICU)
148#include <unicode/ucal.h>
149#include <unicode/ustring.h>
154#undef ICAL_BY_MONTH_SIZE
155#undef ICAL_BY_WEEKNO_SIZE
156#undef ICAL_BY_YEARDAY_SIZE
158#define ICAL_BY_MONTH_SIZE 13
159#define ICAL_BY_WEEKNO_SIZE 54
160#define ICAL_BY_YEARDAY_SIZE 367
165#if defined(HAVE_LIBICU)
166#define MAX_TIME_T_YEAR 20000
168#if (SIZEOF_ICALTIME_T > 4)
171#define MAX_TIME_T_YEAR 2582
175#define MAX_TIME_T_YEAR 2037
179#define LEAP_MONTH 0x1000
184static short daymask_find_next_bit(
const unsigned long *days,
short start_index);
188static const struct freq_map {
206 if (strcasecmp(str, freq_map[i].str) == 0) {
207 return freq_map[i].kind;
218 if (freq_map[i].kind == kind) {
219 return freq_map[i].str;
225static const struct skip_map {
239 if (strcasecmp(str, skip_map[i].str) == 0) {
240 return skip_map[i].kind;
251 if (skip_map[i].kind == kind) {
252 return skip_map[i].str;
258static const struct wd_map {
276 if (wd_map[i].wd == kind) {
277 return wd_map[i].str;
289 if (strcasecmp(str, wd_map[i].str) == 0) {
299static void icalrecur_free_by(icalrecurrence_by_data *by)
308 if (by->size == size) {
313 icalrecur_free_by(by);
317 if ((by->data == NULL) || (by->size == 0)) {
318 if ((by->data != NULL) || (by->size != 0)) {
336 if (size > by->size) {
337 memset(&by->data[by->size], 0, (
size_t)(size - by->size) *
sizeof(by->data[0]));
347struct icalrecur_parser {
353 struct icalrecurrencetype *rt;
366struct expand_split_map_struct {
382static const struct expand_split_map_struct expand_map[] = {
384 {
ICAL_SECONDLY_RECURRENCE, {1, 3, 1, 1, 1, 1, 1, 1, 1}},
385 {
ICAL_MINUTELY_RECURRENCE, {1, 3, 1, 1, 1, 1, 1, 2, 1}},
386 {
ICAL_HOURLY_RECURRENCE, {1, 3, 1, 1, 1, 1, 2, 2, 1}},
387 {
ICAL_DAILY_RECURRENCE, {1, 3, 3, 1, 1, 2, 2, 2, 1}},
388 {
ICAL_WEEKLY_RECURRENCE, {1, 3, 3, 3, 2, 2, 2, 2, 1}},
389 {
ICAL_MONTHLY_RECURRENCE, {1, 3, 3, 2, 2, 2, 2, 2, 1}},
390 {
ICAL_YEARLY_RECURRENCE, {2, 2, 2, 2, 2, 2, 2, 2, 1}},
393static const struct recur_map {
399 {
"BYMONTH", ICAL_BY_MONTH_SIZE, 1, 0},
400 {
"BYWEEKNO", ICAL_BY_WEEKNO_SIZE, -1, 0},
401 {
"BYYEARDAY", ICAL_BY_YEARDAY_SIZE, -1, 0},
402 {
"BYMONTHDAY", ICAL_BY_MONTHDAY_SIZE, -1, 0},
403 {
"BYDAY", ICAL_BY_DAY_SIZE, 0, 0},
404 {
"BYHOUR", ICAL_BY_HOUR_SIZE, 0, 1},
405 {
"BYMINUTE", ICAL_BY_MINUTE_SIZE, 0, 1},
406 {
"BYSECOND", ICAL_BY_SECOND_SIZE, 0, 1},
407 {
"BYSETPOS", ICAL_BY_SETPOS_SIZE, -1, 0},
410static const char *icalrecur_first_clause(
struct icalrecur_parser *parser)
414 parser->this_clause = parser->copy;
416 idx = strchr(parser->this_clause,
';');
419 parser->next_clause = 0;
425 parser->next_clause = idx;
427 return parser->this_clause;
430static const char *icalrecur_next_clause(
struct icalrecur_parser *parser)
434 parser->this_clause = parser->next_clause;
436 if (parser->this_clause == 0) {
440 idx = strchr(parser->this_clause,
';');
443 parser->next_clause = 0;
447 parser->next_clause = idx;
450 return parser->this_clause;
453static void icalrecur_clause_name_and_value(
struct icalrecur_parser *parser,
454 char **name,
char **value)
458 *name = parser->this_clause;
460 idx = strchr(parser->this_clause,
'=');
476static void sort_byrules(icalrecurrence_by_data *by)
478 short *array = by->data;
482 for (i = 1; i < by->size; i++) {
483 for (j = i - 1; j >= 0 && array[j] > array[j + 1]; j--) {
484 short tmp = array[j + 1];
486 array[j + 1] = array[j];
496static void sort_bysetpos(icalrecurrence_by_data *by)
499#define SIGN(A) ((A) < 0 ? -1 : 1)
501 short *array = by->data;
505 for (i = 1; i < by->size; i++) {
507 j >= 0 && ((SIGN(array[j]) == SIGN(array[j + 1]) && abs(array[j]) > abs(array[j + 1])) ||
508 (array[j] < 0 && array[j + 1] > 0));
510 short tmp = array[j + 1];
512 array[j + 1] = array[j];
523static int icalrecur_add_byrules(
const struct icalrecur_parser *parser, icalrecurrence_by_data *by,
524 int min,
int size,
char *vals)
528 int max = size - (min == 0);
556 long v = strtol(t, &t_end, 10);
567 if (min >= 0 || v <= -max) {
589 by->data[i++] = (short)v;
619static void sort_bydayrules(
struct icalrecur_parser *parser)
622 short *array = by->data;
624 int week_start, i, j;
628 for (i = 0; i < by->size; i++) {
629 for (j = 0; j < i; j++) {
640 short tmp = array[j];
649static int icalrecur_add_bydayrules(
struct icalrecur_parser *parser,
670 if (idx >= by->size) {
692 const long tmpl = strtol(t, &t_end, 10);
693 weekno = (
signed char)tmpl;
697 if (weekno != tmpl) {
703 if ((weekno == 0) && (t != t_end)) {
738 sort_bydayrules(parser);
753 memset(rule, 0,
sizeof(*rule));
755 icalrecurrencetype_clear(rule);
765 icalmemory_free_buffer(p); \
772 SAFEFREE(recur->
by[i].data);
784 icalerror_check_arg_rv((recur != NULL),
"recur");
785 icalerror_check_arg_rv((recur->
refcount > 0),
"recur->refcount > 0");
792 icalerror_check_arg_rv((recur != NULL),
"recur");
793 icalerror_check_arg_rv((recur->
refcount > 0),
"recur->refcount > 0");
801 icalrecurrencetype_free(recur, 1);
804static void *icalrecur_memdup(
void *p,
size_t size,
int *error)
806 if ((p == NULL) || (size == 0)) {
812 memcpy(newp, p, size);
820static icalrecurrence_by_data icalrecur_by_dup(icalrecurrence_by_data *
by,
int *error)
822 icalrecurrence_by_data newby = {0, 0};
824 newby.data = icalrecur_memdup(
by->data, (
size_t)
by->size *
sizeof(
by->data[0]), error);
826 newby.size =
by->size;
837 icalerror_check_arg_rz((recur != NULL),
"recur");
844 memcpy(res, recur,
sizeof(*res));
856 icalrecurrence_by_data *src_by = &recur->
by[i];
857 icalrecurrence_by_data *dst_by = &res->
by[i];
858 *dst_by = icalrecur_by_dup(src_by, &error);
862 icalrecurrencetype_free(res, 1);
871 struct icalrecur_parser parser = {0};
874 icalerror_check_arg_re(str != 0,
"str", 0);
884 parser.this_clause = parser.copy;
886 if (parser.copy == 0) {
893 for (icalrecur_first_clause(&parser);
894 parser.this_clause != 0; icalrecur_next_clause(&parser)) {
898 icalrecur_clause_name_and_value(&parser, &name, &value);
901 if (strlen(parser.this_clause) > 0) {
911 }
else if (strcasecmp(name,
"FREQ") == 0) {
921 }
else if (strcasecmp(name,
"RSCALE") == 0) {
922 if (parser.rt->
rscale != NULL) {
928 }
else if (strcasecmp(name,
"SKIP") == 0) {
938 }
else if (strcasecmp(name,
"COUNT") == 0) {
943 parser.rt->
count = 0;
945 const long v = strtol(value, &v_end, 10);
946 if (value != v_end) {
947 parser.rt->
count = v;
950 if (parser.rt->
count < 1) {
954 }
else if (strcasecmp(name,
"UNTIL") == 0) {
964 }
else if (strcasecmp(name,
"INTERVAL") == 0) {
971 const long tmp = strtol(value, &v_temp, 10);
972 if (value != v_temp) {
987 }
else if (strcasecmp(name,
"WKST") == 0) {
996 sort_bydayrules(&parser);
999 }
else if (strncasecmp(name,
"BY", 2) == 0) {
1003 if (strcasecmp(name + 2, recur_map[byrule].str + 2) == 0) {
1005 r = icalrecur_add_bydayrules(&parser, value);
1007 icalrecurrence_by_data *by = &parser.rt->
by[byrule];
1008 r = icalrecur_add_byrules(&parser, by,
1009 recur_map[byrule].min,
1010 recur_map[byrule].size,
1027 icalrecurrencetype_clear(parser.rt);
1033 icalrecurrence_by_data *by = &parser.rt->
by[byrule];
1036 expand_map[parser.rt->
freq].map[byrule] == ILLEGAL) {
1042 icalrecurrencetype_clear(parser.rt);
1045 icalrecur_free_by(by);
1073 size_t buf_sz = 200;
1074 char temp[20] = {0};
1084 if (recur->
rscale != 0) {
1103 snprintf(temp,
sizeof(temp),
"%d", recur->
interval);
1118 const icalrecurrence_by_data *by = &recur->
by[j];
1126 int limit = recur_map[j].size - 1;
1127 for (i = 0; i < limit && i < by->size; i++) {
1136 snprintf(temp,
sizeof(temp),
"%d%s", pos, daystr);
1142 snprintf(temp,
sizeof(temp),
"%dL",
1146 snprintf(temp,
sizeof(temp),
"%d", by->data[i]);
1150 if ((i + 1) < limit && by->size > i + 1) {
1160 print_date_to_string(temp, &recur->
until);
1162 print_datetime_to_string(temp, &recur->
until);
1169 else if (recur->
count != 0) {
1170 snprintf(temp,
sizeof(temp),
"%d", recur->
count);
1182#define BITS_PER_LONG ((unsigned short)(8 * sizeof(unsigned long)))
1185#define LONGS_PER_BITS(n) (((n) + BITS_PER_LONG - 1) / BITS_PER_LONG)
1187#define ICAL_YEARDAYS_MASK_SIZE (ICAL_BY_YEARDAY_SIZE + 7)
1188#define ICAL_YEARDAYS_MASK_OFFSET 4
1191typedef struct icalrecurrence_iterator_by_data {
1192 icalrecurrence_by_data by;
1199} icalrecurrence_iterator_by_data;
1201struct icalrecur_iterator_impl {
1202 struct icaltimetype dtstart;
1203 struct icalrecurrencetype *rule;
1205 struct icaltimetype rstart;
1206 struct icaltimetype istart;
1207 struct icaltimetype iend;
1208 struct icaltimetype last;
1209 int32_t occurrence_no;
1212 int32_t recurrence_set_size;
1213 short sp_idxp, sp_idxn;
1216#if defined(HAVE_LIBICU)
1221 struct icaltimetype period_start;
1235 unsigned long days[LONGS_PER_BITS(ICAL_YEARDAYS_MASK_SIZE)];
1242static void daysmask_clearall(
unsigned long mask[])
1245 sizeof(
unsigned long) * LONGS_PER_BITS(ICAL_YEARDAYS_MASK_SIZE));
1249#if defined(UNDEFINED_SANITIZER) && defined(__clang__)
1250 __attribute__((no_sanitize(
"integer")))
1252 unsigned long makeMask(
unsigned long mask,
int leftshift)
1254 return mask << leftshift;
1258static bool daysmask_in_range(
int n)
1260 return n >= -ICAL_YEARDAYS_MASK_OFFSET && n < ICAL_YEARDAYS_MASK_SIZE;
1263static void daysmask_set_range(
unsigned long days[],
int fromDayIncl,
int untilDayExcl,
int v)
1265 if (fromDayIncl < -ICAL_YEARDAYS_MASK_OFFSET) {
1266 fromDayIncl = -ICAL_YEARDAYS_MASK_OFFSET;
1268 if (untilDayExcl > ICAL_YEARDAYS_MASK_SIZE) {
1269 untilDayExcl = ICAL_YEARDAYS_MASK_SIZE;
1271 if (fromDayIncl >= untilDayExcl) {
1275 int fromBitIdx = fromDayIncl + ICAL_YEARDAYS_MASK_OFFSET;
1276 int untilBitIdx = untilDayExcl + ICAL_YEARDAYS_MASK_OFFSET;
1278 for (
int word_idx = fromBitIdx / BITS_PER_LONG;
1279 word_idx < (int)((untilBitIdx + BITS_PER_LONG - 1) / BITS_PER_LONG);
1281 int lowerBitIdxIncl = (fromBitIdx <= (int)(word_idx * BITS_PER_LONG))
1283 : (fromBitIdx - (int)(word_idx * BITS_PER_LONG));
1284 int upperBitIdxExcl = (untilBitIdx >= (int)((word_idx + 1) * BITS_PER_LONG))
1285 ? (int)BITS_PER_LONG
1286 : (int)(untilBitIdx - (int)(word_idx * BITS_PER_LONG));
1288 unsigned long mask = (
unsigned long)-1;
1289 if (lowerBitIdxIncl > 0) {
1290 mask &= makeMask(((
unsigned long)-1), lowerBitIdxIncl);
1292 if ((upperBitIdxExcl > 0) && (upperBitIdxExcl < (
int)BITS_PER_LONG)) {
1293 mask &= ((
unsigned long)-1) >> (BITS_PER_LONG - upperBitIdxExcl);
1297 days[word_idx] |= mask;
1299 days[word_idx] &= ~mask;
1305static int daysmask_setbit(
unsigned long mask[],
int n,
int v)
1309 if (!daysmask_in_range(n)) {
1313 n += ICAL_YEARDAYS_MASK_OFFSET;
1316 prev = (mask[n / BITS_PER_LONG] & (1UL << (n % BITS_PER_LONG))) ? 1 : 0;
1318 prev = (mask[n / BITS_PER_LONG] & (1UL >> (-n % BITS_PER_LONG))) ? 1 : 0;
1323 mask[n / BITS_PER_LONG] |= (1UL << (n % BITS_PER_LONG));
1325 mask[n / BITS_PER_LONG] |= (1UL >> (-n % BITS_PER_LONG));
1329 mask[n / BITS_PER_LONG] &= ~(1UL << (n % BITS_PER_LONG));
1331 mask[n / BITS_PER_LONG] &= ~(1UL >> (-n % BITS_PER_LONG));
1339static unsigned long daysmask_getbit(
const unsigned long mask[],
int n)
1341 if (!daysmask_in_range(n)) {
1345 n += ICAL_YEARDAYS_MASK_OFFSET;
1346 return (mask[n / BITS_PER_LONG] >> (n % BITS_PER_LONG)) & 1;
1350static void daysmask_add_day(icalrecur_iterator *impl,
int doy)
1352 if (!daysmask_in_range(doy)) {
1356 daysmask_setbit(impl->days, doy, 1);
1357 if (doy < impl->days_index) {
1358 impl->days_index = (short)doy;
1364 return (impl->bydata[byrule].orig_data == 1);
1367static void recur_iterator_set_static_single_by_value(icalrecur_iterator *impl,
1370 icalrecurrence_iterator_by_data *by = &impl->bydata[byrule];
1372 by->by.data = &by->buffer_value;
1373 by->by.data[0] = value;
1376static void setup_defaults(icalrecur_iterator *impl,
1381 if (impl->dtstart.is_date && recur_map[byrule].isTime) {
1387 recur_iterator_set_static_single_by_value(impl, byrule, 0);
1388 }
else if (expand_map[freq].map[byrule] == EXPAND) {
1391 if (impl->bydata[byrule].by.size == 0) {
1392 recur_iterator_set_static_single_by_value(impl, byrule, (
short)deftime);
1405 int pos = (dow - (int)week_start + 7) % 7;
1408 return (52 + is_long);
1417static void __get_start_time(icalrecur_iterator *impl,
icaltimetype date,
1427 *
hour = impl->rstart.hour;
1435 *
minute = impl->rstart.minute;
1443 *
second = impl->rstart.second;
1449#if defined(HAVE_LIBICU)
1467 UErrorCode status = U_ZERO_ERROR;
1469 icalarray *calendars;
1474 en = ucal_getKeywordValuesForLocale(
"calendar",
"",
false, &status);
1475 while ((cal = uenum_next(en, NULL, &status))) {
1484static void set_second(icalrecur_iterator *impl,
int second)
1486 ucal_set(impl->rscale, UCAL_SECOND, (int32_t)
second);
1489static void set_minute(icalrecur_iterator *impl,
int minute)
1491 ucal_set(impl->rscale, UCAL_MINUTE, (int32_t)
minute);
1494static void set_hour(icalrecur_iterator *impl,
int hour)
1496 ucal_set(impl->rscale, UCAL_HOUR_OF_DAY, (int32_t)
hour);
1499static void __set_month(icalrecur_iterator *impl,
int month)
1505 ucal_set(impl->rscale, UCAL_MONTH, (int32_t)
month);
1506 if (is_leap_month) {
1507 ucal_set(impl->rscale, UCAL_IS_LEAP_MONTH, 1);
1511static int set_month(icalrecur_iterator *impl,
int month)
1513 UErrorCode status = U_ZERO_ERROR;
1516 __set_month(impl,
month);
1518 ucal_set(impl->rscale, UCAL_DAY_OF_MONTH, (int32_t)1);
1521 (int)ucal_get(impl->rscale, UCAL_MONTH, &status);
1523 if (ucal_get(impl->rscale, UCAL_IS_LEAP_MONTH, &status)) {
1524 actual_month |= LEAP_MONTH;
1527 if (actual_month !=
month) {
1528 switch (impl->rule->skip) {
1538 ucal_add(impl->rscale, UCAL_MONTH, (int32_t)-1, &status);
1548 (
int)ucal_get(impl->rscale, UCAL_MONTH, &status));
1551static int get_months_in_year(icalrecur_iterator *impl,
int year)
1553 UErrorCode status = U_ZERO_ERROR;
1556 ucal_set(impl->rscale, UCAL_YEAR, (int32_t)
year);
1560 (
int)ucal_getLimit(impl->rscale, UCAL_MONTH,
1561 UCAL_ACTUAL_MAXIMUM, &status));
1564static int get_days_in_year(icalrecur_iterator *impl,
int year)
1566 UErrorCode status = U_ZERO_ERROR;
1569 ucal_set(impl->rscale, UCAL_YEAR, (int32_t)
year);
1572 return (
int)ucal_getLimit(impl->rscale, UCAL_DAY_OF_YEAR,
1573 UCAL_ACTUAL_MAXIMUM, &status);
1576static void set_day_of_year(icalrecur_iterator *impl,
int doy)
1579 doy += get_days_in_year(impl, 0);
1582 ucal_set(impl->rscale, UCAL_DAY_OF_YEAR, (int32_t)doy);
1585static int get_start_of_week(icalrecur_iterator *impl)
1587 UErrorCode status = U_ZERO_ERROR;
1590 doy = (int)ucal_get(impl->rscale, UCAL_DAY_OF_YEAR, &status);
1591 dow = (int)ucal_get(impl->rscale, UCAL_DAY_OF_WEEK, &status);
1592 dow -= (int)impl->rule->week_start;
1600static int get_day_of_week(icalrecur_iterator *impl)
1602 UErrorCode status = U_ZERO_ERROR;
1604 return (
int)ucal_get(impl->rscale, UCAL_DAY_OF_WEEK, &status);
1607static int get_week_number(icalrecur_iterator *impl,
struct icaltimetype tt)
1609 UErrorCode status = U_ZERO_ERROR;
1614 last_millis = ucal_getMillis(impl->rscale, &status);
1617 ucal_setDate(impl->rscale,
1618 (int32_t)tt.
year, (int32_t)
month, (int32_t)tt.
day, &status);
1620 ucal_set(impl->rscale, UCAL_IS_LEAP_MONTH, 1);
1623 weekno = (int)ucal_get(impl->rscale, UCAL_WEEK_OF_YEAR, &status);
1626 ucal_setMillis(impl->rscale, last_millis, &status);
1631static int get_days_in_month(icalrecur_iterator *impl,
int month,
int year)
1633 UErrorCode status = U_ZERO_ERROR;
1635 ucal_set(impl->rscale, UCAL_YEAR, (int32_t)
year);
1638 month = impl->rstart.month;
1640 __set_month(impl,
month);
1642 return (
int)ucal_getLimit(impl->rscale,
1643 UCAL_DAY_OF_MONTH, UCAL_ACTUAL_MAXIMUM, &status);
1646static void prepare_rscale_adjusted(icalrecur_iterator *impl,
1649 ucal_set(impl->rscale, UCAL_YEAR, (int32_t)
year);
1652 month = impl->rstart.month;
1654 __set_month(impl,
month);
1657 day = impl->rstart.day;
1658 }
else if (
day < 0) {
1659 day += 1 + (int)ucal_getLimit(impl->rscale, UCAL_DAY_OF_MONTH,
1660 UCAL_ACTUAL_MAXIMUM, status);
1662 ucal_set(impl->rscale, UCAL_DAY_OF_MONTH, (int32_t)
day);
1665static int get_day_of_year(icalrecur_iterator *impl,
1668 UErrorCode status = U_ZERO_ERROR;
1669 prepare_rscale_adjusted(impl,
year,
month,
day, &status);
1670 return (
int)ucal_get(impl->rscale, UCAL_DAY_OF_YEAR, &status);
1673static int get_day_of_week_adjusted(icalrecur_iterator *impl,
1676 UErrorCode status = U_ZERO_ERROR;
1677 prepare_rscale_adjusted(impl,
year,
month,
day, &status);
1678 return (
int)ucal_get(impl->rscale, UCAL_DAY_OF_WEEK, &status);
1681static struct icaltimetype occurrence_as_icaltime(icalrecur_iterator *impl,
1685 UErrorCode status = U_ZERO_ERROR;
1686 UCalendar *cal = impl->rscale;
1687 int is_leap_month = 0;
1689 if (normalize && (impl->rscale != impl->greg)) {
1691 UDate millis = ucal_getMillis(impl->rscale, &status);
1693 ucal_setMillis(impl->greg, millis, &status);
1697 (int)ucal_get(impl->rscale, UCAL_IS_LEAP_MONTH, &status);
1700 tt.
year = (int)ucal_get(cal, UCAL_YEAR, &status);
1701 tt.
day = (int)ucal_get(cal, UCAL_DATE, &status);
1703 (int)ucal_get(cal, UCAL_MONTH, &status);
1704 if (is_leap_month) {
1705 tt.
month |= LEAP_MONTH;
1709 tt.
hour = (int)ucal_get(cal, UCAL_HOUR_OF_DAY, &status);
1710 tt.
minute = (int)ucal_get(cal, UCAL_MINUTE, &status);
1711 tt.
second = (int)ucal_get(cal, UCAL_SECOND, &status);
1717static struct icaltimetype __icaltime_from_day_of_year(icalrecur_iterator *impl,
1718 int day,
int year,
int *weekno)
1720 ucal_set(impl->rscale, UCAL_YEAR, (int32_t)
year);
1722 day += get_days_in_year(impl, 0) + 1;
1725 ucal_set(impl->rscale, UCAL_DAY_OF_YEAR, (int32_t)
day);
1728 UErrorCode status = U_ZERO_ERROR;
1730 *weekno = (int)ucal_get(impl->rscale, UCAL_WEEK_OF_YEAR, &status);
1733 return occurrence_as_icaltime(impl, 0);
1736static void increment_year(icalrecur_iterator *impl,
int inc)
1738 UErrorCode status = U_ZERO_ERROR;
1740 ucal_add(impl->rscale, UCAL_YEAR, (int32_t)inc, &status);
1743static void __increment_month(icalrecur_iterator *impl,
int inc)
1745 UErrorCode status = U_ZERO_ERROR;
1747 ucal_add(impl->rscale, UCAL_MONTH, (int32_t)inc, &status);
1750static void increment_monthday(icalrecur_iterator *impl,
int inc)
1752 UErrorCode status = U_ZERO_ERROR;
1754 ucal_add(impl->rscale, UCAL_DAY_OF_MONTH, (int32_t)inc, &status);
1757static void increment_hour(icalrecur_iterator *impl,
int inc)
1759 UErrorCode status = U_ZERO_ERROR;
1761 ucal_add(impl->rscale, UCAL_HOUR_OF_DAY, (int32_t)inc, &status);
1764static void increment_minute(icalrecur_iterator *impl,
int inc)
1766 UErrorCode status = U_ZERO_ERROR;
1768 ucal_add(impl->rscale, UCAL_MINUTE, (int32_t)inc, &status);
1771static void increment_second(icalrecur_iterator *impl,
int inc)
1773 UErrorCode status = U_ZERO_ERROR;
1775 ucal_add(impl->rscale, UCAL_SECOND, (int32_t)inc, &status);
1778static bool validate_byrule(icalrecur_iterator *impl,
1780 short (*decode_val)(
short *,
bool),
1783 if (has_by_data(impl, byrule)) {
1784 UErrorCode status = U_ZERO_ERROR;
1785 const icalrecurrence_by_data *by_ptr = &impl->bydata[byrule].by;
1787 (short)ucal_getLimit(impl->rscale, field, UCAL_MAXIMUM, &status);
1790 for (idx = 0; idx < by_ptr->size; idx++) {
1791 short val = decode_val ? decode_val(&by_ptr->data[idx], decode_flags) : by_ptr->data[idx];
1793 if (abs(val) > max) {
1802static short decode_month(
short *
month,
bool is_hebrew)
1804 if (is_hebrew && *
month > 5) {
1815static short decode_day(
short *
day,
bool flags)
1822static bool initialize_rscale(icalrecur_iterator *impl)
1826 char locale[ULOC_KEYWORD_AND_VALUES_CAPACITY] = {0};
1827 UErrorCode status = U_ZERO_ERROR;
1828 UChar *tzid = (UChar *)UCAL_UNKNOWN_ZONE_ID;
1829 bool is_hebrew =
false;
1844 if (src && !strncmp(src, prefix, strlen(prefix))) {
1846 src += strlen(prefix);
1851 size_t len = (strlen(src) + 1) * U_SIZEOF_UCHAR;
1853 tzid = u_strFromUTF8Lenient(tzid, (int32_t)len, NULL, src, -1, &status);
1854 if (U_FAILURE(status)) {
1861 (void)uloc_setKeywordValue(
"calendar",
"gregorian",
1862 locale,
sizeof(locale), &status);
1865 impl->greg = ucal_open(tzid, -1, locale, UCAL_DEFAULT, &status);
1867 ucal_setDateTime(impl->greg,
1868 (int32_t)dtstart.
year,
1869 (int32_t)(dtstart.
month - 1),
1870 (int32_t)dtstart.
day,
1871 (int32_t)dtstart.
hour,
1873 (int32_t)dtstart.
second, &status);
1875 if (!impl->greg || U_FAILURE(status)) {
1882 impl->rscale = impl->greg;
1889 for (r = rule->
rscale; *r; r++) {
1890 *r = tolower((
int)*r);
1894 en = ucal_getKeywordValuesForLocale(
"calendar",
"",
false, &status);
1895 while ((cal = uenum_next(en, NULL, &status))) {
1896 if (!strcmp(cal, rule->
rscale)) {
1897 is_hebrew = (strcmp(rule->
rscale,
"hebrew") == 0);
1908 (void)uloc_setKeywordValue(
"calendar", rule->
rscale,
1909 locale,
sizeof(locale), &status);
1912 impl->rscale = ucal_open(tzid, -1, locale, UCAL_DEFAULT, &status);
1914 UDate millis = ucal_getMillis(impl->greg, &status);
1916 ucal_setMillis(impl->rscale, millis, &status);
1918 if (!impl->rscale || U_FAILURE(status)) {
1926 &decode_month, is_hebrew) ||
1927 !validate_byrule(impl,
ICAL_BY_DAY, UCAL_WEEK_OF_YEAR, &decode_day,
false) ||
1930 !validate_byrule(impl,
ICAL_BY_WEEK_NO, UCAL_WEEK_OF_YEAR, NULL,
false) ||
1931 !validate_byrule(impl,
ICAL_BY_SET_POS, UCAL_DAY_OF_YEAR, NULL,
false)) {
1937 ucal_setAttribute(impl->rscale, UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, 4);
1938 ucal_setAttribute(impl->rscale, UCAL_FIRST_DAY_OF_WEEK, (int32_t)rule->
week_start);
1941 impl->rstart = occurrence_as_icaltime(impl, 0);
1947static void set_start(icalrecur_iterator *impl,
icaltimetype date)
1949 UErrorCode status = U_ZERO_ERROR;
1951 impl->last.is_date = impl->rstart.is_date;
1952 impl->last.zone = impl->rstart.zone;
1954 if (impl->rstart.is_date) {
1955 ucal_setDate(impl->greg,
1957 (int32_t)(date.
month - 1),
1958 (int32_t)date.
day, &status);
1964 ucal_setDateTime(impl->greg,
1966 (int32_t)(date.
month - 1),
1974 if (impl->rscale != impl->greg) {
1975 UDate millis = ucal_getMillis(impl->greg, &status);
1976 ucal_setMillis(impl->rscale, millis, &status);
1980static void set_datetime(icalrecur_iterator *impl,
icaltimetype date)
1982 UErrorCode status = U_ZERO_ERROR;
1984 impl->last.is_date = impl->rstart.is_date;
1985 impl->last.zone = impl->rstart.zone;
1987 if (impl->rstart.is_date) {
1988 ucal_setDate(impl->greg,
1990 (int32_t)(date.
month - 1),
1991 (int32_t)date.
day, &status);
1993 ucal_setDateTime(impl->greg,
1995 (int32_t)(date.
month - 1),
2003 if (impl->rscale != impl->greg) {
2004 UDate millis = ucal_getMillis(impl->greg, &status);
2005 ucal_setMillis(impl->rscale, millis, &status);
2014 if (impl->rscale == impl->greg) {
2016 diff = __greg_month_diff(a, b);
2021 UErrorCode status = U_ZERO_ERROR;
2026 millis = ucal_getMillis(impl->rscale, &status);
2028 set_day_of_year(impl, 1);
2029 diff = get_months_in_year(impl,
year) - a.
month;
2031 diff += get_months_in_year(impl,
year);
2036 ucal_setMillis(impl->rscale, millis, &status);
2045 UErrorCode status = U_ZERO_ERROR;
2050 millis = ucal_getMillis(impl->rscale, &status);
2052 set_day_of_year(impl, 1);
2054 diff = __day_diff(impl, a, b);
2057 ucal_setMillis(impl->rscale, millis, &status);
2062static void reset_period_start(icalrecur_iterator *impl)
2066 (void)get_day_of_year(impl, start.
year, start.
month, start.
day);
2077 icalarray *calendars =
icalarray_new(
sizeof(
const char **), 1);
2078 const char *cal =
"GREGORIAN";
2085static void set_second(icalrecur_iterator *impl,
int second)
2087 impl->last.second =
second;
2090static void set_minute(icalrecur_iterator *impl,
int minute)
2092 impl->last.minute =
minute;
2095static void set_hour(icalrecur_iterator *impl,
int hour)
2097 impl->last.hour =
hour;
2100static int set_month(icalrecur_iterator *impl,
int month)
2102 return (impl->last.month =
month);
2106#define get_months_in_year(impl, year) (12)
2109static int get_days_in_year(icalrecur_iterator *impl,
int year)
2116static void set_day_of_year(icalrecur_iterator *impl,
int doy)
2121 doy += get_days_in_year(impl, impl->last.year);
2126 impl->last.day = next.day;
2127 impl->last.month = next.month;
2128 impl->last.year = next.year;
2131static int get_start_of_week(
const icalrecur_iterator *impl)
2136static int get_day_of_week(
const icalrecur_iterator *impl)
2143static int get_week_number(icalrecur_iterator *impl,
struct icaltimetype tt)
2158 week = weeks_in_year(tt.
year - 1, impl->rule->week_start);
2159 }
else if (week > weeks_in_year(tt.
year, impl->rule->week_start)) {
2167static int get_days_in_month(icalrecur_iterator *impl,
int month,
int year)
2174static struct icaltimetype get_dtstart_adjusted(icalrecur_iterator *impl,
2189 }
else if (
day < 0) {
2197static int get_day_of_year(icalrecur_iterator *impl,
2203static int get_day_of_week_adjusted(icalrecur_iterator *impl,
2210static struct icaltimetype occurrence_as_icaltime(icalrecur_iterator *impl,
2216static struct icaltimetype __icaltime_from_day_of_year(icalrecur_iterator *impl,
2217 int day,
int year,
int *weekno)
2222 day += get_days_in_year(impl,
year) + 1;
2228 *weekno = get_week_number(impl, tt);
2233static void increment_year(icalrecur_iterator *impl,
int inc)
2235 impl->last.
year += inc;
2238static void __increment_month(icalrecur_iterator *impl,
int inc)
2242 impl->last.month += inc;
2247 years = impl->last.month / 12;
2249 impl->last.month = impl->last.month % 12;
2251 if (impl->last.month < 0) {
2252 impl->last.month = impl->last.month + 12;
2259 increment_year(impl, years);
2263static void increment_monthday(icalrecur_iterator *impl,
int inc)
2268static void increment_hour(icalrecur_iterator *impl,
int inc)
2273static void increment_minute(icalrecur_iterator *impl,
int inc)
2278static void increment_second(icalrecur_iterator *impl,
int inc)
2283static bool initialize_rscale(icalrecur_iterator *impl)
2285 if (impl->rule->rscale && strcasecmp(impl->rule->rscale,
"GREGORIAN")) {
2290 impl->rstart = impl->dtstart;
2296static void set_start(icalrecur_iterator *impl,
icaltimetype date)
2298 impl->last.year = date.
year;
2299 impl->last.month = date.
month;
2300 impl->last.day = date.
day;
2301 impl->last.is_date = impl->dtstart.is_date;
2302 impl->last.zone = impl->dtstart.zone;
2304 if (!impl->dtstart.is_date) {
2305 __get_start_time(impl, date, &impl->last.hour,
2306 &impl->last.minute, &impl->last.second);
2310static void set_datetime(icalrecur_iterator *impl,
icaltimetype date)
2320 return __greg_month_diff(a, b);
2326 return __day_diff(impl, a, b);
2329static void reset_period_start(icalrecur_iterator *impl)
2332 impl->last.year = impl->period_start.year;
2333 impl->last.month = impl->period_start.month;
2334 impl->last.day = impl->period_start.day;
2339static int get_second(icalrecur_iterator *impl)
2341 return occurrence_as_icaltime(impl, 1).second;
2344static int get_minute(icalrecur_iterator *impl)
2346 return occurrence_as_icaltime(impl, 1).minute;
2349static int get_hour(icalrecur_iterator *impl)
2351 return occurrence_as_icaltime(impl, 1).hour;
2354static bool __iterator_set_start(icalrecur_iterator *impl,
icaltimetype start);
2355static void increment_month(icalrecur_iterator *impl,
int inc);
2356static void expand_month_days(icalrecur_iterator *impl,
int year,
int month);
2357static void expand_year_days(icalrecur_iterator *impl,
int year);
2358static int next_yearday(icalrecur_iterator *impl,
2359 void (*next_period)(icalrecur_iterator *,
int));
2360static int prev_yearday(icalrecur_iterator *impl,
2361 void (*next_period)(icalrecur_iterator *,
int));
2363static void adjust_to_byday(icalrecur_iterator *impl)
2376 int week_start = (int)impl->rule->week_start;
2377 int this_dow = get_day_of_week(impl);
2382 int this_pos = (this_dow - week_start + 7) % 7;
2383 int first_pos = (first_dow - week_start + 7) % 7;
2385 if (first_pos != this_pos) {
2386 increment_monthday(impl, first_pos - this_pos);
2398 icalrecur_iterator *impl;
2410#define IN_RANGE(val, min, max) ((val) >= (min) && (val) <= (max))
2414 !IN_RANGE(dtstart.
year, 0, MAX_TIME_T_YEAR) ||
2415 !IN_RANGE(dtstart.
month, 1, 12) ||
2416 !IN_RANGE(dtstart.
day, 1,
2418 (!dtstart.
is_date && (!IN_RANGE(dtstart.
hour, 0, 23) ||
2419 !IN_RANGE(dtstart.
minute, 0, 59) ||
2420 !IN_RANGE(dtstart.
second, 0, 59)))) {
2437 memset(impl, 0,
sizeof(icalrecur_iterator));
2439 impl->dtstart = dtstart;
2441#if defined(HAVE_LIBICU)
2467 impl->bydata[byrule].by = impl->rule->by[byrule];
2474 impl->bydata[byrule].orig_data =
2475 (short)(impl->rule->by[byrule].size > 0);
2478 if (expand_map[freq].map[byrule] == ILLEGAL &&
2479 has_by_data(impl, byrule)) {
2483 impl->bydata[byrule].orig_data = 0;
2492 if (!initialize_rscale(impl)) {
2517 if (!__iterator_set_start(impl, dtstart)) {
2527 icalerror_check_arg_rv((impl != 0),
"impl");
2529#if defined(HAVE_LIBICU)
2531 if (impl->rscale && (impl->rscale != impl->greg)) {
2532 ucal_close(impl->rscale);
2535 ucal_close(impl->greg);
2567 diff = get_days_in_year(impl,
year) -
2570 diff += get_days_in_year(impl,
year);
2586static void increment_month(icalrecur_iterator *impl,
int inc)
2588 __increment_month(impl, inc);
2591 struct icaltimetype this = occurrence_as_icaltime(impl, 0);
2593 while (this.year < MAX_TIME_T_YEAR) {
2594 icalrecurrence_iterator_by_data *bydata = &impl->bydata[
ICAL_BY_MONTH];
2595 for (bydata->index = 0;
2596 bydata->index < bydata->by.size; bydata->index++) {
2597 if (this.month == bydata->by.data[bydata->index]) {
2602 __increment_month(impl, inc);
2603 this = occurrence_as_icaltime(impl, 0);
2608static int next_unit(icalrecur_iterator *impl,
2610 int (*next_sub_unit)(icalrecur_iterator *),
2611 void (*set_unit)(icalrecur_iterator *,
int),
2612 int (*get_unit)(icalrecur_iterator *),
2614 void (*increment_unit)(icalrecur_iterator *,
int))
2617 (impl->bydata[by_unit].by.size > 0);
2618 int this_frequency = (impl->rule->freq == frequency);
2620 int end_of_data = 0;
2622 icalassert(has_by_unit || this_frequency);
2625 if (next_sub_unit && next_sub_unit(impl) == 0) {
2632 icalrecurrence_iterator_by_data *bydata = &impl->bydata[by_unit];
2633 if (this_frequency) {
2636 size_t stalledCnt = 0;
2637 while ((impl->last.year < MAX_TIME_T_YEAR) && (stalledCnt++ < max_recurrence_time_count)) {
2638 int last_unit = get_unit(impl);
2640 while (bydata->index < bydata->by.size) {
2641 int cur_by = bydata->by.data[bydata->index];
2642 if ((cur_by >= last_unit) &&
2643 ((cur_by - last_unit) % impl->rule->interval) == 0) {
2644 set_unit(impl, cur_by);
2653 if (last_unit + impl->rule->interval < period_len) {
2654 int diff = period_len - last_unit;
2655 multiplier = (diff / impl->rule->interval + (diff % impl->rule->interval > 0));
2657 increment_unit(impl, multiplier * impl->rule->interval);
2665 if (bydata->by.size <= bydata->index) {
2671 if (bydata->index < bydata->by.size) {
2672 set_unit(impl, bydata->by.data[bydata->index]);
2679 increment_unit(impl, impl->rule->interval);
2686static int next_second(icalrecur_iterator *impl)
2689 &set_second, &get_second, 60, &increment_second);
2692static int next_minute(icalrecur_iterator *impl)
2695 &set_minute, &get_minute, 60, &increment_minute);
2698static int next_hour(icalrecur_iterator *impl)
2701 &set_hour, &get_hour, 24, &increment_hour);
2704static int next_day(icalrecur_iterator *impl)
2707 NULL, NULL, 0, &increment_monthday);
2710static int prev_unit(icalrecur_iterator *impl,
2712 int (*prev_sub_unit)(icalrecur_iterator *),
2713 void (*set_unit)(icalrecur_iterator *,
int),
2714 int (*get_unit)(icalrecur_iterator *),
2715 void (*increment_unit)(icalrecur_iterator *,
int))
2718 (impl->bydata[by_unit].by.size > 0);
2719 int this_frequency = (impl->rule->freq == frequency);
2721 int end_of_data = 0;
2723 icalassert(has_by_unit || this_frequency);
2726 if (prev_sub_unit && prev_sub_unit(impl) == 0) {
2731 icalrecurrence_iterator_by_data *bydata = &impl->bydata[by_unit];
2732 if (this_frequency) {
2735 while (impl->last.year > 0) {
2736 int last_unit = get_unit(impl);
2737 while (bydata->index >= 0) {
2738 int cur_by = bydata->by.data[bydata->index];
2739 if ((cur_by <= last_unit) && (impl->rule->interval > 0) &&
2740 ((last_unit - cur_by) % impl->rule->interval) == 0) {
2741 set_unit(impl, cur_by);
2746 bydata->index = bydata->by.size - 1;
2748 if (last_unit - impl->rule->interval > 0) {
2749 multiplier = (last_unit / impl->rule->interval + (last_unit % impl->rule->interval > 0));
2751 increment_unit(impl, -multiplier * impl->rule->interval);
2756 if (bydata->index < 0) {
2758 bydata->by.size - 1;
2763 set_unit(impl, bydata->by.data[bydata->index]);
2768 increment_unit(impl, -impl->rule->interval);
2775static int prev_second(icalrecur_iterator *impl)
2778 &set_second, &get_second, &increment_second);
2781static int prev_minute(icalrecur_iterator *impl)
2784 &set_minute, &get_minute, &increment_minute);
2787static int prev_hour(icalrecur_iterator *impl)
2790 &set_hour, &get_hour, &increment_hour);
2793static int prev_day(icalrecur_iterator *impl)
2796 NULL, NULL, &increment_monthday);
2800static void expand_bymonth_days(icalrecur_iterator *impl,
int year,
int month)
2803 int days_in_month = get_days_in_month(impl,
month,
year);
2806 short doy = ICAL_BY_YEARDAY_SIZE, mday = impl->bydata[
ICAL_BY_MONTH_DAY].by.data[i];
2807 int this_month =
month;
2809 if (abs(mday) > days_in_month) {
2810 int days_in_year = get_days_in_year(impl,
year);
2812 switch (impl->rule->skip) {
2824 if (this_month > get_months_in_year(impl,
year)) {
2825 doy = days_in_year + 1;
2836 if (this_month == 0) {
2845 if (doy == ICAL_BY_YEARDAY_SIZE) {
2846 doy = get_day_of_year(impl,
year, this_month, mday);
2849 daysmask_add_day(impl, doy);
2854static void expand_by_day(icalrecur_iterator *impl,
int year,
2855 int doy_offset,
int last_day,
2856 int first_dow,
int last_dow,
2860 unsigned long bydays[LONGS_PER_BITS(ICAL_YEARDAYS_MASK_SIZE)];
2863 memcpy(bydays, impl->days,
sizeof(bydays));
2865 daysmask_set_range(impl->days, doy_offset + 1, doy_offset + last_day + 1, 0);
2867 for (i = 0; i < impl->bydata[
ICAL_BY_DAY].by.size; i++) {
2871 int first_matching_day, last_matching_day;
2872 int day, this_weekno;
2876 first_matching_day = ((dow + 7 - first_dow) % 7) + 1;
2877 last_matching_day = last_day - ((last_dow + 7 - dow) % 7);
2882 day = first_matching_day;
2884 }
else if (pos > 0) {
2886 day = first_matching_day + (pos - 1) * 7;
2888 if (
day > last_matching_day) {
2894 day = last_matching_day + (pos + 1) * 7;
2896 if (
day < first_matching_day) {
2901 if (doy_offset < 0) {
2904 (void)__icaltime_from_day_of_year(impl,
day + doy_offset,
year,
2914 int nweeks = weeks_in_year(
year, impl->rule->week_start);
2921 weekno += nweeks + 1;
2924 if (weekno == this_weekno) {
2934 const unsigned long daysmask = daysmask_getbit(bydays,
day + doy_offset);
2935 int new_val = is_limiting
2941 if (!daysmask_setbit(impl->days,
day + doy_offset, new_val) && new_val) {
2942 if (
day + doy_offset < impl->days_index) {
2943 impl->days_index =
day + doy_offset;
2948 }
while (!pos && ((
day += 7) <= last_day) && ++this_weekno);
2953static void limit_by_day(icalrecur_iterator *impl,
int year)
2955 unsigned long bydays[LONGS_PER_BITS(ICAL_YEARDAYS_MASK_SIZE)];
2958 memcpy(bydays, impl->days,
sizeof(bydays));
2959 daysmask_clearall(impl->days);
2960 impl->days_index = ICAL_YEARDAYS_MASK_SIZE;
2965 for (doy = 0; doy < ICAL_YEARDAYS_MASK_SIZE; doy++) {
2969 if (!daysmask_getbit(bydays, doy)) {
2973 date = __icaltime_from_day_of_year(impl, doy,
year, NULL);
2974 dow = get_day_of_week_adjusted(impl, date.
year, date.
month, date.
day);
2976 for (i = 0; i < impl->bydata[
ICAL_BY_DAY].by.size; i++) {
2977 short byday = impl->bydata[
ICAL_BY_DAY].by.data[i];
2989 last_day = get_days_in_month(impl, date.
month, date.
year);
2992 last_day = get_days_in_year(impl, date.
year);
2995 if (pos != (pos > 0 ? (
day - 1) / 7 + 1 : -((last_day -
day) / 7 + 1))) {
3000 daysmask_add_day(impl, doy);
3007 reset_period_start(impl);
3013static void expand_month_days(icalrecur_iterator *impl,
int year,
int month)
3015 int doy_offset, days_in_month, first_dow;
3017 daysmask_clearall(impl->days);
3021 impl->period_start = occurrence_as_icaltime(impl, 0);
3023 doy_offset = get_day_of_year(impl,
year,
month, 1) - 1;
3024 first_dow = get_day_of_week_adjusted(impl,
year,
month, 1);
3025 days_in_month = get_days_in_month(impl,
month,
year);
3035 limit_by_day(impl,
year);
3039 impl->days_index = ICAL_YEARDAYS_MASK_SIZE;
3041 last_dow = get_day_of_week_adjusted(impl,
year,
month, days_in_month);
3043 expand_by_day(impl,
year, doy_offset, days_in_month,
3044 first_dow, last_dow,
3049static void __next_month(icalrecur_iterator *impl,
int inc)
3054 increment_month(impl, inc);
3055 this = occurrence_as_icaltime(impl, 0);
3056 expand_month_days(impl, this.year, this.month);
3059static int next_month(icalrecur_iterator *impl)
3061 return next_yearday(impl, &__next_month);
3064static int prev_month(icalrecur_iterator *impl)
3066 return prev_yearday(impl, &__next_month);
3069static int next_weekday_by_week(icalrecur_iterator *impl)
3071 int end_of_data = 0;
3073 if (next_hour(impl) == 0) {
3097 dow -= (int)impl->rule->week_start;
3102 int start_of_week = get_start_of_week(impl);
3104 if (dow + start_of_week < 1) {
3110 increment_year(impl, -1);
3113 set_day_of_year(impl, start_of_week + dow);
3119static bool next_week(icalrecur_iterator *impl)
3123 if (next_weekday_by_week(impl) == 0) {
3131 increment_monthday(impl, 7 * impl->rule->interval);
3136static int prev_weekday_by_week(icalrecur_iterator *impl)
3138 int end_of_data = 0;
3139 int start_of_week, dow;
3141 if (prev_hour(impl) == 0) {
3163 dow -= (int)impl->rule->week_start;
3168 start_of_week = get_start_of_week(impl);
3170 if (dow + start_of_week < 1) {
3172 increment_year(impl, -1);
3175 set_day_of_year(impl, start_of_week + dow);
3180static int prev_week(icalrecur_iterator *impl)
3184 if (prev_weekday_by_week(impl) == 0) {
3192 increment_monthday(impl, 7 * -impl->rule->interval);
3200static void expand_year_days(icalrecur_iterator *impl,
int year)
3203 short days_in_year = (short)get_days_in_year(impl,
year);
3206 daysmask_clearall(impl->days);
3210 impl->period_start = occurrence_as_icaltime(impl, 0);
3224 if (abs(doy) > days_in_year) {
3225 switch (impl->rule->skip) {
3237 doy = days_in_year + 1;
3249 }
else if (doy < 0) {
3250 doy += days_in_year + 1;
3253 daysmask_add_day(impl, doy);
3268 int nweeks = weeks_in_year(
year, impl->rule->week_start);
3272 (void)__icaltime_from_day_of_year(impl, 1,
year, &weekno);
3279 set_day_of_year(impl, 1);
3280 start_doy += get_start_of_week(impl) - 1;
3282 start_doy += (get_day_of_week_adjusted(impl, impl->dtstart.year,
3283 impl->dtstart.month, impl->dtstart.day) -
3284 (int)impl->rule->week_start + 7) %
3287 (void)get_days_in_year(impl,
year);
3294 weekno += nweeks + 1;
3295 }
else if (weekno > nweeks) {
3299 doy = start_doy + 7 * (weekno - 1);
3301 daysmask_add_day(impl, doy);
3309 if (
month > 0 &&
month < ICAL_BY_MONTH_SIZE) {
3319 int first_dow, last_dow;
3322 limit_by_day(impl,
year);
3326 impl->days_index = ICAL_YEARDAYS_MASK_SIZE;
3333 if (
month > 0 &&
month < ICAL_BY_MONTH_SIZE) {
3334 int doy_offset, days_in_month;
3338 get_day_of_year(impl,
year,
month, 1) - 1;
3339 first_dow = get_day_of_week_adjusted(impl,
year,
month, 1);
3342 days_in_month = get_days_in_month(impl,
month,
year);
3343 last_dow = get_day_of_week_adjusted(impl,
year,
3344 month, days_in_month);
3346 expand_by_day(impl,
year, doy_offset, days_in_month,
3347 first_dow, last_dow, limiting);
3352 short doy_offset = 0, last_day;
3358 (void)__icaltime_from_day_of_year(impl, 1,
year, &weekno);
3365 set_day_of_year(impl, 1);
3366 doy_offset += get_start_of_week(impl) - 1;
3367 last_day = 7 * weeks_in_year(
year, impl->rule->week_start);
3369 first_dow = (int)impl->rule->week_start;
3370 last_dow = (first_dow + 6) % 7;
3373 first_dow = get_day_of_week_adjusted(impl,
year, 1, 1);
3376 set_day_of_year(impl, days_in_year);
3377 last_dow = get_day_of_week(impl);
3379 last_day = days_in_year;
3382 expand_by_day(impl,
year, doy_offset, last_day, first_dow, last_dow, limiting);
3387static void __next_year(icalrecur_iterator *impl,
int inc)
3392 increment_year(impl, inc);
3393 this = occurrence_as_icaltime(impl, 0);
3394 expand_year_days(impl, this.year);
3397static int next_year(icalrecur_iterator *impl)
3399 return next_yearday(impl, &__next_year);
3402static int prev_year(icalrecur_iterator *impl)
3404 return prev_yearday(impl, &__next_year);
3407static short daymask_find_next_bit(
const unsigned long *days,
short start_index)
3409 short days_index = start_index;
3411 short startBitIndex;
3412 unsigned short wordIdx;
3414 if (days_index >= ICAL_YEARDAYS_MASK_SIZE) {
3415 return ICAL_YEARDAYS_MASK_SIZE;
3417 if (days_index < -ICAL_YEARDAYS_MASK_OFFSET) {
3418 days_index = -ICAL_YEARDAYS_MASK_OFFSET;
3422 startBitIndex = days_index + ICAL_YEARDAYS_MASK_OFFSET;
3423 wordIdx = (
unsigned short)(startBitIndex / BITS_PER_LONG);
3425 if (startBitIndex >= 0) {
3426 v >>= startBitIndex % BITS_PER_LONG;
3428 v <<= -startBitIndex % BITS_PER_LONG;
3433 days_index += BITS_PER_LONG - startBitIndex % BITS_PER_LONG;
3436 unsigned short maxWordIdx = (
unsigned short)(LONGS_PER_BITS(ICAL_YEARDAYS_MASK_SIZE)) - 1;
3437 while (days_index < ICAL_YEARDAYS_MASK_SIZE && wordIdx < maxWordIdx) {
3445 days_index += BITS_PER_LONG;
3454 int maskSize = (int)(BITS_PER_LONG / 2);
3455 mask = (((
unsigned long)1) << maskSize) - 1;
3458 if ((v & mask) == 0) {
3460 days_index += maskSize;
3470static short daymask_find_prev_bit(
const unsigned long *days,
short start_index)
3472 short days_index = start_index;
3474 short startBitIndex;
3477 if (days_index <= -ICAL_YEARDAYS_MASK_OFFSET) {
3478 return -ICAL_YEARDAYS_MASK_OFFSET;
3480 if (days_index >= ICAL_YEARDAYS_MASK_SIZE) {
3481 days_index = ICAL_YEARDAYS_MASK_SIZE - 1;
3485 startBitIndex = days_index + ICAL_YEARDAYS_MASK_OFFSET;
3486 wordIdx = (int)(startBitIndex / BITS_PER_LONG);
3488 v = makeMask(v, BITS_PER_LONG - (startBitIndex % BITS_PER_LONG) - 1);
3492 days_index -= (startBitIndex % BITS_PER_LONG) + 1;
3495 while (days_index > -ICAL_YEARDAYS_MASK_OFFSET) {
3503 days_index -= BITS_PER_LONG;
3512 int maskSize = (int)(BITS_PER_LONG / 2);
3513 mask = ((((
unsigned long)1) << maskSize) - 1) << maskSize;
3516 if ((v & mask) == 0) {
3518 days_index -= maskSize;
3521 mask = makeMask(mask, maskSize);
3528static int next_yearday(icalrecur_iterator *impl,
3529 void (*next_period)(icalrecur_iterator *,
int))
3531 if (next_hour(impl) == 0) {
3537 reset_period_start(impl);
3540 impl->days_index = daymask_find_next_bit(impl->days, impl->days_index + 1);
3544 if (impl->days_index >= ICAL_YEARDAYS_MASK_SIZE) {
3549 next_period(impl, impl->rule->interval);
3551 if (impl->days_index < ICAL_YEARDAYS_MASK_SIZE) {
3563 if (impl->days_index < 1) {
3565 increment_year(impl, -1);
3568 set_day_of_year(impl, impl->days_index);
3573static int prev_yearday(icalrecur_iterator *impl,
3574 void (*next_period)(icalrecur_iterator *,
int))
3576 if (prev_hour(impl) == 0) {
3582 reset_period_start(impl);
3585 impl->days_index = daymask_find_prev_bit(impl->days, impl->days_index - 1);
3589 while (impl->days_index <= -ICAL_YEARDAYS_MASK_OFFSET) {
3593 next_period(impl, -impl->rule->interval);
3595 impl->days_index = ICAL_YEARDAYS_MASK_SIZE;
3596 impl->days_index = daymask_find_prev_bit(impl->days, impl->days_index - 1);
3605 if (impl->days_index < 1) {
3607 increment_year(impl, -1);
3610 set_day_of_year(impl, impl->days_index);
3615static int days_in_current_month(icalrecur_iterator *impl)
3617 return get_days_in_month(impl, impl->last.month, impl->last.year);
3620static int days_in_current_year(icalrecur_iterator *impl)
3622 return get_days_in_year(impl, impl->last.year);
3625static inline int has_contract_restriction(icalrecur_iterator *impl,
3628 return impl->bydata[byrule].by.size > 0 &&
3629 expand_map[impl->rule->freq].map[byrule] == CONTRACT;
3632static bool check_contract_restriction(icalrecur_iterator *impl,
3634 int (*get_total)(icalrecur_iterator *))
3636 if (has_contract_restriction(impl, byrule)) {
3639 for (
int itr = 0; itr < impl->bydata[byrule].by.size; itr++) {
3640 short byval = impl->bydata[byrule].by.data[itr];
3641 if ((byval < 0) && (total == 0)) {
3644 total = get_total(impl);
3653 if (v == ((byval >= 0) ? byval : (total + 1 + byval))) {
3666static bool check_contracting_rules(icalrecur_iterator *impl)
3668 struct icaltimetype last = occurrence_as_icaltime(impl, 0);
3675 (last.
year != impl->period_start.year || last.
month != impl->period_start.month)) {
3676 month = impl->period_start.month;
3682#define CHECK_CONTRACT_RESTRICTION(by, v, get_total) \
3683 (!has_contract_restriction(impl, (by)) || check_contract_restriction(impl, (by), (v), (get_total)))
3691 CHECK_CONTRACT_RESTRICTION(
ICAL_BY_WEEK_NO, get_week_number(impl, last), NULL) &&
3692 CHECK_CONTRACT_RESTRICTION(
3694 CHECK_CONTRACT_RESTRICTION(
3699#undef CHECK_CONTRACT_RESTRICTION
3713static void setup_setpos(icalrecur_iterator *impl,
int next)
3716 int days_index = impl->days_index;
3719 bydata_indices[byrule] = impl->bydata[byrule].index;
3723 impl->recurrence_set_size = 1;
3724 int period_change = 1;
3726 switch (impl->rule->freq) {
3732 period_change = (next ? next_second : prev_second)(impl);
3735 period_change = (next ? next_minute : prev_minute)(impl);
3738 period_change = (next ? next_hour : prev_hour)(impl);
3741 period_change = (next ? next_weekday_by_week : prev_weekday_by_week)(impl);
3746 period_change = (next ? next_yearday : prev_yearday)(impl, NULL);
3749 period_change = (next ? next_yearday : prev_yearday)(impl, NULL);
3755 if (period_change == 0 && check_contracting_rules(impl)) {
3756 impl->recurrence_set_size++;
3758 }
while (period_change == 0);
3765 impl->set_pos = impl->recurrence_set_size;
3766 impl->sp_idxp = impl->sp_pmax;
3767 impl->sp_idxn = impl->sp_pmax + 1;
3773 set_datetime(impl, last);
3775 impl->days_index = days_index;
3777 impl->bydata[byrule].index = bydata_indices[byrule];
3785static inline int setpos_cmp(
int s1,
int s2,
int next)
3788 return (next ? -1 : 1);
3789 }
else if (s2 < s1) {
3790 return (next ? 1 : -1);
3801static bool check_setpos(icalrecur_iterator *impl,
int next)
3810 if (impl->sp_pmax >= 0) {
3811 set_pos = by->data[impl->sp_idxp];
3813 while (setpos_cmp(set_pos, impl->set_pos, next) < 0) {
3814 if (next && impl->sp_idxp < impl->sp_pmax) {
3816 }
else if (!next && impl->sp_idxp > 0) {
3821 set_pos = by->data[impl->sp_idxp];
3823 if (impl->set_pos == set_pos) {
3828 if (impl->sp_pmax < by->size - 1) {
3829 set_pos = by->data[impl->sp_idxn] + impl->recurrence_set_size + 1;
3830 while (setpos_cmp(set_pos, impl->set_pos, next) < 0) {
3831 if (next && impl->sp_idxn > impl->sp_pmax + 1) {
3833 }
else if (!next && impl->sp_idxn < by->size - 1) {
3838 set_pos = by->data[impl->sp_idxn] + impl->recurrence_set_size + 1;
3840 if (impl->set_pos == set_pos) {
3851 (impl->rule->count != 0 && impl->occurrence_no >= impl->rule->count) ||
3858 if ((impl->occurrence_no == 0) &&
3860 check_setpos(impl, 1) &&
3861 check_contracting_rules(impl)) {
3862 impl->occurrence_no++;
3866 int period_change = 1;
3869 icalrecur_iterator impl_last = *impl;
3872 size_t stalledCnt = 0;
3874 int lastTimeCompare = 0;
3876 int checkContractingRules = (int)check_contracting_rules(impl);
3877 size_t cntRecurrences = 0;
3880 switch (impl->rule->freq) {
3887 period_change = next_minute(impl);
3891 period_change = next_hour(impl);
3895 period_change = next_day(impl);
3899 period_change = (int)next_week(impl);
3903 period_change = next_month(impl);
3907 period_change = next_year(impl);
3915 impl->last = occurrence_as_icaltime(impl, 1);
3919 if (impl->last.year > MAX_TIME_T_YEAR ||
3926 set_datetime(impl, impl_last.last);
3931 int new_ccr = (int)check_contracting_rules(impl);
3933 if (checkContractingRules == 0 || period_change) {
3934 setup_setpos(impl, 1);
3939 checkContractingRules = new_ccr;
3944 if (lastTimeCompare == 0) {
3945 if (stalledCnt++ == max_recurrence_time_count) {
3951 }
while ((cntRecurrences++ < max_recurrences) &&
3952 ((lastTimeCompare == 0) ||
3954 (!check_contracting_rules(impl)) ||
3955 (hasSetPos && !check_setpos(impl, 1))));
3957 impl->occurrence_no++;
3969 int period_change = 1;
3970 icalrecur_iterator impl_last = *impl;
3972 int checkContractingRules = (int)check_contracting_rules(impl);
3976 switch (impl->rule->freq) {
3982 period_change = prev_minute(impl);
3986 period_change = prev_hour(impl);
3990 period_change = prev_day(impl);
3994 period_change = prev_week(impl);
3998 period_change = prev_month(impl);
4002 period_change = prev_year(impl);
4010 impl->last = occurrence_as_icaltime(impl, 1);
4017 set_datetime(impl, impl_last.last);
4022 int new_ccr = (int)check_contracting_rules(impl);
4024 if (checkContractingRules == 0 || period_change) {
4025 setup_setpos(impl, 0);
4030 checkContractingRules = new_ccr;
4033 }
while (impl->last.year > MAX_TIME_T_YEAR ||
4039 (hasSetPos && !check_setpos(impl, 0)) ||
4040 !check_contracting_rules(impl));
4042 impl->occurrence_no--;
4049static void set_bydata_start(icalrecurrence_iterator_by_data *bydata,
int tfield)
4053 bdi < bydata->by.size; bdi++) {
4054 if (bydata->by.data[bdi] == tfield) {
4055 bydata->index = bdi;
4061static bool __iterator_set_start(icalrecur_iterator *impl,
icaltimetype start)
4064 short interval = impl->rule->interval;
4067 impl->istart = start;
4068 impl->occurrence_no = 0;
4069 impl->days_index = ICAL_YEARDAYS_MASK_SIZE;
4072 set_start(impl, start);
4079 if ((interval > 1) &&
4080 (diff = (impl->istart.year - impl->rstart.year) % interval)) {
4083 set_day_of_year(impl, 1);
4084 increment_year(impl, interval - diff);
4088 start = occurrence_as_icaltime(impl, 0);
4091 int start_weekno = get_week_number(impl, start);
4092 if (start_weekno > 5 &&
4097 increment_year(impl, -1);
4098 expand_year_days(impl, start.
year - 1);
4099 int days_in_year = get_days_in_year(impl, start.
year - 1);
4100 impl->days_index = daymask_find_next_bit(impl->days, days_in_year + 1);
4101 if (impl->days_index >= ICAL_YEARDAYS_MASK_SIZE) {
4102 increment_year(impl, 1);
4104 }
else if (start_weekno < 45 &&
4105 start.
month == 12) {
4109 increment_year(impl, 1);
4110 expand_year_days(impl, start.
year + 1);
4111 impl->days_index = daymask_find_next_bit(impl->days, -ICAL_YEARDAYS_MASK_OFFSET);
4112 if (impl->days_index >= ICAL_YEARDAYS_MASK_SIZE) {
4113 increment_year(impl, -1);
4120 while (start.
year < MAX_TIME_T_YEAR && impl->days_index >= ICAL_YEARDAYS_MASK_SIZE) {
4121 expand_year_days(impl, start.
year);
4134 if (impl->days_index >= ICAL_YEARDAYS_MASK_SIZE) {
4135 increment_year(impl, interval);
4136 start = occurrence_as_icaltime(impl, 0);
4141 set_day_of_year(impl, impl->days_index);
4142 if (impl->days_index < 1) {
4143 increment_year(impl, -1);
4152 if ((interval > 1) &&
4153 (diff = month_diff(impl, impl->rstart, impl->istart) % interval)) {
4156 increment_monthday(impl, -impl->istart.day + 1);
4157 __increment_month(impl, interval - diff);
4161 start = occurrence_as_icaltime(impl, 0);
4165 while (start.
year < 20000) {
4166 expand_month_days(impl, start.
year, start.
month);
4167 if (impl->days_index < ICAL_YEARDAYS_MASK_SIZE) {
4170 increment_month(impl, impl->rule->interval);
4171 start = occurrence_as_icaltime(impl, 0);
4175 set_day_of_year(impl, impl->days_index);
4183 recur_iterator_set_static_single_by_value(impl,
ICAL_BY_DAY, (
short)get_day_of_week(impl));
4185 adjust_to_byday(impl);
4189 impl->rstart = occurrence_as_icaltime(impl, 0);
4193 start = occurrence_as_icaltime(impl, 0);
4195 if ((interval > 1) &&
4196 (diff = (day_diff(impl, impl->rstart, start) + 6) / 7) % interval) {
4199 increment_monthday(impl, 7 * (interval - diff));
4205 if ((interval > 1) &&
4206 (diff = day_diff(impl, impl->rstart, impl->istart) % interval)) {
4209 increment_monthday(impl, interval - diff);
4214 if ((interval > 1) &&
4215 (diff = abs(impl->istart.hour - impl->rstart.hour) % interval)) {
4218 increment_hour(impl, interval - diff);
4220 set_bydata_start(&impl->bydata[
ICAL_BY_HOUR], impl->istart.hour);
4224 if ((interval > 1) &&
4225 (diff = abs(impl->istart.minute - impl->rstart.minute) % interval)) {
4228 increment_minute(impl, interval - diff);
4230 set_bydata_start(&impl->bydata[
ICAL_BY_MINUTE], impl->istart.minute);
4234 if ((interval > 1) &&
4235 (diff = abs(impl->istart.second - impl->rstart.second) % interval)) {
4238 increment_second(impl, interval - diff);
4240 set_bydata_start(&impl->bydata[
ICAL_BY_SECOND], impl->istart.second);
4248 impl->last = occurrence_as_icaltime(impl, 1);
4250 setup_setpos(impl, 1);
4254 if (impl->last.year > MAX_TIME_T_YEAR) {
4266 if (impl->rule->count > 0) {
4276 start = impl->dtstart;
4284 return __iterator_set_start(impl, start);
4318 from = impl->rule->until;
4325 if (!__iterator_set_start(impl, from)) {
4349 impl->days_index = 0;
4367 icalrecurrencetype_free(recur, 0);
4369 memset(recur, 0,
sizeof(*recur));
4393 pos = (abs(
day) - wd) / 8 * ((
day < 0) ? -1 : 1);
4400 short s_weekday = (short)weekday;
4401 short a_position = (short)(8 * abs(position));
4402 return (s_weekday + a_position) * ((position < 0) ? -1 : 1);
4407 return (
month & LEAP_MONTH) != 0;
4412 return (
month & ~LEAP_MONTH);
4417 return (
short)
month | (is_leap ? LEAP_MONTH : 0);
4421 icaltime_t start,
int count, icaltime_t *array)
4424 icalrecur_iterator *ritr;
4427 memset(array, 0, (
size_t)count *
sizeof(icaltime_t));
4460#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
4461 if (pthread_mutex_lock(&invalid_rrule_mutex) != 0) {
4466 myHandling = invalidRruleHandling;
4468#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
4469 if (pthread_mutex_unlock(&invalid_rrule_mutex) != 0) {
4479#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
4480 if (pthread_mutex_lock(&invalid_rrule_mutex) != 0) {
4485 invalidRruleHandling = newSetting;
4487#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
4488 if (pthread_mutex_unlock(&invalid_rrule_mutex) != 0) {
void icalarray_append(icalarray *array, const void *element)
Appends an element to an array.
icalarray * icalarray_new(size_t element_size, size_t increment_size)
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
Error handling for libical.
icalerrorenum
Represents the different types of errors that can be triggered in libical.
@ ICAL_MALFORMEDDATA_ERROR
@ ICAL_UNIMPLEMENTED_ERROR
#define icalerrno
Access the current icalerrno value.
size_t icallimit_get(icallimits_kind kind)
Defines the interface for getting/setting internal library limits.
@ ICAL_LIMIT_RECURRENCE_SEARCH
@ ICAL_LIMIT_RECURRENCE_TIME_STANDING_STILL
void icalmemory_free_buffer(void *buf)
Releases a buffer.
char * icalmemory_strdup(const char *s)
Creates a duplicate of a string.
void icalmemory_append_string(char **buf, char **pos, size_t *buf_size, const char *string)
Appends a string to a buffer.
void * icalmemory_resize_buffer(void *buf, size_t size)
Resizes a buffer created with icalmemory_new_buffer().
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
char * icalmemory_tmp_copy(const char *str)
Creates a copy of the given string, stored on the ring buffer, and returns it.
void icalmemory_append_char(char **buf, char **pos, size_t *buf_size, char ch)
Appends a character to a buffer.
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
void * icalmemory_tmp_buffer(size_t size)
Creates a new temporary buffer on the ring and returns it.
Common memory management routines.
bool icalrecur_iterator_set_start(icalrecur_iterator *impl, struct icaltimetype start)
struct icalrecurrencetype * icalrecurrencetype_new_from_string(const char *str)
struct icaltimetype icalrecur_iterator_prev(icalrecur_iterator *impl)
void icalrecurrencetype_ref(struct icalrecurrencetype *recur)
icalrecurrencetype_skip icalrecur_string_to_skip(const char *str)
bool icalrecur_iterator_set_end(icalrecur_iterator *impl, struct icaltimetype end)
short icalrecurrencetype_encode_month(int month, bool is_leap)
short icalrecurrencetype_encode_day(enum icalrecurrencetype_weekday weekday, int position)
bool icalrecurrencetype_month_is_leap(short month)
const char * icalrecur_weekday_to_string(icalrecurrencetype_weekday kind)
const char * icalrecur_skip_to_string(icalrecurrencetype_skip kind)
bool icalrecur_resize_by(icalrecurrence_by_data *by, short size)
struct icalrecurrencetype * icalrecurrencetype_clone(struct icalrecurrencetype *recur)
const char * icalrecur_freq_to_string(icalrecurrencetype_frequency kind)
void ical_set_invalid_rrule_handling_setting(ical_invalid_rrule_handling newSetting)
void icalrecur_iterator_free(icalrecur_iterator *impl)
icalrecurrencetype_frequency icalrecur_string_to_freq(const char *str)
struct icalrecurrencetype * icalrecurrencetype_new(void)
bool icalrecur_iterator_set_range(icalrecur_iterator *impl, struct icaltimetype from, struct icaltimetype to)
icalarray * icalrecurrencetype_rscale_supported_calendars(void)
enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day)
ical_invalid_rrule_handling ical_get_invalid_rrule_handling_setting(void)
int icalrecurrencetype_day_position(short day)
bool icalrecur_expand_recurrence(const char *rule, icaltime_t start, int count, icaltime_t *array)
char * icalrecurrencetype_as_string(struct icalrecurrencetype *recur)
void icalrecurrencetype_unref(struct icalrecurrencetype *recur)
icalrecur_iterator * icalrecur_iterator_new(struct icalrecurrencetype *rule, struct icaltimetype dtstart)
struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *impl)
icalrecurrencetype_weekday icalrecur_string_to_weekday(const char *str)
int icalrecurrencetype_month_month(short month)
char * icalrecurrencetype_as_string_r(struct icalrecurrencetype *recur)
Routines for dealing with recurring time.
icalrecurrencetype_weekday
icalrecurrencetype_frequency
@ ICAL_SECONDLY_RECURRENCE
@ ICAL_MINUTELY_RECURRENCE
@ ICAL_MONTHLY_RECURRENCE
icalrecurrencetype_byrule
@ ICAL_BYRULE_NO_CONTRACTION
ical_invalid_rrule_handling
@ ICAL_RRULE_TREAT_AS_ERROR
@ ICAL_RRULE_IGNORE_INVALID
struct icaltimetype icaltime_from_timet_with_zone(const icaltime_t tm, const bool is_date, const icaltimezone *zone)
Constructor.
struct icaltimetype icaltime_from_string(const char *str)
int icaltime_day_of_year(const struct icaltimetype t)
int icaltime_start_doy_week(const struct icaltimetype t, int fdow)
bool icaltime_is_leap_year(const int year)
int icaltime_day_of_week(const struct icaltimetype t)
struct icaltimetype icaltime_from_day_of_year(const int _doy, const int _year)
bool icaltime_is_valid_time(const struct icaltimetype t)
int icaltime_days_in_month(const int month, const int year)
struct icaltimetype icaltime_convert_to_zone(const struct icaltimetype tt, icaltimezone *zone)
int icaltime_days_in_year(const int year)
bool icaltime_is_null_time(const struct icaltimetype t)
struct icaltimetype icaltime_normalize(const struct icaltimetype tt)
icaltime_t icaltime_as_timet(const struct icaltimetype tt)
int icaltime_compare(const struct icaltimetype a_in, const struct icaltimetype b_in)
void icaltime_adjust(struct icaltimetype *tt, const int days, const int hours, const int minutes, const int seconds)
struct icaltimetype icaltime_null_time(void)
const char * icaltimezone_get_location(const icaltimezone *zone)
const char * icaltimezone_get_tzid(icaltimezone *zone)
const char * icaltimezone_tzid_prefix(void)
Timezone handling routines.
struct _icaltimezone icaltimezone
Defines the data structure representing iCalendar parameter values.
icalrecurrencetype_frequency freq
icalrecurrencetype_skip skip
icalrecurrencetype_weekday week_start
struct icaltimetype until
icalrecurrence_by_data by[ICAL_BY_NUM_PARTS]
const icaltimezone * zone