Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
icalduration.h File Reference
#include "icaltime.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  icaldurationtype

Functions

struct icaldurationtype icaldurationtype_from_int (int t)
struct icaldurationtype icaldurationtype_from_string (const char *)
int icaldurationtype_as_int (struct icaldurationtype duration)
char * icaldurationtype_as_ical_string (struct icaldurationtype d)
struct icaldurationtype icaldurationtype_null_duration (void)
struct icaldurationtype icaldurationtype_bad_duration (void)
int icaldurationtype_is_null_duration (struct icaldurationtype d)
int icaldurationtype_is_bad_duration (struct icaldurationtype d)
struct icaltimetype icaltime_add (struct icaltimetype t, struct icaldurationtype d)
struct icaldurationtype icaltime_subtract (struct icaltimetype t1, struct icaltimetype t2)

Class Documentation

struct icaldurationtype

Definition at line 394 of file ical.h.

Collaboration diagram for icaldurationtype:
Class Members
unsigned int days
unsigned int hours
int is_neg
unsigned int minutes
unsigned int seconds
unsigned int weeks

Function Documentation

Definition at line 201 of file icalduration.c.

{

    char *buf, *output_line;
    size_t buf_size = 256;
    char* buf_ptr = 0;
    int seconds;

    buf = (char*)icalmemory_new_buffer(buf_size);
    buf_ptr = buf;
    

    seconds = icaldurationtype_as_int(d);

    if(seconds !=0){
       
       if(d.is_neg == 1){
           icalmemory_append_char(&buf, &buf_ptr, &buf_size, '-'); 
       }

       icalmemory_append_char(&buf, &buf_ptr, &buf_size, 'P');
    
       if (d.weeks != 0 ) {
           append_duration_segment(&buf, &buf_ptr, &buf_size, "W", d.weeks);
       }
       
       if (d.days != 0 ) {
           append_duration_segment(&buf, &buf_ptr, &buf_size, "D", d.days);
       }
       
       if (d.hours != 0 || d.minutes != 0 || d.seconds != 0) {
           
           icalmemory_append_string(&buf, &buf_ptr, &buf_size, "T");
           
           if (d.hours != 0 ) {
              append_duration_segment(&buf, &buf_ptr, &buf_size, "H", d.hours);
           }
           if (d.minutes != 0 ) {
              append_duration_segment(&buf, &buf_ptr, &buf_size, "M", 
                                   d.minutes);
           }
           if (d.seconds != 0 ) {
              append_duration_segment(&buf, &buf_ptr, &buf_size, "S", 
                                   d.seconds);
           }
           
       }
    } else {
       icalmemory_append_string(&buf, &buf_ptr, &buf_size, "PT0S");
    }
 
    output_line = icalmemory_tmp_copy(buf);
    icalmemory_free_buffer(buf);

    return output_line;
    
}

Here is the call graph for this function:

Definition at line 261 of file icalduration.c.

{
    return (int)( (dur.seconds +
                 (60 * dur.minutes) +
                 (60 * 60 * dur.hours) +
                 (60 * 60 * 24 * dur.days) +
                 (60 * 60 * 24 * 7 * dur.weeks))
                * (dur.is_neg==1? -1 : 1) ) ;
} 

Definition at line 296 of file icalduration.c.

{
    struct icaldurationtype d;
    memset(&d,0,sizeof(struct icaldurationtype));
    d.is_neg = -1;
    return d;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 49 of file icalduration.c.

{
    struct icaldurationtype dur;
    int used = 0;

    dur = icaldurationtype_null_duration();

    if(t < 0){
       dur.is_neg = 1;
       t = -t;
    }

    if (t % (60 * 60 * 24 * 7) == 0) {
       dur.weeks = t / (60 * 60 * 24 * 7);
    } else {
       used += dur.weeks * (60 * 60 * 24 * 7);
       dur.days = (t - used) / (60 * 60 * 24);
       used += dur.days * (60 * 60 * 24);
       dur.hours = (t - used) / (60 * 60);
       used += dur.hours * (60 * 60);
       dur.minutes = (t - used) / (60);
       used += dur.minutes * (60);
       dur.seconds = (t - used);
    }
 
    return dur;
}

Here is the call graph for this function:

Definition at line 77 of file icalduration.c.

{

    int i;
    int begin_flag = 0;
    int time_flag = 0;
    int date_flag = 0;
    int week_flag = 0;
    int digits=-1;
    int scan_size = -1;
    int size = strlen(str);
    char p;
    struct icaldurationtype d;

    memset(&d, 0, sizeof(struct icaldurationtype));

    for(i=0;i != size;i++){
       p = str[i];
       
       switch(p) 
           {
           case '-': {
              if(i != 0 || begin_flag == 1) goto error;

              d.is_neg = 1;
              break;
           }

           case 'P': {
              if (i != 0 && i !=1 ) goto error;
              begin_flag = 1;
              break;
           }

           case 'T': {
              time_flag = 1;
              break;
           }

           case '0':
           case '1':
           case '2':
           case '3':
           case '4':
           case '5':
           case '6':
           case '7':
           case '8':
           case '9':
              { 
                  
                  /* HACK. Skip any more digits if the l;ast one
                       read has not been assigned */
                  if(digits != -1){
                     break;
                  }

                  if (begin_flag == 0) goto error;
                  /* Get all of the digits, not one at a time */
                  scan_size = sscanf(&str[i],"%d",&digits);
                  if(scan_size == 0) goto error;
                  break;
              }

           case 'H': {      
              if (time_flag == 0||week_flag == 1||d.hours !=0||digits ==-1) 
                  goto error;
              d.hours = digits; digits = -1;
              break;
           }
           case 'M': {
              if (time_flag == 0||week_flag==1||d.minutes != 0||digits ==-1) 
                  goto error;
              d.minutes = digits; digits = -1;       
              break;
           }
           case 'S': {
              if (time_flag == 0||week_flag==1||d.seconds!=0||digits ==-1) 
                  goto error;
              d.seconds = digits; digits = -1;       
              break;
           }
           case 'W': {
              if (time_flag==1||date_flag==1||d.weeks!=0||digits ==-1) 
                  goto error;
              week_flag = 1;       
              d.weeks = digits; digits = -1;         
              break;
           }
           case 'D': {
              if (time_flag==1||week_flag==1||d.days!=0||digits ==-1) 
                  goto error;
              date_flag = 1;
              d.days = digits; digits = -1;          
              break;
           }
           default: {
              goto error;
           }

           }
    }

    return d;
       

 error:
    icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
    return icaldurationtype_bad_duration();
}

Here is the call graph for this function:

Definition at line 304 of file icalduration.c.

{
    return (d.is_neg == -1);
}

Here is the caller graph for this function:

Definition at line 280 of file icalduration.c.

{
    if(icaldurationtype_as_int(d) == 0){
       return 1;
    } else {
       return 0;
    }
}

Here is the call graph for this function:

Definition at line 271 of file icalduration.c.

{
    struct icaldurationtype d;
    
    memset(&d,0,sizeof(struct icaldurationtype));
    
    return d;
}

Here is the call graph for this function:

struct icaltimetype icaltime_add ( struct icaltimetype  t,
struct icaldurationtype  d 
) [read]

Definition at line 310 of file icalduration.c.

{
    if (!d.is_neg) {
        t.second += d.seconds;
        t.minute += d.minutes;
        t.hour += d.hours;
        t.day += d.days;
        t.day += d.weeks * 7;
    } else {
        t.second -= d.seconds;
        t.minute -= d.minutes;
        t.hour -= d.hours;
        t.day -= d.days;
        t.day -= d.weeks * 7;
    }
    
    t = icaltime_normalize(t);
    
    return t;
}

Here is the call graph for this function:

struct icaldurationtype icaltime_subtract ( struct icaltimetype  t1,
struct icaltimetype  t2 
) [read]

Definition at line 332 of file icalduration.c.

{

    time_t t1t = icaltime_as_timet(t1);
    time_t t2t = icaltime_as_timet(t2);

    return icaldurationtype_from_int((int)(t1t-t2t));


}

Here is the call graph for this function: