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