static void add_freebusy(struct icaltimetype *start,
			 struct icaltimetype *end,
			 icalparameter_fbtype fbtype,
			 struct calquery_filter *calfilter)
{
    struct freebusy_array *freebusy = &calfilter->freebusy;
    struct freebusy *newfb;

    /* Grow the array, if necessary */
    if (freebusy->len == freebusy->alloc) {
	freebusy->alloc += 100;  /* XXX  arbitrary */
	freebusy->fb = xrealloc(freebusy->fb,
				freebusy->alloc * sizeof(struct freebusy));
    }

    /* Add new freebusy */
    newfb = &freebusy->fb[freebusy->len++];
    if (icaltime_is_date(*start)) {
	newfb->per.duration = icaltime_subtract(*end, *start);
	newfb->per.end = icaltime_null_time();
	start->is_date = 0;  /* MUST be DATE-TIME */
	newfb->per.start =
	    icaltime_convert_to_zone(*start, icaltimezone_get_utc_timezone());
    }
    else {
	newfb->per.duration = icaldurationtype_null_duration();
	newfb->per.end = (icaltime_compare(calfilter->end, *end) < 0) ?
	    calfilter->end : *end;
	newfb->per.start = (icaltime_compare(calfilter->start, *start) > 0) ?
	    calfilter->start : *start;
    }
    newfb->type = fbtype;
}
static void add_freebusy(struct icaltimetype *start,
			 struct icaltimetype *end,
			 icalparameter_fbtype fbtype,
			 struct calquery_filter *calfilter)
{
    struct freebusy_array *freebusy = &calfilter->freebusy;
    struct freebusy *newfb;

     
    if (freebusy->len == freebusy->alloc) {
	freebusy->alloc += 100;   
	freebusy->fb = xrealloc(freebusy->fb,
				freebusy->alloc * sizeof(struct freebusy));
    }

     
    newfb = &freebusy->fb[freebusy->len++];
    if (icaltime_is_date(*start)) {
	newfb->per.duration = icaltime_subtract(*end, *start);
	newfb->per.end = icaltime_null_time();
	start->is_date = 0;   
	newfb->per.start =
	    icaltime_convert_to_zone(*start, icaltimezone_get_utc_timezone());
    }
    else {
	newfb->per.duration = icaldurationtype_null_duration();
	newfb->per.end = (icaltime_compare(calfilter->end, *end) < 0) ?
	    calfilter->end : *end;
	newfb->per.start = (icaltime_compare(calfilter->start, *start) > 0) ?
	    calfilter->start : *start;
    }
    newfb->type = fbtype;
}