ecomp != 0 ? ecomp : 0 ;
}
-static date_t to_date(struct icaltimetype time)
+static date_t to_date(struct icaltimetype itime)
{
- return (date_t){
- .year = time.year,
- .month = time.month ? time.month-1 : 0,
- .day = time.day ? time.day -1 : 0,
- .hour = time.hour,
- .min = time.minute,
- };
+ return get_date(icaltime_as_timet_with_zone(itime, itime.zone));
}
-static icaltimetype to_itime(date_t time)
+static icaltimetype to_itime(date_t date)
{
- return (struct icaltimetype){
- .year = time.year,
- .month = time.month + 1,
- .day = time.day + 1,
- .hour = time.hour,
- .minute = time.min
- };
+ return icaltime_from_timet_with_zone(get_stamp(date), 0, NULL);
}
static void add_recur(cal_t *cal,
/* Add all recurrences */
rrule = icalcomponent_get_first_property(comp, ICAL_RRULE_PROPERTY);
+
+ /* One-time event */
+ if (!rrule) {
+ icalarray_append(array, &(ical_inst){
+ .cal = cal,
+ .comp = comp,
+ .start = cstart,
+ .end = cend,
+ });
+ }
+
+ /* Recurring events */
while (rrule) {
recur = icalproperty_get_rrule(rrule);
iter = icalrecur_iterator_new(recur, cstart);
static void read_icals(void)
{
for (ical_t *cal = calendars; cal; cal = cal->next) {
- if (cal->comp == NULL && cal->location) {
- wordexp_t wexp;
- wordexp(cal->location, &wexp, WRDE_NOCMD);
- icalparser *parser = icalparser_new();
- for (int i = 0; i < wexp.we_wordc; i++) {
- FILE *file = fopen(wexp.we_wordv[i], "r");
- if (!file)
- continue;
- icalparser_set_gen_data(parser, file);
- }
+ if (!cal->location)
+ debug("Missing location for ical '%s'", cal->cal.name);
+ if (cal->comp)
+ continue;
+ wordexp_t wexp;
+ wordexp(cal->location, &wexp, WRDE_NOCMD);
+ icalparser *parser = icalparser_new();
+ if (wexp.we_wordc > 1)
+ debug("Multiple calendards are not supported '%s'", cal->location);
+ FILE *file = fopen(wexp.we_wordv[0], "r");
+ if (!file) {
+ debug("Cannot open ical file '%s'", wexp.we_wordv[0]);
+ } else {
+ icalparser_set_gen_data(parser, file);
cal->comp = icalparser_parse(parser, (void*)fgets);
icalparser_free(parser);
- wordfree(&wexp);
}
+ wordfree(&wexp);
}
}
last->next = cal;
else
calendars = cal;
- return;
}
/* Set calendar values */