Package: birthday
Version: 1.6.2-3

Hi!

Using the calendar (-c) format, `birthday' will not print any events
that started in the past and have a duration in the furure:

Event= 21/1/2011 ev to 30/1/2011

This will not produce output with eg. -T 25/1/2011. Additionally,
there's no indicator in the generated output that that event lasts
longer than its initial day.

Even worse, *no* other event that's anytime later will be printed.
That's because this event's delta() time wrt. today is some 360 days,
which isn't the `i'th day (counting from the -T date onwards), thus
the event index (j) isn't incremented. That way, any follwoing events
aren't ever seen. (Except you print a calendar spawning more than a
year.)

The attached patch fixes this by not walking down the list of events
and never looking at "old" ones again, but by keeping the whole list
and sweeping over it. It also contains a testcase.

That way, all events will be printed, and they'll be printed on each
day they occur.

Thanks a lot,
Jan-Benedict Glaw

-- 
      Jan-Benedict Glaw      jbg...@lug-owl.de              +49-172-7608481
Signature of: They that give up essential liberty to obtain temporary safety,
the second  : deserve neither liberty nor safety.  (Ben Franklin)
diff -Nurp birthday-1.6.2/bdcal.c birthday-1.6.2jbglaw/bdcal.c
--- birthday-1.6.2/bdcal.c	2005-12-09 19:06:59.000000000 +0100
+++ birthday-1.6.2jbglaw/bdcal.c	2011-01-25 16:34:16.000000000 +0100
@@ -57,7 +57,7 @@ void do_cal(struct event *evl, const str
     btime = *localtime( &now );
   }
 
-  for (i=j=0; i < iCTotal; i++)
+  for (i=0; i < iCTotal; i++)
     {
       if (iCWeeks != 0 && i!=0 && (i%(iCWeeks*7))==0) printf("\x0c");
       strftime(buf, iCWidth+1, "---%A-%B-%d-%Y", &btime);
@@ -78,13 +78,18 @@ void do_cal(struct event *evl, const str
 	}
       else
 	printf("%s\n", buf);
-      
+
       lines=1;
       chars=0;
-      /* assuming the events are ordered by date, this will process all the events for the current day, if any, and
-	 leave j pointing to the first event which is not for today */
-      for (; evl[j].text != NULL && delta(&(evl[j].date), today) <= i; j++)
-	if (delta(&(evl[j].date), today) == i)
+
+      for (j = 0; evl[j].text != NULL; j++)
+	if (delta(&(evl[j].date), today) == i /* Today's events.  */
+            || (evl[j].enddate.year != 0      /* Events that end somewhen... */
+                && evl[j].enddate.month != 0
+                && evl[j].enddate.day != 0
+                && delta(&(evl[j].enddate), today) >= i
+                && (delta(&(evl[j].date), today) >= delta(&(evl[j].enddate), today) /* ...and either started in the past. */
+                    || delta(&(evl[j].date), today) <= i)))                         /* ...or in the timespan of this calendar output. */
 	  {
 	    chars+=strlen(evl[j].text)+4;
 	    if (chars > iCWidth)
diff -Nurp birthday-1.6.2/test/ongoing-events.t birthday-1.6.2jbglaw/test/ongoing-events.t
--- birthday-1.6.2/test/ongoing-events.t	1970-01-01 01:00:00.000000000 +0100
+++ birthday-1.6.2jbglaw/test/ongoing-events.t	2011-01-25 16:48:04.000000000 +0100
@@ -0,0 +1,47 @@
+# This tests the output of events that last longer than a day.
+# Old `birthday' versions only printed those on their first
+# occurence in calendar (-c) mode, and only if they didn't start
+# in the past.
+*args
+-T 25/1/2011 -c  -d 6
+*file
+First event, starting in the past, already finished=	21/1/2011 ev to 23/1/2011
+Second event, starting in the past, ongoing=		21/1/2011 ev to 26/1/2011
+Third event, starting and ending in the future=		28/1/2011 ev to 30/1/2011
+*output
+---Tuesday-January-25-2011------------------------------------------------------
+Second event, starting in the past, ongoing    
+
+
+
+
+---Wednesday-January-26-2011----------------------------------------------------
+Second event, starting in the past, ongoing    
+
+
+
+
+---Thursday-January-27-2011-----------------------------------------------------
+
+
+
+
+
+---Friday-January-28-2011-------------------------------------------------------
+Third event, starting and ending in the future    
+
+
+
+
+------SSaattuurrddaayy--JJaannuuaarryy--2299--22001111----------------------------------------------------------------------------------------------------------
+Third event, starting and ending in the future    
+
+
+
+
+------SSuunnddaayy--JJaannuuaarryy--3300--22001111--------------------------------------------------------------------------------------------------------------
+Third event, starting and ending in the future    
+
+
+
+

Attachment: signature.asc
Description: Digital signature

Reply via email to