4 * Function to go through an ical component set and convert all non-UTC
5 * date/time properties to UTC. It also strips out any VTIMEZONE
6 * subcomponents afterwards, because they're irrelevant.
14 #include <sys/types.h>
21 #include "citserver.h"
22 #include "sysdep_decls.h"
26 #ifdef CITADEL_WITH_CALENDAR_SERVICE
28 #include "ical_dezonify.h"
32 * Back end function for ical_dezonify()
34 * We supply this with the master component, the relevant component,
35 * and the property (which will be a DTSTART, DTEND, etc.)
36 * which we want to convert to UTC.
38 void ical_dezonify_backend(icalcomponent *cal,
42 icaltimezone *t = NULL;
45 struct icaltimetype TheTime;
47 /* Give me nothing and I will give you nothing in return. */
48 if (cal == NULL) return;
50 /* Hunt for a TZID parameter in this property. */
51 param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER);
53 /* Get the stringish name of this TZID. */
55 tzid = icalparameter_get_tzid(param);
57 /* Convert it to an icaltimezone type. */
59 t = icalcomponent_get_timezone(cal, tzid);
64 /* Now we know the timezone. Convert to UTC. */
66 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
67 TheTime = icalproperty_get_dtstart(prop);
69 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
70 TheTime = icalproperty_get_dtend(prop);
72 else if (icalproperty_isa(prop) == ICAL_DUE_PROPERTY) {
73 TheTime = icalproperty_get_due(prop);
75 else if (icalproperty_isa(prop) == ICAL_EXDATE_PROPERTY) {
76 TheTime = icalproperty_get_exdate(prop);
82 /* Do the conversion. */
84 icaltimezone_convert_time(&TheTime,
86 icaltimezone_get_utc_timezone()
90 icalproperty_remove_parameter_by_kind(prop, ICAL_TZID_PARAMETER);
92 /* Now add the converted property back in. */
93 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
94 icalproperty_set_dtstart(prop, TheTime);
96 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
97 icalproperty_set_dtend(prop, TheTime);
99 else if (icalproperty_isa(prop) == ICAL_DUE_PROPERTY) {
100 icalproperty_set_due(prop, TheTime);
102 else if (icalproperty_isa(prop) == ICAL_EXDATE_PROPERTY) {
103 icalproperty_set_exdate(prop, TheTime);
109 * Recursive portion of ical_dezonify()
111 void ical_dezonify_recur(icalcomponent *cal, icalcomponent *rcal) {
116 * Recurse through all subcomponents *except* VTIMEZONE ones.
118 for (c=icalcomponent_get_first_component(
119 rcal, ICAL_ANY_COMPONENT);
121 c = icalcomponent_get_next_component(
122 rcal, ICAL_ANY_COMPONENT)
124 if (icalcomponent_isa(c) != ICAL_VTIMEZONE_COMPONENT) {
125 ical_dezonify_recur(cal, c);
130 * Now look for DTSTART and DTEND properties
132 for (p=icalcomponent_get_first_property(
133 rcal, ICAL_ANY_PROPERTY);
135 p = icalcomponent_get_next_property(
136 rcal, ICAL_ANY_PROPERTY)
139 (icalproperty_isa(p) == ICAL_DTSTART_PROPERTY)
140 || (icalproperty_isa(p) == ICAL_DTEND_PROPERTY)
141 || (icalproperty_isa(p) == ICAL_DUE_PROPERTY)
142 || (icalproperty_isa(p) == ICAL_EXDATE_PROPERTY)
144 ical_dezonify_backend(cal, rcal, p);
151 * Convert all DTSTART and DTEND properties in all subcomponents to UTC.
152 * This function will search any VTIMEZONE subcomponents to learn the
153 * relevant timezone information.
155 void ical_dezonify(icalcomponent *cal) {
156 icalcomponent *vt = NULL;
158 /* Convert all times to UTC */
159 ical_dezonify_recur(cal, cal);
161 /* Strip out VTIMEZONE subcomponents -- we don't need them anymore */
162 while (vt = icalcomponent_get_first_component(
163 cal, ICAL_VTIMEZONE_COMPONENT), vt != NULL) {
164 icalcomponent_remove_component(cal, vt);
165 icalcomponent_free(vt);
171 #endif /* CITADEL_WITH_CALENDAR_SERVICE */