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.
13 #include <sys/types.h>
20 #include "citserver.h"
21 #include "sysdep_decls.h"
27 #include "ical_dezonify.h"
31 * Back end function for ical_dezonify()
33 * We supply this with the master component, the relevant component,
34 * and the property (which will be a DTSTART, DTEND, etc.)
35 * which we want to convert to UTC.
37 void ical_dezonify_backend(icalcomponent *cal,
44 struct icaltimetype TheTime;
46 /* Give me nothing and I will give you nothing in return. */
47 if (cal == NULL) return;
49 /* Hunt for a TZID parameter in this property. */
50 param = icalproperty_get_first_parameter(prop, ICAL_TZID_PARAMETER);
51 if (param == NULL) return;
53 /* Get the stringish name of this TZID. */
54 tzid = icalparameter_get_tzid(param);
55 if (tzid == NULL) return;
57 /* Convert it to an icaltimezone type. */
58 t = icalcomponent_get_timezone(cal, tzid);
59 if (t == NULL) return;
61 /* Now we know the timezone. Convert to UTC. */
63 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
64 TheTime = icalproperty_get_dtstart(prop);
66 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
67 TheTime = icalproperty_get_dtend(prop);
69 else if (icalproperty_isa(prop) == ICAL_DUE_PROPERTY) {
70 TheTime = icalproperty_get_due(prop);
72 else if (icalproperty_isa(prop) == ICAL_EXDATE_PROPERTY) {
73 TheTime = icalproperty_get_exdate(prop);
79 /* Do the conversion. */
80 icaltimezone_convert_time(&TheTime,
82 icaltimezone_get_utc_timezone()
85 icalproperty_remove_parameter_by_kind(prop, ICAL_TZID_PARAMETER);
87 /* Now add the converted property back in. */
88 if (icalproperty_isa(prop) == ICAL_DTSTART_PROPERTY) {
89 icalproperty_set_dtstart(prop, TheTime);
91 else if (icalproperty_isa(prop) == ICAL_DTEND_PROPERTY) {
92 icalproperty_set_dtend(prop, TheTime);
94 else if (icalproperty_isa(prop) == ICAL_DUE_PROPERTY) {
95 icalproperty_set_due(prop, TheTime);
97 else if (icalproperty_isa(prop) == ICAL_EXDATE_PROPERTY) {
98 icalproperty_set_exdate(prop, TheTime);
104 * Recursive portion of ical_dezonify()
106 void ical_dezonify_recur(icalcomponent *cal, icalcomponent *rcal) {
111 * Recurse through all subcomponents *except* VTIMEZONE ones.
113 for (c=icalcomponent_get_first_component(
114 rcal, ICAL_ANY_COMPONENT);
116 c = icalcomponent_get_next_component(
117 rcal, ICAL_ANY_COMPONENT)
119 if (icalcomponent_isa(c) != ICAL_VTIMEZONE_COMPONENT) {
120 ical_dezonify_recur(cal, c);
125 * Now look for DTSTART and DTEND properties
127 for (p=icalcomponent_get_first_property(
128 rcal, ICAL_ANY_PROPERTY);
130 p = icalcomponent_get_next_property(
131 rcal, ICAL_ANY_PROPERTY)
134 (icalproperty_isa(p) == ICAL_DTSTART_PROPERTY)
135 || (icalproperty_isa(p) == ICAL_DTEND_PROPERTY)
136 || (icalproperty_isa(p) == ICAL_DUE_PROPERTY)
137 || (icalproperty_isa(p) == ICAL_EXDATE_PROPERTY)
139 ical_dezonify_backend(cal, rcal, p);
146 * Convert all DTSTART and DTEND properties in all subcomponents to UTC.
147 * This function will search any VTIMEZONE subcomponents to learn the
148 * relevant timezone information.
150 void ical_dezonify(icalcomponent *cal) {
151 icalcomponent *vt = NULL;
153 /* Convert all times to UTC */
154 ical_dezonify_recur(cal, cal);
156 /* Strip out VTIMEZONE subcomponents -- we don't need them anymore */
157 while (vt = icalcomponent_get_first_component(
158 cal, ICAL_VTIMEZONE_COMPONENT), vt != NULL) {
159 icalcomponent_remove_component(cal, vt);
160 icalcomponent_free(vt);
166 #endif /* HAVE_ICAL_H */