From 2994ea7003b8afbecac0e14038a7f7340d59a8bb Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <lfleischer@calcurse.org>
Date: Wed, 13 Jan 2016 18:13:06 +0100
Subject: ical: Handle items without an end date gracefully

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 src/ical.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

(limited to 'src')

diff --git a/src/ical.c b/src/ical.c
index 4626dde..0c52611 100644
--- a/src/ical.c
+++ b/src/ical.c
@@ -166,7 +166,13 @@ static void ical_export_recur_apoints(FILE * stream)
 				  ical_datetime);
 		fputs("BEGIN:VEVENT\n", stream);
 		fprintf(stream, "DTSTART:%s\n", ical_datetime);
-		fprintf(stream, "DURATION:PT0H0M%ldS\n", rapt->dur);
+		if (rapt->dur > 0) {
+			fprintf(stream, "DURATION:P%ldDT%ldH%ldM%ldS\n",
+				rapt->dur / DAYINSEC,
+				(rapt->dur / HOURINSEC) % DAYINHOURS,
+				(rapt->dur / MININSEC) % HOURINMIN,
+				rapt->dur % MININSEC);
+		}
 		fprintf(stream, "RRULE:FREQ=%s;INTERVAL=%d",
 			ical_recur_type[rapt->rpt->type], rapt->rpt->freq);
 
@@ -210,11 +216,13 @@ static void ical_export_apoints(FILE * stream)
 				  ical_datetime);
 		fputs("BEGIN:VEVENT\n", stream);
 		fprintf(stream, "DTSTART:%s\n", ical_datetime);
-		fprintf(stream, "DURATION:P%ldDT%ldH%ldM%ldS\n",
-			apt->dur / DAYINSEC,
-			(apt->dur / HOURINSEC) % DAYINHOURS,
-			(apt->dur / MININSEC) % HOURINMIN,
-			apt->dur % MININSEC);
+		if (apt->dur > 0) {
+			fprintf(stream, "DURATION:P%ldDT%ldH%ldM%ldS\n",
+				apt->dur / DAYINSEC,
+				(apt->dur / HOURINSEC) % DAYINHOURS,
+				(apt->dur / MININSEC) % HOURINMIN,
+				apt->dur % MININSEC);
+		}
 		fprintf(stream, "SUMMARY:%s\n", apt->mesg);
 		if (apt->state & APOINT_NOTIFY)
 			ical_export_valarm(stream);
@@ -900,18 +908,11 @@ ical_read_event(FILE * fdi, FILE * log, int list, unsigned *noevents,
 			}
 
 			if (vevent_type == APPOINTMENT && vevent.dur == 0) {
-				if (vevent.end == 0) {
-					ical_log(log, ICAL_VEVENT, ITEMLINE,
-						 _("could not compute duration "
-						  "(no end time)."));
-					goto cleanup;
+				if (vevent.end != 0) {
+					vevent.dur = vevent.end - vevent.start;
 				}
 
-				vevent.dur = vevent.end - vevent.start;
-				if (vevent.dur == 0) {
-					vevent_type = EVENT;
-					vevent.end = 0L;
-				} else if (vevent.dur < 0) {
+				if (vevent.dur < 0) {
 					ical_log(log, ICAL_VEVENT, ITEMLINE,
 						_("item has a negative duration."));
 					goto cleanup;
-- 
cgit v1.2.3-70-g09d2