Bug 92255 - duration / end date not included when saving in iCalendar format
Summary: duration / end date not included when saving in iCalendar format
Status: RESOLVED FIXED
Alias: None
Product: korganizer
Classification: Applications
Component: general (show other bugs)
Version: 3.3
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Reinhold Kainhofer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-10-28 12:54 UTC by Gintautas Miliauskas
Modified: 2004-11-14 13:16 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gintautas Miliauskas 2004-10-28 12:54:31 UTC
Version:           3.3 (using KDE KDE 3.3.0)
Installed from:    Debian testing/unstable Packages
OS:                Linux

When I open a file in KOrganizer that specifies the duration of an event through the iCalendar field DURATION and then immediately save it, the DURATION field is gone (and DTEND field is *not* added).

The input file:

BEGIN:VCALENDAR
PRODID:-//SchoolTool.org/NONSGML SchoolTool//EN
VERSION:2.0
BEGIN:VEVENT
UID:KOrganizer-1566238205.758
SUMMARY:korg 13-15
DTSTART:20041028T130000
DURATION:PT2H
DTSTAMP:20041028T104043Z
END:VEVENT
END:VCALENDAR

The file saved by KOrganizer:

BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML KOrganizer 3.3//EN
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20041028T104124Z
ORGANIZER:MAILTO:
CREATED:20041028T104112Z
UID:KOrganizer-1566238205.758
SEQUENCE:0
LAST-MODIFIED:20041028T104112Z
SUMMARY:korg 13-15
CLASS:PUBLIC
PRIORITY:3
DTSTART:20041028T100000Z
TRANSP:OPAQUE
END:VEVENT

END:VCALENDAR

As you can see, the DURATION field is gone.

However, if I export to vCalendar rather than iCalendar, a DTEND field is added, which is fine:

BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML KOrganizer 3.3//EN
VERSION:1.0
BEGIN:VEVENT
DTSTART:20041028T100000Z
DTEND:20041028T120000Z
DCREATED:20041028T104652Z
UID:KOrganizer-1566238205.758
SEQUENCE:0
LAST-MODIFIED:20041028T104652Z
X-ORGANIZER:MAILTO:
SUMMARY:korg 13-15
CLASS:PUBLIC
PRIORITY:3
TRANSP:0
END:VEVENT

Furthermore, if I edit the duration in KOrganizer after importing, all is fine as well.  In this example, I opened the original file (with DURATION specified), expanded the event to occupy an extra hour and saved it.  As you can see, DTEND is provided in the result:

BEGIN:VCALENDAR
PRODID:-//K Desktop Environment//NONSGML KOrganizer 3.3//EN
VERSION:2.0
BEGIN:VEVENT
DTSTAMP:20041028T104442Z
ORGANIZER:MAILTO:
CREATED:20041028T104112Z
UID:KOrganizer-1566238205.758
SEQUENCE:1
LAST-MODIFIED:20041028T104434Z
SUMMARY:korg 13-16
CLASS:PUBLIC
PRIORITY:3
DTSTART:20041028T100000Z
DTEND:20041028T130000Z
TRANSP:OPAQUE
END:VEVENT

END:VCALENDAR

Apparently, when DTEND is specified in the file, I can open and save it as many times as I want without any data loss, but DURATION poses a problem.  I've seen somewhere that it is not parsed, but I think that this piece of information is outdated, because the duration of events having this field is shown properly in the GUI, just not saved into iCalendar (but saved into vCalendar).

Corresponding issue in the related project: http://issues.schooltool.org/issue100
Comment 1 Reinhold Kainhofer 2004-11-14 13:16:30 UTC
CVS commit by kainhofe: 

Correctly write out the duration of an event (if the original event had a duration, no DTEND). 
The code to calculcate the duration was also completely messed up (but funnly not wrong): For example, a duration of 2 hours was written out as 
   DURATION:P7200W-55904DT475552800S
And yes, that's actually just a very complicated way to write 2 hours (7200 weeks into the future, then 55904 days back, and then we'll have to go another 475552800 seconds forward, and we are two hours in the future from now)...

BUG: 92255
	 


  M +16 -14    icalformatimpl.cpp   1.125


--- kdepim/libkcal/icalformatimpl.cpp  #1.124:1.125
@@ -710,9 +710,9 @@ void ICalFormatImpl::writeIncidence(ical
 // @TODO: turned off as it always is set to PT0S (and must not occur together with DTEND
 
-//  if (incidence->hasDuration()) {
-//    icaldurationtype duration;
-//    duration = writeICalDuration(incidence->duration());
-//    icalcomponent_add_property(parent,icalproperty_new_duration(duration));
-//  }
+  if (incidence->hasDuration()) {
+    icaldurationtype duration;
+    duration = writeICalDuration( incidence->duration() );
+    icalcomponent_add_property(parent,icalproperty_new_duration(duration));
+  }
 }
 
@@ -2164,14 +2164,16 @@ icaldurationtype ICalFormatImpl::writeIC
   icaldurationtype d;
 
-  d.weeks    = seconds   % gSecondsPerWeek;
-  seconds   -= d.weeks   * gSecondsPerWeek;
-  d.days     = seconds   % gSecondsPerDay;
-  seconds   -= d.days    * gSecondsPerDay;
-  d.hours    = seconds   % gSecondsPerHour;
-  seconds   -= d.hours   * gSecondsPerHour;
-  d.minutes  = seconds   % gSecondsPerMinute;
-  seconds   -= d.minutes * gSecondsPerMinute;
+  d.is_neg  = (seconds<0)?1:0;
+  if (seconds<0) seconds = -seconds;
+
+  d.weeks    = seconds / gSecondsPerWeek;
+  seconds   %= gSecondsPerWeek;
+  d.days     = seconds / gSecondsPerDay;
+  seconds   %= gSecondsPerDay;
+  d.hours    = seconds / gSecondsPerHour;
+  seconds   %= gSecondsPerHour;
+  d.minutes  = seconds / gSecondsPerMinute;
+  seconds   %= gSecondsPerMinute;
   d.seconds  = seconds;
-  d.is_neg = 0;
 
   return d;