#!/usr/bin/perl -w
use strict;


=head1 DESCRIPTION

****************************************************************
NOTE: This bug has been fixed by Flavio with DateTime-Set v 0.25
****************************************************************

This bug report is on the DateTime::* ICal-related modules, concerning
this bizarre RRULE:

   FREQ=MONTHLY;INTERVAL=09;BYDAY=TH;BYSETPOS=1;BYMONTHDAY=15;COUNT=2

This means: take every 9th month starting with dtstart, and of those,
take only the first two cases where the 15th of the month falls on a Thursday.
If dtstart is in 2005-09, then the first two cases are:

   2005-09-15
   2006-06-15

**** Update on 2005 Oct 3 ****

With DateTime-Set version 0.23 this test case now works if DTEND and UNTIL
are not specified.
However, it still fails if either DTEND or UNTIL is specified, giving:

   Use of uninitialized value in numeric eq (==) at /home/mdaoh/workspaces/modules/DateTime-Set/lib/Set/Infinite/_recurrence.pm line 119.
   Use of uninitialized value in negation (-) at /home/mdaoh/workspaces/modules/DateTime.pm/lib/DateTime.pm line 1377.
   Can't call method "is_infinite" on an undefined value at /home/mdaoh/workspaces/modules/DateTime-Event-ICal/lib/DateTime/Event/ICal.pm line 392.

=head1 AUTHOR

Mark D. Anderson (mda@discerning.com).
 
=cut

# force perl to take DateTime modules from my cvs
BEGIN {
    if (1) {
# DateTime-LeapSecond/lib
my @LIBS = qw(Date-ICal/lib			    DateTime-Event-Lunar/lib	    DateTime-Format-Epoch/lib	  DateTime-Incomplete/lib
DateTime-Calendar-Chinese/lib	    DateTime-Event-NameDay/lib	    DateTime-Format-Excel/lib	  
DateTime-Calendar-Christian/lib     DateTime-Event-Random/lib	    DateTime-Format-HTTP/lib	  DateTime-Locale/lib
DateTime-Calendar-Discordian/lib    DateTime-Event-Recurrence/lib   DateTime-Format-Human/lib	  DateTime-Set/lib
DateTime-Calendar-Japanese-Era/lib  DateTime-Event-SolarTerm/lib    DateTime-Format-IBeat/lib	  DateTime-TimeZone-Alias/lib
DateTime-Calendar-Japanese/lib	    DateTime-Event-Spreadsheet/lib  DateTime-Format-ICal/lib	  DateTime-TimeZone/lib
DateTime-Calendar-Julian/lib	    DateTime-Event-Sunrise/lib	    DateTime-Format-Japanese/lib  DateTime-Util-Astro/lib
DateTime-Calendar-Mayan/lib	    DateTime-Fiscal-Year/lib	    DateTime-Format-Mail/lib	  DateTime-Util-Calc/lib
DateTime-Calendar-Pataphysical/lib  DateTime-Format-Bork/lib	    DateTime-Format-MySQL/lib	  DateTime.pm/lib
DateTime-Event-Chinese/lib	    DateTime-Format-Builder/lib     DateTime-Format-Pg/lib	  Set-Infinite/lib
DateTime-Event-Cron/lib		    DateTime-Format-DBI/lib	    DateTime-Format-Roman/lib	  Template-Plugin-DateTime/lib
DateTime-Event-FourthofJuly/lib     DateTime-Format-DateManip/lib   DateTime-Format-W3CDTF/lib	  Time-Local/lib
   DateTime-Event-ICal/lib		    DateTime-Format-DateParse/lib   DateTime-HiRes/lib);
@INC = ((map {"/home/mdaoh/workspaces/modules/$_"} @LIBS), @INC);
}
}

use DateTime::Event::ICal;

sub dump_set {
    my ($set) = @_;
    print "got set $set\n";
    # print "set=", Dumper($set);
    my $iter = $set->iterator();
    my $i = 0;
    while (my $dt = $iter->next()) {
	print "occurence $i: ", $dt->ymd(), "\n";
	$i++;
    }
    print "there were $i occurrences\n";
}

sub test_recur {
    my $set = DateTime::Event::ICal->recur
	(
	 freq => 'monthly',  
	 interval => '09',
	 byday => ['th'], 
	 bysetpos => [1], 
	 bymonthday => [15],
	 count => '2',
	 dtstart => DateTime->new(year => '2005', month => 9, day => 13),
	 # dtend => DateTime->new(year => '2007'),
	 # dtend => DateTime->new(year => '2005', month => 9, day => 14),
	 # until => DateTime->new(year => '2007'),
	 );
    dump_set($set);
}

test_recur();
    
