diff options
| author | erdgeist <erdgeist@bauklotz.local> | 2009-03-15 04:00:40 +0100 |
|---|---|---|
| committer | erdgeist <erdgeist@bauklotz.local> | 2009-03-15 04:00:40 +0100 |
| commit | f40972938df392d245c9b5a910d22243def6f9c5 (patch) | |
| tree | e5f304ec15e3441d9338250368ae688026af5c0f /lib/chaos_calendar/ical_occurrences.c | |
| parent | c9fa047402fdc009319dca7b05455e8ce73eaee7 (diff) | |
ruby wrapper around libical
Diffstat (limited to 'lib/chaos_calendar/ical_occurrences.c')
| -rw-r--r-- | lib/chaos_calendar/ical_occurrences.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/chaos_calendar/ical_occurrences.c b/lib/chaos_calendar/ical_occurrences.c new file mode 100644 index 00000000..2f36d8c5 --- /dev/null +++ b/lib/chaos_calendar/ical_occurrences.c | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | #include <ruby.h> | ||
| 2 | #include <ical.h> | ||
| 3 | |||
| 4 | //#define RRULE "FREQ=MONTHLY;BYMONTH=1,2,3,4,5,6,7,8,9,10,11;BYDAY=-1WE;UNTIL=20091105T220000" | ||
| 5 | //#define RRULE "FREQ=DAILY;UNTIL=20991111T220000;VFOO" | ||
| 6 | //#define DTSTART "20000101T010000" | ||
| 7 | |||
| 8 | VALUE occurrences( char *dtstart, char *dtend, char *rrule ) { | ||
| 9 | VALUE occurr = rb_ary_new(); | ||
| 10 | |||
| 11 | icalerror_clear_errno(); | ||
| 12 | icalerror_set_error_state( ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL); | ||
| 13 | |||
| 14 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); | ||
| 15 | if( icalerrno != ICAL_NO_ERROR ) { | ||
| 16 | printf( "libical error: %i. -- 1\n", icalerrno ); | ||
| 17 | return occurr; | ||
| 18 | } | ||
| 19 | struct icaltimetype start = icaltime_from_string( dtstart ); | ||
| 20 | if( icalerrno != ICAL_NO_ERROR ) { | ||
| 21 | printf( "libical error: %i. -- 2\n", icalerrno ); | ||
| 22 | return occurr; | ||
| 23 | } | ||
| 24 | struct icaltimetype end = icaltime_from_string( dtend ); | ||
| 25 | if( icalerrno != ICAL_NO_ERROR ) { | ||
| 26 | printf( "libical error: %i. -- 3\n", icalerrno ); | ||
| 27 | return occurr; | ||
| 28 | } | ||
| 29 | |||
| 30 | icalrecur_iterator* ritr = icalrecur_iterator_new( recur, start ); | ||
| 31 | |||
| 32 | while(1) { | ||
| 33 | // char outbuf[1024] = {0}; | ||
| 34 | struct icaltimetype next = icalrecur_iterator_next(ritr); | ||
| 35 | |||
| 36 | if( icaltime_is_null_time(next) || ( icaltime_compare( next, end ) > 0 ) ) { | ||
| 37 | icalrecur_iterator_free(ritr); | ||
| 38 | return occurr; | ||
| 39 | } | ||
| 40 | |||
| 41 | rb_ary_push( occurr, rb_time_new( icaltime_as_timet( next ), 0 ) ); | ||
| 42 | // print_datetime_to_string( outbuf, &next ); | ||
| 43 | // rb_ary_push( occurr, rb_str_new2( outbuf ) ); | ||
| 44 | }; | ||
| 45 | |||
| 46 | icalrecur_iterator_free(ritr); | ||
| 47 | return occurr; | ||
| 48 | } | ||
