[icalendar-dev] Bug in vDuration?

Gene Cash gene.cash at gmail.com
Tue May 13 01:59:19 CEST 2008


Ferry Boender wrote:
> Hi All,
> 
> (I wonder if this list is still active, but we'll see).
> 
> Either I don't fully understand how vDuration should work, or there is a 
> bug (or rather a shortcoming) in it. When loading a iCalendar file 
> created by KOrganizer, the alarms are mutilated. Here's an short example 
> of what is happening which I think isn't correct:
> 
>  >>> vDuration(timedelta(days=-1)).ical() # Correct
> '-P1D'
>  >>> vDuration(timedelta(days=1, hours=5)).ical() # Correct
> 'P1DT5H'
>  >>> vDuration(timedelta(hours=-5)).ical() # Incorrect?
> '-P1DT19H'
> 
> I would have expected this to render as '-PT15H', which is the way how 
> KOrganizer marshals negative time offsets for alarms. So now, when I 
> load a iCal file generated by KOrganizer and write it back again, all 
> the alarms are FUBAR. It would appear (from the test-cases mentioned in 
> the docstring of the vDuration ical() method) the original author of the 
> package failed to notice that converting anything other than negative 
> days fails. (or I'm just not getting how this should be used ;-) )
> 
> I've written a patch to correct the problem, in case anybody is 
> interested. With the patch (see attachment, if the lists supports them. 
> Otherwise I'll repost), the marshalling is as follows:

Actually, I discovered this a while ago. I added just one line and I 
think it solved the problem, at least for me. Am I wrong here?

I'm using this package as part of a time organizer for my Nokia N800.
http://home.cfl.rr.com/genecash/nokia/

I posted it but I never got any sort of response. This isn't a full 
patch, just pointing out the line I added.

     def ical(self):
         sign = ""
         if self.td.days < 0:
             sign = "-"
+           self.td = -self.td
         timepart = ""
         if self.td.seconds:
             timepart = "T"
             hours = self.td.seconds // 3600
             minutes = self.td.seconds % 3600 // 60
             seconds = self.td.seconds % 60
             if hours:
                 timepart += "%dH" % hours
             if minutes or (hours and seconds):
                 timepart += "%dM" % minutes
             if seconds:
                 timepart += "%dS" % seconds
         if self.td.days == 0 and timepart:
             return "%sP%s" % (sign, timepart)
         else:
             return "%sP%dD%s" % (sign, abs(self.td.days), timepart)

-gc

-- 
Fig Newton: The force required to accelerate a fig 39.37 inches/sec.


More information about the icalendar-dev mailing list