Logo Search packages:      
Sourcecode: libical version File versions  Download package

struct icalperiodtype icalspanlist_next_free_time ( icalspanlist *  sl,
struct icaltimetype  t 
) [read]

Find next free time span in a spanlist.

Get first next free time after time t. all times are in UTC.

Parameters:
sl The spanlist to search.
t The time to start looking.
Given a spanlist and a time, find the next period of time that is free

Definition at line 282 of file icalspanlist.c.

References icaltime_span::end, icaltime_span::is_busy, and icaltime_span::start.

{
     pvl_elem itr;
     struct icalperiodtype period;
     struct icaltime_span *s;

     time_t rangett= icaltime_as_timet(t);

     period.start = icaltime_null_time();
     period.end = icaltime_null_time();

     itr = pvl_head(sl->spans);
     s = (struct icaltime_span *)pvl_data(itr);

     if (s == 0){
       /* No elements in span */
       return period;
     }

     /* Is the reference time before the first span? If so, assume
        that the reference time is free */
     if(rangett <s->start ){
       /* End of period is start of first span if span is busy, end
            of the span if it is free */
       period.start =  t;

       if (s->is_busy == 1){
           period.end =  icaltime_from_timet(s->start,0);
       } else {
           period.end =  icaltime_from_timet(s->end,0);
       }

       return period;
     }

     /* Otherwise, find the first free span that contains the
        reference time. */
     for( itr = pvl_head(sl->spans);
       itr != 0;
       itr = pvl_next(itr))
    {
      s = (struct icaltime_span *)pvl_data(itr);

      if(s->is_busy == 0 && s->start >= rangett && 
          ( rangett < s->end || s->end == s->start)){

          if (rangett < s->start){
            period.start = icaltime_from_timet(s->start,0);
          } else {
            period.start = icaltime_from_timet(rangett,0);
          }
          
          period.end = icaltime_from_timet(s->end,0);

          return period;
      }
                  
    }

     period.start = icaltime_null_time();
     period.end = icaltime_null_time();

     return period;
}


Generated by  Doxygen 1.6.0   Back to index