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 363 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) { /* floating time */
      tt.is_utc = 0;
      tt.is_date = 0;
    } else if (size == 16) { /* UTC time, ends in 'Z'*/
      if(str[15] != 'Z')
          goto errorlabel;

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

    if(tt.is_date == 1){
      if (sscanf(str,"%04d%02d%02d",&tt.year,&tt.month,&tt.day) < 3)
          goto errorlabel;
    } 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 errorlabel;

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

    return tt;    

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


Generated by  Doxygen 1.6.0   Back to index