DateTime-Set

 view release on metacpan or  search on metacpan

TODO  view on Meta::CPAN


- DateTime::SpanSet has no count() method

2004-07-03

- what happens if the recurrence function returns an 'undef' ?
  (the program should die - add tests for this)

- this POD entry is not entirely correct, it should be tested/fixed:

    The callbacks can return C<DateTime::Infinite::Future> and
    C<DateTime::Infinite::Past> objects, in order to define 
    I<bounded recurrences>.
    In this case, both 'next' and 'previous' callbacks must be defined:

- 'truncate' method ?

- add set_time_zone tests to Span & SpanSet 

- add "mutability" tests for DT::Span, DT::SpanSet
  see 02immutable.t

- implement add/subtract in DT::Span, DT::SpanSet
- implement start/end aliases in DT::Set

lib/DateTime/Set.pm  view on Meta::CPAN

      } else {
          return $dt->truncate( to => 'minute' )->add( minutes => 1 );
      }
  }

Note that this recurrence takes leap seconds into account.  Consider
using C<truncate()> in this manner to avoid complicated arithmetic
problems!

It is also possible to create a recurrence by specifying either or both
of 'next' and 'previous' callbacks.

The callbacks can return C<DateTime::Infinite::Future> and
C<DateTime::Infinite::Past> objects, in order to define I<bounded
recurrences>.  In this case, both 'next' and 'previous' callbacks must
be defined:

    # "monthly from $dt until forever"

    my $months = DateTime::Set->from_recurrence(
        next => sub {
            return $dt if $_[0] < $dt;
            $_[0]->truncate( to => 'month' );
            $_[0]->add( months => 1 );
            return $_[0];

lib/Set/Infinite/_recurrence.pm  view on Meta::CPAN

                unless ref($s2) && exists $s2->{method};

        # optimize: recurrence && recurrence
        if ( $s1->{parent}->is_forever && 
            ref($s2) && _is_recurrence( $s2 ) )
        {
            my ( $next1, $previous1 ) = @{ $s1->{param} };
            my ( $next2, $previous2 ) = @{ $s2->{param} };
            return $s1->{parent}->_function( '_recurrence', 
                  sub {
                               # intersection of parent 'next' callbacks
                               my ($n1, $n2);
                               my $iterate = 0;
                               $n2 = $next2->( $_[0] );
                               while(1) { 
                                   $n1 = $next1->( $previous1->( $n2 ) );
                                   return $n1 if $n1 == $n2;
                                   $n2 = $next2->( $previous2->( $n1 ) );
                                   return if $iterate++ == $max_iterate;
                               }
                  },
                  sub {
                               # intersection of parent 'previous' callbacks
                               my ($p1, $p2);
                               my $iterate = 0;
                               $p2 = $previous2->( $_[0] );
                               while(1) { 
                                   $p1 = $previous1->( $next1->( $p2 ) );
                                   return $p1 if $p1 == $p2;
                                   $p2 = $previous2->( $next2->( $p1 ) ); 
                                   return if $iterate++ == $max_iterate;
                               }
                  },



( run in 0.724 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )