[Vpim-talk] Leap day bug

Gregory Seidman gsslist+vpim at anthropohedron.net
Mon Mar 3 10:06:04 EST 2008


On Sun, Mar 02, 2008 at 10:56:44PM -0800, Sam Roberts wrote:
> Quoting gsslist+vpim at anthropohedron.net, on Sun, Mar 02, 2008 at 09:21:21PM -0500:
> > leap = Event.create_yearly(Time.mktime(2004, 2, 29), 'Leap day')
> > 
> > leap.occurences.each(Time.mktime(2009, 3, 4)) { |time|
> >   puts time.to_s
> > }
> > 
> > Not only is it showing up for years that aren't leap years, it gets
> > pushed to March 1 on the first non-leap year and stays there even on
> > leap years.
> 
> Sorry about that. vPim uses ruby's Date class. Add a year to 2004-02-29,
> and you get:
> 
>   irb(main):011:0> Time.mktime(2005, 2, 29)
>   => Tue Mar 01 00:00:00 -0800 2005
> 
> Here's another example from my notes:
> 
> " - bug: deal with "round down" that Date does when you add a month, and the dofmonth is not
> "   in valid range -> if you have jan31 repeating monthly with iCal, you shouldn't get an
> "   occurence in Feb
[...]
> " I need to keep my own date/time, and not use Time as the basic object in my iteration.
> " 
> " Then, I can eliminate non-existent times before yielding them.
> 
> I'll see what this involves, maybe I can correct for some of Date's
> problems without reimplementing it, which I don't have the time for,
> though I might have to do it for timezone support.

I think you should be able to do it with a quick check on mday. If
calculated_time.mday != original_time.mday then skip it and move on.
You'll need to keep a separate iteration variable from the time itself, so
instead of adding a month or a year to a Time you are adding i*(month or
year) to the dtstart.

I haven't dug into the code to see if it's an easy fix. If I'd noticed the
issue earlier in the weekend, I would have had time. Alas...

BTW, this is coming up in the context of my (new this weekend, but already
up and working) CalTerm project (find it on rubyforge).

> > Incidentally, why isn't the tracker active for the vpim project? I would
> > have submitted this as a bug otherwise.
> 
> Would you have preferred to submit with a tracker? I could turn it on, I
> just thought people would rather email me if they had a comment, or
> subscribe to the list. My direct email address is part of the docs.

I like submitting to a tracker in large part because I can check if it's
come up before and, if so, simply comment on the previous bug. If it hasn't
come up before, I can submit it. Either way, any discussion on it (and
patches, if any) stay associated with the issue.

> Cheers,
> Sam
--Greg



More information about the Vpim-talk mailing list