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

struct icaltimetype icaltime_from_timet_with_zone ( const time_t  tm,
const int  is_date,
const icaltimezone *  zone 
) [read]


Convert seconds past UNIX epoch to a timetype, using timezones.

tm The time
is_date Boolean: 1 means we should treat tm as a DATE
zone The timezone tm is in, NULL means to treat tm as a floating time
Return a new icaltime instance, initialized to the given time expressed as seconds past UNIX epoch, optionally using the given timezone.

If the caller specifies the is_date param as TRUE, the returned object is of DATE type, otherwise the input is meant to be of DATE-TIME type. If the zone is not specified (NULL zone param) the time is taken to be floating, that is, valid in any timezone. Note that, in addition to the uses specified in [RFC2445], this can be used when doing simple math on couples of times. If the zone is specified (UTC or otherwise), it's stored in the object and it's used as the native timezone for this object. This means that the caller can convert this time to a different target timezone with no need to store the source timezone.

Definition at line 195 of file icaltime.c.

References icaltimezone_convert_time(), and icaltimezone_get_utc_timezone().

    struct icaltimetype tt;
    struct tm t;
    icaltimezone *utc_zone;

    utc_zone = icaltimezone_get_utc_timezone ();

    /* Convert the time_t to a struct tm in UTC time. We can trust gmtime
       for this. */
    gmtime_r (&tm, &t);
    t = *(gmtime (&tm));
    tt.year   = t.tm_year + 1900;
    tt.month  = t.tm_mon + 1;
    tt.day    = t.tm_mday;
    tt.hour   = t.tm_hour;
    tt.minute = t.tm_min;
    tt.second = t.tm_sec;
    tt.is_date = 0; 
    tt.is_utc = (zone == utc_zone) ? 1 : 0;
    tt.is_daylight = 0;
    tt.zone = NULL;

    /* Use our timezone functions to convert to the required timezone. */
    icaltimezone_convert_time (&tt, utc_zone, (icaltimezone *)zone);

    tt.is_date = is_date; 

    /* If it is a DATE value, make sure hour, minute & second are 0. */
    if (is_date) { 
      tt.hour   = 0;
      tt.minute = 0;
      tt.second = 0;

    return tt;

Generated by  Doxygen 1.6.0   Back to index