Libical API Documentation 4.0 UNRELEASED Go to the stable 3.0 documentation
Loading...
Searching...
No Matches
icalrecur.h
Go to the documentation of this file.
1/*======================================================================
2 FILE: icalrecur.h
3 CREATOR: eric 20 March 2000
4
5 SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6 SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7========================================================================*/
8
64
65#ifndef ICALRECUR_H
66#define ICALRECUR_H
67
68#include "libical_ical_export.h"
69#include "icalarray.h"
70#include "icaltime.h"
71
72#include <stdbool.h>
73
74/*
75 * Recurrence enumerations
76 */
77
78typedef enum icalrecurrencetype_frequency
79{
80 /* These enums are used to index an array, so don't change the
81 order or the integers */
82
83 ICAL_SECONDLY_RECURRENCE = 0,
84 ICAL_MINUTELY_RECURRENCE = 1,
85 ICAL_HOURLY_RECURRENCE = 2,
86 ICAL_DAILY_RECURRENCE = 3,
87 ICAL_WEEKLY_RECURRENCE = 4,
88 ICAL_MONTHLY_RECURRENCE = 5,
89 ICAL_YEARLY_RECURRENCE = 6,
90 ICAL_NO_RECURRENCE = 7
91} icalrecurrencetype_frequency;
92
93typedef enum icalrecurrencetype_weekday
94{
95 ICAL_NO_WEEKDAY,
96 ICAL_SUNDAY_WEEKDAY,
97 ICAL_MONDAY_WEEKDAY,
98 ICAL_TUESDAY_WEEKDAY,
99 ICAL_WEDNESDAY_WEEKDAY,
100 ICAL_THURSDAY_WEEKDAY,
101 ICAL_FRIDAY_WEEKDAY,
102 ICAL_SATURDAY_WEEKDAY
103} icalrecurrencetype_weekday;
104
105typedef enum icalrecurrencetype_skip
106{
107 ICAL_SKIP_BACKWARD = 0,
108 ICAL_SKIP_FORWARD,
109 ICAL_SKIP_OMIT,
110 ICAL_SKIP_UNDEFINED
111} icalrecurrencetype_skip;
112
113typedef enum icalrecurrencetype_byrule
114{
115 ICAL_BYRULE_NO_CONTRACTION = -1,
116 ICAL_BY_MONTH = 0,
117 ICAL_BY_WEEK_NO = 1,
118 ICAL_BY_YEAR_DAY = 2,
119 ICAL_BY_MONTH_DAY = 3,
120 ICAL_BY_DAY = 4,
121 ICAL_BY_HOUR = 5,
122 ICAL_BY_MINUTE = 6,
123 ICAL_BY_SECOND = 7,
124 ICAL_BY_SET_POS = 8,
125
126 ICAL_BY_NUM_PARTS = 9
127} icalrecurrencetype_byrule;
128
129/*
130 * Recurrence enumerations conversion routines.
131 */
132
133LIBICAL_ICAL_EXPORT icalrecurrencetype_frequency icalrecur_string_to_freq(const char *str);
134LIBICAL_ICAL_EXPORT const char *icalrecur_freq_to_string(icalrecurrencetype_frequency kind);
135
136LIBICAL_ICAL_EXPORT icalrecurrencetype_skip icalrecur_string_to_skip(const char *str);
137LIBICAL_ICAL_EXPORT const char *icalrecur_skip_to_string(icalrecurrencetype_skip kind);
138
139LIBICAL_ICAL_EXPORT const char *icalrecur_weekday_to_string(icalrecurrencetype_weekday kind);
140LIBICAL_ICAL_EXPORT icalrecurrencetype_weekday icalrecur_string_to_weekday(const char *str);
141
145
146/* See RFC 5545 Section 3.3.10, RECUR Value, and RFC 7529
147 * for an explanation of the values and fields in struct icalrecurrencetype.
148 *
149 * The maximums below are based on lunisolar leap years (13 months)
150 */
151#define ICAL_BY_SECOND_SIZE 62 /* 0 to 60 */
152#define ICAL_BY_MINUTE_SIZE 61 /* 0 to 59 */
153#define ICAL_BY_HOUR_SIZE 25 /* 0 to 23 */
154#define ICAL_BY_MONTH_SIZE 14 /* 1 to 13 */
155#define ICAL_BY_MONTHDAY_SIZE 32 /* 1 to 31 */
156#define ICAL_BY_WEEKNO_SIZE 56 /* 1 to 55 */
157#define ICAL_BY_YEARDAY_SIZE 386 /* 1 to 385 */
158#define ICAL_BY_SETPOS_SIZE ICAL_BY_YEARDAY_SIZE /* 1 to N */
159#define ICAL_BY_DAY_SIZE (7 * (ICAL_BY_WEEKNO_SIZE - 1) + 1) /* 1 to N */
160
161typedef struct
162{
163 short *data;
164 short size;
166
169 /* Reference count */
170 int refcount;
171
172 icalrecurrencetype_frequency freq;
173
174 /* until and count are mutually exclusive. */
175 struct icaltimetype until;
176 int count;
177
178 short interval;
179
180 icalrecurrencetype_weekday week_start;
181
198 icalrecurrence_by_data by[ICAL_BY_NUM_PARTS];
199
200 /* For RSCALE extension (RFC 7529) */
201 char *rscale;
202 icalrecurrencetype_skip skip;
203};
204
210LIBICAL_ICAL_EXPORT struct icalrecurrencetype *icalrecurrencetype_new(void);
211
215LIBICAL_ICAL_EXPORT void icalrecurrencetype_ref(struct icalrecurrencetype *recur);
216
221LIBICAL_ICAL_EXPORT void icalrecurrencetype_unref(struct icalrecurrencetype *recur);
222
223LIBICAL_ICAL_EXPORT icalarray *icalrecurrencetype_rscale_supported_calendars(void);
224
229LIBICAL_ICAL_EXPORT struct icalrecurrencetype *icalrecurrencetype_clone(struct icalrecurrencetype *r);
230
236LIBICAL_ICAL_EXPORT bool icalrecur_resize_by(icalrecurrence_by_data *by, short size);
237
238/*
239 * Routines to decode the day values of the by[ICAL_BY_DAY] array
240 */
241
257LIBICAL_ICAL_EXPORT enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day);
258
265LIBICAL_ICAL_EXPORT int icalrecurrencetype_day_position(short day);
266
272LIBICAL_ICAL_EXPORT short icalrecurrencetype_encode_day(enum icalrecurrencetype_weekday weekday,
273 int position);
274
275/*
276 * Routines to decode the 'month' element of the by[ICAL_BY_MONTH] array
277 */
278
286LIBICAL_ICAL_EXPORT bool icalrecurrencetype_month_is_leap(short month);
287
288LIBICAL_ICAL_EXPORT int icalrecurrencetype_month_month(short month);
289
295LIBICAL_ICAL_EXPORT short icalrecurrencetype_encode_month(int month, bool is_leap);
296
297/*
298 * Recurrence rule parser
299 */
300
302LIBICAL_ICAL_EXPORT struct icalrecurrencetype *icalrecurrencetype_new_from_string(const char *str);
303
304LIBICAL_ICAL_EXPORT char *icalrecurrencetype_as_string(struct icalrecurrencetype *recur);
305
306LIBICAL_ICAL_EXPORT char *icalrecurrencetype_as_string_r(struct icalrecurrencetype *recur);
307
308/*
309 * Recurrence iteration routines
310 */
311
312typedef struct icalrecur_iterator_impl icalrecur_iterator;
313
319LIBICAL_ICAL_EXPORT icalrecur_iterator *icalrecur_iterator_new(struct icalrecurrencetype *rule,
320 struct icaltimetype dtstart);
321
329LIBICAL_ICAL_EXPORT bool icalrecur_iterator_set_start(icalrecur_iterator *impl,
330 struct icaltimetype start);
331
335LIBICAL_ICAL_EXPORT bool icalrecur_iterator_set_end(icalrecur_iterator *impl,
336 struct icaltimetype end);
337
355LIBICAL_ICAL_EXPORT bool icalrecur_iterator_set_range(icalrecur_iterator *impl,
356 struct icaltimetype from,
357 struct icaltimetype to);
358
362LIBICAL_ICAL_EXPORT struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *);
363
368LIBICAL_ICAL_EXPORT struct icaltimetype icalrecur_iterator_prev(icalrecur_iterator *);
369
371LIBICAL_ICAL_EXPORT void icalrecur_iterator_free(icalrecur_iterator *);
372
383LIBICAL_ICAL_EXPORT bool icalrecur_expand_recurrence(const char *rule, icaltime_t start,
384 int count, icaltime_t *array);
385
386/* ical_invalid_rrule_handling :
387 * How should the ICAL library handle RRULEs with invalid BYxxx part combos?
388 */
389typedef enum ical_invalid_rrule_handling
390{
391 ICAL_RRULE_TREAT_AS_ERROR = 0,
392 ICAL_RRULE_IGNORE_INVALID = 1
393} ical_invalid_rrule_handling;
394
395LIBICAL_ICAL_EXPORT ical_invalid_rrule_handling ical_get_invalid_rrule_handling_setting(void);
396
397LIBICAL_ICAL_EXPORT void ical_set_invalid_rrule_handling_setting(
398 ical_invalid_rrule_handling newSetting);
399
400#endif /* ICALRECUR_H */
An array of arbitrarily-sized elements which grows dynamically as elements are added.
struct _icalarray icalarray
A struct representing an icalarray object.
Definition icalarray.h:26
bool icalrecur_iterator_set_start(icalrecur_iterator *impl, struct icaltimetype start)
Definition icalrecur.c:4042
struct icalrecurrencetype * icalrecurrencetype_new_from_string(const char *str)
Definition icalrecur.c:822
void icalrecurrencetype_ref(struct icalrecurrencetype *recur)
Increases the reference counter by 1.
Definition icalrecur.c:735
void icalrecur_iterator_free(icalrecur_iterator *)
Definition icalrecur.c:2390
bool icalrecur_iterator_set_end(icalrecur_iterator *impl, struct icaltimetype end)
Definition icalrecur.c:4067
short icalrecurrencetype_encode_month(int month, bool is_leap)
Definition icalrecur.c:4191
short icalrecurrencetype_encode_day(enum icalrecurrencetype_weekday weekday, int position)
Definition icalrecur.c:4174
bool icalrecurrencetype_month_is_leap(short month)
Definition icalrecur.c:4181
bool icalrecur_resize_by(icalrecurrence_by_data *by, short size)
Resizes the buffer backing the 'by' array to the specified size, if different. Frees the buffer if th...
Definition icalrecur.c:300
struct icalrecurrencetype * icalrecurrencetype_new(void)
Allocates and initializes a new instance of icalrecurrencetype. The new instance is returned with a r...
Definition icalrecur.c:698
bool icalrecur_iterator_set_range(icalrecur_iterator *impl, struct icaltimetype from, struct icaltimetype to)
Definition icalrecur.c:4078
enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day)
Decodes a day to a weekday.
Definition icalrecur.c:4158
int icalrecurrencetype_day_position(short day)
Decodes a day to a position of the weekday.
Definition icalrecur.c:4163
bool icalrecur_expand_recurrence(const char *rule, icaltime_t start, int count, icaltime_t *array)
Fills an array with the 'count' number of occurrences generated by the rrule.
Definition icalrecur.c:4196
void icalrecurrencetype_unref(struct icalrecurrencetype *recur)
Decreases the reference counter by 1. If it goes to 0, the instance and all referenced memory (i....
Definition icalrecur.c:743
icalrecur_iterator * icalrecur_iterator_new(struct icalrecurrencetype *rule, struct icaltimetype dtstart)
Definition icalrecur.c:2264
struct icalrecurrencetype * icalrecurrencetype_clone(struct icalrecurrencetype *r)
Creates a deep copy of the given recurrence rule. The new instance is returned with a refcount of 1.
Definition icalrecur.c:785
struct icaltimetype is a pseudo-object that abstracts time handling.
Definition icalrecur.h:162
Definition icalrecur.h:168
icalrecurrencetype_weekday week_start
Encoded value.
Definition icalrecur.h:180
Definition icaltime.h:96