+ t = icalproperty_get_dtstart(p); // it's safe to use dtstart for all of them
+ CtdlLogPrintf(CTDL_DEBUG, "Found an icaltimetype: %s\n",
+ icaltime_as_ical_string(t)
+ );
+
+ /* First see if there's a timezone attached to the data structure itself */
+ z = icaltime_get_timezone(t);
+ if (z) CtdlLogPrintf(CTDL_DEBUG, "Timezone is present in data structure\n");
+
+ /* If not, try to determine the tzid from the parameter using attached zones */
+ if (!z) {
+ z = icalcomponent_get_timezone(top_level_cal,
+ icalparameter_get_tzid(
+ icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER)
+ )
+ );
+ if (z) CtdlLogPrintf(CTDL_DEBUG, "Timezone was found in attached zones\n");
+ }
+
+ /* Still no good? Try our internal database */
+ if (!z) {
+ z = icaltimezone_get_builtin_timezone_from_tzid(
+ icalparameter_get_tzid(
+ icalproperty_get_first_parameter(p, ICAL_TZID_PARAMETER)
+ )
+ );
+ if (z) CtdlLogPrintf(CTDL_DEBUG, "Timezone was found in internal db\n");
+ }
+
+ if (z) {
+ CtdlLogPrintf(CTDL_DEBUG, "Have valid timezone, need to attach it.\n");
+
+ zone_already_attached = 0;
+ for (i=0; i<5; ++i) {
+ if (z == attached_zones[i]) {
+ ++zone_already_attached;
+ CtdlLogPrintf(CTDL_DEBUG, "zone already attached!!\n");
+ }
+ }
+ if ((!zone_already_attached) && (num_zones_attached < 5)) {
+ CtdlLogPrintf(CTDL_DEBUG, "attach zone %d\n", num_zones_attached);
+ attached_zones[num_zones_attached++] = z;
+ }
+
+ icalproperty_set_parameter(p,
+ icalparameter_new_tzid(icaltimezone_get_tzid(z))
+ );
+ }