There's some example code in the FAQ which fails its tests, but presumably once passed. It's for spansets. Here's the code:

  use DateTime::Event::Recurrence;
  use DateTime::SpanSet;

  # Make the set representing the work start times: M-F 9:00 to 12:00
  my $start = DateTime::Event::Recurrence->weekly
               ( days => [1 .. 5], hours => [8, 12] );
  # Make the set representing the work end times: M-F 13:00 to 17:00
  my $end   = DateTime::Event::Recurrence->weekly
               ( days => [1 .. 5], hours => [13, 17] );

  # Build a spanset from the set of starting points and ending points
  my $spanset = DateTime::SpanSet->from_sets
                  ( start_set => $start,
                    end_set   => $end );

  # Iterate from Thursday the 3rd to Monday the 6th
  my $it = $spanset->iterator
             (start  =>
              DateTime->new(year => 2003, month => 1, day => 3),
              before =>
              DateTime->new(year => 2003, month => 1, day => 7));

  while (my $span = $it->next) {
      my ($st, $end) = ($span->start(), $span->end());
      print $st->day_abbr, " ", $st->hour, " to ", $end->hour, "\n";
  }
  # Prints: "Fri 8 to 12\nFri 13 to 17\nMon 8 to 12\nMon 13 to 17\n"

  # Now see if a given DateTime falls within working hours
  my $dt = DateTime->new(year => 2003, month => 2, day => 11, hour => 11);
  print $dt->datetime, " is a work time\n"
      if $spanset->contains( $dt );

What's happening is that the hours are getting overlapped inside the spanset, so it prints

  Fri 8 to 13
  Fri 12 to 17
  Mon 8 to 13
  Mon 12 to 17

I can't tell if this is a real bug or just reflects an API change and we should change the code.

Flavio, any thoughts?


-dave

/*===========================
VegGuide.Org
Your guide to all that's veg.
===========================*/

Reply via email to