summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorДилян Палаузов <git-dpa@aegee.org>2021-11-08 16:30:01 +0200
committerAllen Winter <allen.winter@kdab.com>2021-11-20 11:46:53 -0500
commitf2f2dc214601e01cbb1dde0589d9c2a749c64697 (patch)
tree2f0d9e6ed2a8166e2eaf2d3fb58227ad6886d8b4
parentc3cc9eef001090e4d82a234d4c989c907622b870 (diff)
downloadlibical-git-f2f2dc214601e01cbb1dde0589d9c2a749c64697.tar.gz
icalcomponent.c: handle the case, when DTEND and DURATION are missing
In icalcomponent_get_dtend(): • when both DTEND and DURATION are missing, set DTEND to DTSTART when the value-type of DTSTART is DATE-TIME, otherwise set DTEND = DTSTART + 1 day, when the value-type of DTSTART is DATE • throw an error, if both DTEND and DURATION are present, as it is done in icalcomponent_get_duration() In icalcomponent_get_duration(): • if DTEND and DURATION are missing and the value-type of DTSTART is DATE-TIME return zero duration; otherwise, if the value-type of DTSTART is DATE, return one day duration • do not throw an error, if DTEND and DURATION are missing In icalcomponent_get_span() account for the fact, that icalcomponent_get_dtend() returns the correct DTEND, based on the value-type of DTSTART, when DTEND is missing. Likewise for icalcomponent_foreach_recurrence(). Adjust test/regression-component.c to assume span.start == span.end, when the event has only DTSTART and its value-type is DATE-TIME.
-rw-r--r--src/libical/icalcomponent.c47
-rw-r--r--src/test/regression-component.c2
2 files changed, 25 insertions, 24 deletions
diff --git a/src/libical/icalcomponent.c b/src/libical/icalcomponent.c
index 80d6703d..ffb58237 100644
--- a/src/libical/icalcomponent.c
+++ b/src/libical/icalcomponent.c
@@ -657,24 +657,14 @@ or empty VCALENDAR component"); */
}
span.start = icaltime_as_timet_with_zone(start, icaltimezone_get_utc_timezone());
- /* The end time could be specified as either a DTEND or a DURATION */
+ /* The end time could be specified as either a DTEND, a DURATION, or be missing */
/* icalcomponent_get_dtend takes care of these cases. */
end = icalcomponent_get_dtend(comp);
- if (icaltime_is_null_time(end)) {
- if (!icaltime_is_date(start)) {
- /* If dtstart is a DATE-TIME and there is no DTEND nor DURATION
- it takes no time */
- span.start = 0;
- return span;
- } else {
- end = start;
- }
- }
span.end = icaltime_as_timet_with_zone(end, icaltimezone_get_utc_timezone());
if (icaltime_is_date(start)) {
/* Until the end of the day */
- span.end += 60 * 60 * 24 - 1;
+ span.end -= 1;
}
return span;
@@ -822,16 +812,9 @@ void icalcomponent_foreach_recurrence(icalcomponent *comp,
if (icaltime_is_null_time(dtstart))
return;
- /* The end time could be specified as either a DTEND or a DURATION */
+ /* The end time could be specified as either a DTEND, a DURATION or be missing */
/* icalcomponent_get_dtend takes care of these cases. */
dtend = icalcomponent_get_dtend(comp);
- if (icaltime_is_null_time(dtend) && icaltime_is_date(dtstart)) {
- /* No DTEND or DURATION and DTSTART is DATE - duration is 1 day */
- struct icaldurationtype dur = icaldurationtype_null_duration();
-
- dur.days = 1;
- dtend = icaltime_add(dtstart, dur);
- }
/* Now set up the base span for this item, corresponding to the
base DTSTART and DTEND */
@@ -1356,11 +1339,11 @@ struct icaltimetype icalcomponent_get_dtend(icalcomponent *comp)
icalcomponent *inner = icalcomponent_get_inner(comp);
icalproperty *end_prop = icalcomponent_get_first_property(inner, ICAL_DTEND_PROPERTY);
icalproperty *dur_prop = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY);
- struct icaltimetype ret = icaltime_null_time();
+ struct icaltimetype ret;
- if (end_prop != 0) {
+ if (end_prop != 0 && dur_prop == 0) {
ret = icalproperty_get_datetime_with_component(end_prop, comp);
- } else if (dur_prop != 0) {
+ } else if (end_prop == 0 && dur_prop != 0) {
struct icaltimetype start = icalcomponent_get_dtstart(inner);
struct icaldurationtype duration;
@@ -1373,6 +1356,19 @@ struct icaltimetype icalcomponent_get_dtend(icalcomponent *comp)
}
ret = icaltime_add(start, duration);
+ } else if (end_prop == 0 && dur_prop == 0) {
+ struct icaltimetype start = icalcomponent_get_dtstart(inner);
+ if (icaltime_is_date(start)) {
+ struct icaldurationtype duration = icaldurationtype_null_duration();
+ duration.days = 1;
+ ret = icaltime_add(start, duration);
+ } else {
+ ret = start;
+ }
+ } else {
+ /* Error, both duration and dtend have been specified */
+ icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+ ret = icaltime_null_time();
}
return ret;
@@ -1443,6 +1439,11 @@ struct icaldurationtype icalcomponent_get_duration(icalcomponent *comp)
struct icaltimetype end = icalcomponent_get_dtend(inner);
ret = icaltime_subtract(end, start);
+ } else if (end_prop == 0 && dur_prop == 0) {
+ struct icaltimetype start = icalcomponent_get_dtstart(inner);
+ if (icaltime_is_date(start)) {
+ ret.days = 1;
+ }
} else {
/* Error, both duration and dtend have been specified */
icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
diff --git a/src/test/regression-component.c b/src/test/regression-component.c
index 3e147e9e..311cf1f8 100644
--- a/src/test/regression-component.c
+++ b/src/test/regression-component.c
@@ -448,7 +448,7 @@ void test_icalcomponent_get_span()
if (VERBOSE)
print_span(tnum++, span);
- int_is("null span", (int)span.start, 0);
+ int_is("start == end", (int)span.start, span.end);
icalcomponent_free(c);
/** test 7