summaryrefslogtreecommitdiffabout
path: root/libical/src/libical/icalrecur.h
Unidiff
Diffstat (limited to 'libical/src/libical/icalrecur.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libical/icalrecur.h71
1 files changed, 48 insertions, 23 deletions
diff --git a/libical/src/libical/icalrecur.h b/libical/src/libical/icalrecur.h
index 5fcdc15..5f6ac55 100644
--- a/libical/src/libical/icalrecur.h
+++ b/libical/src/libical/icalrecur.h
@@ -7,65 +7,82 @@
7 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org 7 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
8 8
9 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
10 it under the terms of either: 10 it under the terms of either:
11 11
12 The LGPL as published by the Free Software Foundation, version 12 The LGPL as published by the Free Software Foundation, version
13 2.1, available at: http://www.fsf.org/copyleft/lesser.html 13 2.1, available at: http://www.fsf.org/copyleft/lesser.html
14 14
15 Or: 15 Or:
16 16
17 The Mozilla Public License Version 1.0. You may obtain a copy of 17 The Mozilla Public License Version 1.0. You may obtain a copy of
18 the License at http://www.mozilla.org/MPL/ 18 the License at http://www.mozilla.org/MPL/
19*/
20
21/**
22@file icalrecur.h
23@brief Routines for dealing with recurring time
19 24
20How to use: 25How to use:
21 26
221) Get a rule and a start time from a component 271) Get a rule and a start time from a component
28
29@code
23 icalproperty rrule; 30 icalproperty rrule;
24 struct icalrecurrencetype recur; 31 struct icalrecurrencetype recur;
25 struct icaltimetype dtstart; 32 struct icaltimetype dtstart;
26 33
27 rrule = icalcomponent_get_first_property(comp,ICAL_RRULE_PROPERTY); 34 rrule = icalcomponent_get_first_property(comp,ICAL_RRULE_PROPERTY);
28 recur = icalproperty_get_rrule(rrule); 35 recur = icalproperty_get_rrule(rrule);
29 start = icalproperty_get_dtstart(dtstart); 36 start = icalproperty_get_dtstart(dtstart);
37@endcode
30 38
31Or, just make them up: 39Or, just make them up:
40
41@code
32 recur = icalrecurrencetype_from_string("FREQ=YEARLY;BYDAY=SU,WE"); 42 recur = icalrecurrencetype_from_string("FREQ=YEARLY;BYDAY=SU,WE");
33 dtstart = icaltime_from_string("19970101T123000") 43 dtstart = icaltime_from_string("19970101T123000")
44@endcode
34 45
352) Create an iterator 462) Create an iterator
47
48@code
36 icalrecur_iterator* ritr; 49 icalrecur_iterator* ritr;
37 ritr = icalrecur_iterator_new(recur,start); 50 ritr = icalrecur_iterator_new(recur,start);
51@endcode
38 52
393) Iterator over the occurrences 533) Iterator over the occurrences
54
55@code
40 struct icaltimetype next; 56 struct icaltimetype next;
41 while (next = icalrecur_iterator_next(ritr) 57 while (next = icalrecur_iterator_next(ritr)
42 && !icaltime_is_null_time(next){ 58 && !icaltime_is_null_time(next){
43 Do something with next 59 Do something with next
44 } 60 }
61@endcode
45 62
46Note that that the time returned by icalrecur_iterator_next is in 63Note that that the time returned by icalrecur_iterator_next is in
47whatever timezone that dtstart is in. 64whatever timezone that dtstart is in.
48 65
49======================================================================*/ 66*/
50 67
51#ifndef ICALRECUR_H 68#ifndef ICALRECUR_H
52#define ICALRECUR_H 69#define ICALRECUR_H
53 70
54#include <time.h> 71#include <time.h>
55#include "icaltime.h" 72#include "icaltime.h"
56 73
57/*********************************************************************** 74/*
58 * Recurrance enumerations 75 * Recurrance enumerations
59**********************************************************************/ 76 */
60 77
61typedef enum icalrecurrencetype_frequency 78typedef enum icalrecurrencetype_frequency
62{ 79{
63 /* These enums are used to index an array, so don't change the 80 /* These enums are used to index an array, so don't change the
64 order or the integers */ 81 order or the integers */
65 82
66 ICAL_SECONDLY_RECURRENCE=0, 83 ICAL_SECONDLY_RECURRENCE=0,
67 ICAL_MINUTELY_RECURRENCE=1, 84 ICAL_MINUTELY_RECURRENCE=1,
68 ICAL_HOURLY_RECURRENCE=2, 85 ICAL_HOURLY_RECURRENCE=2,
69 ICAL_DAILY_RECURRENCE=3, 86 ICAL_DAILY_RECURRENCE=3,
70 ICAL_WEEKLY_RECURRENCE=4, 87 ICAL_WEEKLY_RECURRENCE=4,
71 ICAL_MONTHLY_RECURRENCE=5, 88 ICAL_MONTHLY_RECURRENCE=5,
@@ -84,40 +101,42 @@ typedef enum icalrecurrencetype_weekday
84 ICAL_THURSDAY_WEEKDAY, 101 ICAL_THURSDAY_WEEKDAY,
85 ICAL_FRIDAY_WEEKDAY, 102 ICAL_FRIDAY_WEEKDAY,
86 ICAL_SATURDAY_WEEKDAY 103 ICAL_SATURDAY_WEEKDAY
87} icalrecurrencetype_weekday; 104} icalrecurrencetype_weekday;
88 105
89enum { 106enum {
90 ICAL_RECURRENCE_ARRAY_MAX = 0x7f7f, 107 ICAL_RECURRENCE_ARRAY_MAX = 0x7f7f,
91 ICAL_RECURRENCE_ARRAY_MAX_BYTE = 0x7f 108 ICAL_RECURRENCE_ARRAY_MAX_BYTE = 0x7f
92}; 109};
93 110
94 111
95 112
96/********************** Recurrence type routines **************/ 113/**
114 * Recurrence type routines
115 */
97 116
98/* See RFC 2445 Section 4.3.10, RECUR Value, for an explaination of 117/* See RFC 2445 Section 4.3.10, RECUR Value, for an explaination of
99 the values and fields in struct icalrecurrencetype */ 118 the values and fields in struct icalrecurrencetype */
100 119
101#define ICAL_BY_SECOND_SIZE 61 120#define ICAL_BY_SECOND_SIZE 61
102#define ICAL_BY_MINUTE_SIZE 61 121#define ICAL_BY_MINUTE_SIZE 61
103#define ICAL_BY_HOUR_SIZE 25 122#define ICAL_BY_HOUR_SIZE 25
104#define ICAL_BY_DAY_SIZE 364 /* 7 days * 52 weeks */ 123#define ICAL_BY_DAY_SIZE 364 /* 7 days * 52 weeks */
105#define ICAL_BY_MONTHDAY_SIZE 32 124#define ICAL_BY_MONTHDAY_SIZE 32
106#define ICAL_BY_YEARDAY_SIZE 367 125#define ICAL_BY_YEARDAY_SIZE 367
107#define ICAL_BY_WEEKNO_SIZE 54 126#define ICAL_BY_WEEKNO_SIZE 54
108#define ICAL_BY_MONTH_SIZE 13 127#define ICAL_BY_MONTH_SIZE 13
109#define ICAL_BY_SETPOS_SIZE 367 128#define ICAL_BY_SETPOS_SIZE 367
110 129
111/* Main struct for holding digested recurrence rules */ 130/** Main struct for holding digested recurrence rules */
112struct icalrecurrencetype 131struct icalrecurrencetype
113{ 132{
114 icalrecurrencetype_frequency freq; 133 icalrecurrencetype_frequency freq;
115 134
116 135
117 /* until and count are mutually exclusive. */ 136 /* until and count are mutually exclusive. */
118 struct icaltimetype until; 137 struct icaltimetype until;
119 int count; 138 int count;
120 139
121 short interval; 140 short interval;
122 141
123 icalrecurrencetype_weekday week_start; 142 icalrecurrencetype_weekday week_start;
@@ -136,54 +155,60 @@ struct icalrecurrencetype
136 short by_hour[ICAL_BY_HOUR_SIZE]; 155 short by_hour[ICAL_BY_HOUR_SIZE];
137 short by_day[ICAL_BY_DAY_SIZE]; /* Encoded value, see below */ 156 short by_day[ICAL_BY_DAY_SIZE]; /* Encoded value, see below */
138 short by_month_day[ICAL_BY_MONTHDAY_SIZE]; 157 short by_month_day[ICAL_BY_MONTHDAY_SIZE];
139 short by_year_day[ ICAL_BY_YEARDAY_SIZE]; 158 short by_year_day[ ICAL_BY_YEARDAY_SIZE];
140 short by_week_no[ICAL_BY_WEEKNO_SIZE]; 159 short by_week_no[ICAL_BY_WEEKNO_SIZE];
141 short by_month[ICAL_BY_MONTH_SIZE]; 160 short by_month[ICAL_BY_MONTH_SIZE];
142 short by_set_pos[ICAL_BY_SETPOS_SIZE]; 161 short by_set_pos[ICAL_BY_SETPOS_SIZE];
143}; 162};
144 163
145 164
146void icalrecurrencetype_clear(struct icalrecurrencetype *r); 165void icalrecurrencetype_clear(struct icalrecurrencetype *r);
147 166
148/* The 'day' element of the by_day array is encoded to allow 167/**
149representation of both the day of the week ( Monday, Tueday), but also 168 * Array Encoding
150the Nth day of the week ( First tuesday of the month, last thursday of 169 *
151the year) These routines decode the day values */ 170 * The 'day' element of the by_day array is encoded to allow
171 * representation of both the day of the week ( Monday, Tueday), but also
172 * the Nth day of the week ( First tuesday of the month, last thursday of
173 * the year) These routines decode the day values
174 */
152 175
153/* 1 == Monday, etc. */ 176/** 1 == Monday, etc. */
154enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day); 177enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day);
155 178
156/* 0 == any of day of week. 1 == first, 2 = second, -2 == second to last, etc */ 179/** 0 == any of day of week. 1 == first, 2 = second, -2 == second to last, etc */
157short icalrecurrencetype_day_position(short day); 180int icalrecurrencetype_day_position(short day);
158 181
159 182
160/*********************************************************************** 183/** Recurrance rule parser */
161 * Recurrance rule parser
162**********************************************************************/
163 184
164/* Convert between strings ans recurrencetype structures. */ 185/** Convert between strings and recurrencetype structures. */
165struct icalrecurrencetype icalrecurrencetype_from_string(const char* str); 186struct icalrecurrencetype icalrecurrencetype_from_string(const char* str);
166char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur); 187char* icalrecurrencetype_as_string(struct icalrecurrencetype *recur);
167 188
168 189
169/********** recurrence iteration routines ********************/ 190/** Recurrence iteration routines */
170 191
171typedef void icalrecur_iterator; 192typedef struct icalrecur_iterator_impl icalrecur_iterator;
172 193
173/* Create a new recurrence rule iterator */ 194/** Create a new recurrence rule iterator */
174icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, 195icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule,
175 struct icaltimetype dtstart); 196 struct icaltimetype dtstart);
176 197
177/* Get the next occurrence from an iterator */ 198/** Get the next occurrence from an iterator */
178struct icaltimetype icalrecur_iterator_next(icalrecur_iterator*); 199struct icaltimetype icalrecur_iterator_next(icalrecur_iterator*);
179 200
180/* Free the iterator */ 201void icalrecur_iterator_decrement_count(icalrecur_iterator*);
202
203/** Free the iterator */
181void icalrecur_iterator_free(icalrecur_iterator*); 204void icalrecur_iterator_free(icalrecur_iterator*);
182 205
183/* Fills array up with at most 'count' time_t values, each 206/**
184 representing an occurrence time in seconds past the POSIX epoch */ 207 * Fills array up with at most 'count' time_t values, each
208 * representing an occurrence time in seconds past the POSIX epoch
209 */
185int icalrecur_expand_recurrence(char* rule, time_t start, 210int icalrecur_expand_recurrence(char* rule, time_t start,
186 int count, time_t* array); 211 int count, time_t* array);
187 212
188 213
189#endif 214#endif