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

time_t icaltime_as_timet_with_zone ( const struct icaltimetype  tt,
const icaltimezone *  zone 
)

Return the time as seconds past the UNIX epoch, using timezones.

Return the time as seconds past the UNIX epoch, using the given timezone.

This convenience method combines a call to icaltime_convert_to_zone() with a call to icaltime_as_timet(). If the input timezone is null, no conversion is done; that is, the time is simply returned as time_t in its native timezone.

Definition at line 386 of file icaltime.c.

References icaltimezone_convert_time(), and icaltimezone_get_utc_timezone().

{
    icaltimezone *utc_zone;
    struct tm stm;
    time_t t;
    char *old_tz;
    struct icaltimetype local_tt;
    
    utc_zone = icaltimezone_get_utc_timezone ();

    /* If the time is the special null time, return 0. */
    if (icaltime_is_null_time(tt)) {
      return 0;
    }

    local_tt = tt;
    
    /* Clear the is_date flag, so we can convert the time. */
    local_tt.is_date = 0;

    /* Use our timezone functions to convert to UTC. */
    icaltimezone_convert_time (&local_tt, (icaltimezone *)zone, utc_zone);

    /* Copy the icaltimetype to a struct tm. */
    memset (&stm, 0, sizeof (struct tm));

    stm.tm_sec = local_tt.second;
    stm.tm_min = local_tt.minute;
    stm.tm_hour = local_tt.hour;
    stm.tm_mday = local_tt.day;
    stm.tm_mon = local_tt.month-1;
    stm.tm_year = local_tt.year-1900;
    stm.tm_isdst = -1;
/* The functions putenv and mktime are not thread safe, inserting a lock
to prevent any crashes */

#ifdef HAVE_PTHREAD
    pthread_mutex_lock (&tzid_mutex);
#endif
    
    /* Set TZ to UTC and use mktime to convert to a time_t. */
    old_tz = set_tz ("UTC");
#ifdef WIN32
    tzset ();
#endif

    t = mktime (&stm);
    unset_tz (old_tz);
#ifdef WIN32
    tzset ();
#endif

#ifdef HAVE_PTHREAD
    pthread_mutex_unlock (&tzid_mutex);
#endif
    return t;
}


Generated by  Doxygen 1.6.0   Back to index