9 void ical_dezonify(icalcomponent *cal);
12 * Back end function for ical_dezonify()
14 * We supply this with the master component and the property (which will
15 * be a DTSTART or DTEND) which we want to convert to UTC.
17 void ical_dezonify_backend(icalcomponent *cal, icalproperty *prop) {
21 struct icaltimetype TheTime;
23 /* Give me nothing and I will give you nothing in return. */
24 if (cal == NULL) return;
26 /* Hunt for a TZID parameter in this property. */
27 param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER);
29 printf("No tzid parameter found - "
30 "perhaps this component is already UTC?\n");
34 /* Get the stringish name of this TZID. */
35 tzid = icalparameter_get_tzid(param);
37 printf("icalparameter_get_tzid() returned NULL\n");
41 /* Convert it to an icaltimezone type. */
42 t = icalcomponent_get_timezone(cal, tzid);
44 printf("icalcomponent_get_timezone(%s) returned NULL\n", tzid);
47 /* Now we know the timezone. Convert to UTC. */
49 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
50 TheTime = icalproperty_get_dtstart(prop);
52 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
53 TheTime = icalproperty_get_dtend(prop);
57 * (I had to specify the 'from' and 'to' timezones backwards. Is the
58 * API documentation wrong?)
60 icaltimezone_convert_time(&TheTime,
61 icaltimezone_get_utc_timezone(),
65 /* Now strip the TZID parameter, because it's incorrect now. */
66 icalproperty_remove_parameter(prop, ICAL_TZID_PARAMETER);
68 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
69 icalproperty_set_dtstart(prop, TheTime);
71 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
72 icalproperty_set_dtend(prop, TheTime);
79 * Recursive portion of ical_dezonify()
81 void ical_dezonify_recur(icalcomponent *cal, icalcomponent *rcal) {
86 * Recurse through all subcomponents *except* VTIMEZONE ones.
88 for (c=icalcomponent_get_first_component(
89 rcal, ICAL_ANY_COMPONENT);
91 c = icalcomponent_get_next_component(
92 rcal, ICAL_ANY_COMPONENT)
94 if (icalcomponent_isa(c) != ICAL_VTIMEZONE_COMPONENT) {
95 ical_dezonify_recur(cal, c);
100 * Now look for DTSTART and DTEND properties
102 for (p=icalcomponent_get_first_property(
103 rcal, ICAL_ANY_PROPERTY);
105 p = icalcomponent_get_next_property(
106 rcal, ICAL_ANY_PROPERTY)
109 (icalproperty_isa(p) == ICAL_DTSTART_PROPERTY)
110 || (icalproperty_isa(p) == ICAL_DTEND_PROPERTY)
112 ical_dezonify_backend(cal, p);
119 * Convert all DTSTART and DTEND properties in all subcomponents to UTC.
120 * This function will search any VTIMEZONE subcomponents to learn the
121 * relevant timezone information.
123 void ical_dezonify(icalcomponent *cal) {
124 icalcomponent *vt = NULL;
126 /* Convert all times to UTC */
127 ical_dezonify_recur(cal, cal);
129 /* Strip out VTIMEZONE subcomponents -- we don't need them anymore */
130 while (vt = icalcomponent_get_first_component(
131 cal, ICAL_VTIMEZONE_COMPONENT), vt != NULL) {
132 icalcomponent_remove_component(cal, vt);
133 icalcomponent_free(vt);