NS_IMETHODIMP calDateTime::GetTimezoneOffset(int32_t *aResult) { NS_ENSURE_ARG_POINTER(aResult); icaltimetype icalt; ToIcalTime(&icalt); int dst; *aResult = icaltimezone_get_utc_offset(const_cast<icaltimezone *>(icalt.zone), &icalt, &dst); return NS_OK; }
//TODO: should not call libical functions directly -- better to make // a new libkcal abstraction method. QDateTime WebdavHandler::zoneAsUtc( const QDateTime& zone, const QString& timeZoneId ) { int daylight; QDateTime epoch; epoch.setTime_t( 0 ); time_t v = epoch.secsTo( zone ); struct icaltimetype tt = icaltime_from_timet( v, 0 ); // 0: is_date=false int offset = icaltimezone_get_utc_offset( icaltimezone_get_builtin_timezone( timeZoneId.latin1() ), &tt, &daylight ); return zone.addSecs( - offset ); }
//TODO: should not call libical functions directly -- better to make // a new libkcal abstraction method. QDateTime utcAsZone( const QDateTime& utc, const QString& timeZoneId ) { int daylight; QDateTime epoch; epoch.setTime_t( 0 ); time_t v = epoch.secsTo( utc ); struct icaltimetype tt = icaltime_from_timet( v, 0 ); // 0: is_date=false int offset = icaltimezone_get_utc_offset( icaltimezone_get_builtin_timezone( timeZoneId.latin1() ), &tt, &daylight ); return utc.addSecs( offset ); }
//TODO: should not call libical functions directly -- better to make // a new libkcal abstraction method. QDateTime WebdavHandler::utcAsZone( const QDateTime& utc, const QString& timeZoneId ) { int daylight; QDateTime epoch; epoch.setTime_t( 0 ); time_t v = epoch.secsTo( utc ); struct icaltimetype tt = icaltime_from_timet_with_zone( v, 0 /*is_date*/, icaltimezone_get_builtin_timezone( "UTC" ) ); int offset = icaltimezone_get_utc_offset( icaltimezone_get_builtin_timezone( timeZoneId.latin1() ), &tt, &daylight ); kdDebug() << "Calculated offset of: " << offset << " of timezone: " << timeZoneId << endl; return utc.addSecs( offset ); }
int main(int argc, char *argv[]) { char *dtstr = "20031026T190000"; icaltimezone *zone; struct icaltimetype tt; int utc_offset; if (argc > 1) { dtstr = argv[1]; } icalcomponent *zonecomp = icalcomponent_new_from_string(mytz); zone = icaltimezone_new(); icaltimezone_set_component(zone, zonecomp); tt = icaltime_from_string(dtstr); icaltime_set_timezone(&tt, zone); utc_offset = icaltimezone_get_utc_offset(zone, &tt, NULL); printf("OFFSET for %s is %d %p\n", dtstr, utc_offset, zone); }
void icaltimezone_convert_time (struct icaltimetype *tt, icaltimezone *from_zone, icaltimezone *to_zone) { int utc_offset, is_daylight; /* If the time is a DATE value or both timezones are the same, or we are converting a floating time, we don't need to do anything. */ if (icaltime_is_date(*tt) || from_zone == to_zone || from_zone == NULL) return; /* Convert the time to UTC by getting the UTC offset and subtracting it. */ utc_offset = icaltimezone_get_utc_offset (from_zone, tt, NULL); icaltime_adjust (tt, 0, 0, 0, -utc_offset); /* Now we convert the time to the new timezone by getting the UTC offset of our UTC time and adding it. */ utc_offset = icaltimezone_get_utc_offset_of_utc_time (to_zone, tt, &is_daylight); tt->is_daylight = is_daylight; icaltime_adjust (tt, 0, 0, 0, utc_offset); }