2007/8/7, J. David Blackstone <[EMAIL PROTECTED]>:
>   Given two DateTime objects as input, and an integer $N, I want to
> partition the time in between them into $N equal intervals and return
> an array of $N + 1 evenly-spaced DateTimes that begins with the first
> input DateTime and ends with the last input DateTime.

you can hide the complexity with a Set:


  use DateTime::Event::ICal;

  my $start = DateTime->now;
  my $end = DateTime->new( year => 2008, month => 7, day => 12 );
  my $n = 3;

  my $split = DateTime::Event::ICal->recur(
    dtstart => $start,
    freq => secondly,
    interval => int( ($end->hires_epoch() - $start->hires_epoch()) / $n ),
    until => $end,
  );
  print join("\n",  @{[ $split->as_list ]} ), "\n";


  # you can hide the rounding error by replacing the last value with
$end itself.

  print "rounded:\n";
  @values =  @{[ $split->as_list ]};
  $values[-1] = $end;
  print join("\n",  @values ), "\n";

- Flavio S. Glock

Reply via email to