Logo Search packages:      
Sourcecode: libical version File versions

static pvl_list expand_by_day ( icalrecur_iterator impl,
int  year 
) [static]

Expand the BYDAY rule part and return a pointer to a newly allocated list of days.

Definition at line 1760 of file icalrecur.c.

References icalrecurrencetype_day_day_of_week(), and icalrecurrencetype_day_position().

{
    /* Try to calculate each of the occurrences. */
    int i;
    pvl_list days_list = pvl_newlist();

    int start_dow, end_dow, end_year_day;
    struct icaltimetype tmp = impl->last;
    
    tmp.year= year;
    tmp.month = 1;
    tmp.day = 1;
    tmp.is_date = 1;
    
    /* Find the day that 1st Jan falls on, 1 (Sun) to 7 (Sat). */
    start_dow = icaltime_day_of_week(tmp);
    
    /* Get the last day of the year*/
    tmp.year= year;
    tmp.month = 12;
    tmp.day = 31;
    tmp.is_date = 1;
    
    end_dow =  icaltime_day_of_week(tmp);
    end_year_day = icaltime_day_of_year(tmp);
    
    for(i = 0; BYDAYPTR[i] != ICAL_RECURRENCE_ARRAY_MAX; i++){
        /* This is 1 (Sun) to 7 (Sat). */
        int dow = 
            icalrecurrencetype_day_day_of_week(BYDAYPTR[i]);  
        int pos =  icalrecurrencetype_day_position(BYDAYPTR[i]);
        
        if(pos == 0){
            /* The day was specified without a position -- it is just
               a bare day of the week ( BYDAY=SU) so add all of the
               days of the year with this day-of-week*/
            int doy, tmp_start_doy;
                
          tmp_start_doy = ((dow + 7 - start_dow) % 7) + 1;

            for (doy = tmp_start_doy; doy <= end_year_day; doy += 7)
                    pvl_push(days_list,(void*)(ptrdiff_t)doy);
            
        } else if ( pos > 0) {
            int first;
            /* First occurrence of dow in year */
            if( dow >= start_dow) {
                first = dow - start_dow + 1;
            } else {
                first = dow - start_dow + 8;
            }

            /* Then just multiple the position times 7 to get the pos'th day in the year */
            pvl_push(days_list,(void*)(first+  (pos-1) * 7));
            
        } else { /* pos < 0 */ 
            int last;
            pos = -pos;

            /* last occurrence of dow in year */
            if( dow <= end_dow) {
                last = end_year_day - end_dow + dow;
            } else {
                last = end_year_day - end_dow + dow - 7;
            }

            pvl_push(days_list,(void*)(last - (pos-1) * 7));
        }
    }
    return days_list;
}


Generated by  Doxygen 1.6.0   Back to index