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

struct icaltimetype icaltime_from_string ( const char *  str  )  [read]

Contructor.

create a time from an ISO format string

Create a time from an ISO format string.

Todo:
If the given string specifies a DATE-TIME not in UTC, there is no way to know if this is a floating time or really refers to a timezone. We should probably add a new constructor: icaltime_from_string_with_zone()

Definition at line 500 of file icaltime.c.

References icaltimezone_get_utc_timezone().

{
    struct icaltimetype tt = icaltime_null_time();
    int size;

    icalerror_check_arg_re(str!=0,"str",icaltime_null_time());

    size = strlen(str);
    
    if ((size == 15) || (size == 19)) { /* floating time with/without separators*/
      tt.is_utc = 0;
      tt.is_date = 0;
    } else if ((size == 16) || (size == 20)) { /* UTC time, ends in 'Z'*/
      if ((str[15] != 'Z') && (str[19] != 'Z'))
          goto FAIL;

      tt.is_utc = 1;
      tt.zone = icaltimezone_get_utc_timezone();
      tt.is_date = 0;
    } else if ((size == 8) || (size == 10)) { /* A DATE */
      tt.is_utc = 0;
      tt.is_date = 1;
    } else { /* error */
      goto FAIL;
    }

    if (tt.is_date == 1){
        if (size == 10) {
            char dsep1, dsep2;    
            if (sscanf(str,"%04d%c%02d%c%02d",&tt.year,&dsep1,&tt.month,&dsep2,&tt.day) < 5)
                goto FAIL;
            if ((dsep1 != '-') || (dsep2 != '-'))
                goto FAIL;
        } else if (sscanf(str,"%04d%02d%02d",&tt.year,&tt.month,&tt.day) < 3) {
          goto FAIL;
        }    
    } else {
       if (size > 16 ) {
         char dsep1, dsep2, tsep, tsep1, tsep2;      
         if (sscanf(str,"%04d%c%02d%c%02d%c%02d%c%02d%c%02d",&tt.year,&dsep1,&tt.month,&dsep2,
                &tt.day,&tsep,&tt.hour,&tsep1,&tt.minute,&tsep2,&tt.second) < 11)
          goto FAIL;

      if((tsep != 'T') || (dsep1 != '-') || (dsep2 != '-') || (tsep1 != ':') || (tsep2 != ':'))
          goto FAIL;

       } else {        
      char tsep;
      if (sscanf(str,"%04d%02d%02d%c%02d%02d%02d",&tt.year,&tt.month,&tt.day,
             &tsep,&tt.hour,&tt.minute,&tt.second) < 7)
          goto FAIL;

      if(tsep != 'T')
          goto FAIL;
       }
    }

    return tt;    

FAIL:
    icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
    return icaltime_null_time();
}


Generated by  Doxygen 1.6.0   Back to index