Hi All.

DateTime::Set was changed fairly recently in such a way as to necessitate special handling of infinite datetimes in recurrences. This isn't such a bad thing, but it does introduce complexity into even the simplest of recurrences.

From the DateTime::Set docs:

  # a 'monthly' recurrence:
  $set = DateTime::Set->from_recurrence(
      recurrence => sub {
          return $_[0] if $_[0]->is_infinite;
          return $_[0]->truncate( to => 'month' )->add( months => 1 )
      },
      span => $date_span1,    # optional span
  );

The operative line here is "return $_[0] if $_[0]->is_infinite". This line, or something similar, now needs to be added to recurrence specifications in order to avoid an infinite loop.

My question is why can't this be done automatically? So the following (consider this to be pseudo-code):

  recurrence => sub {
      return $_[0]->truncate( to => 'month' )->add( months => 1 )
  },

would internally be converted to this:

  recurrence => sub {
     return $_[0] if $_[0]->is_infinite;
     &$recurrence(@_);
  },

In case that's not clear -- take the intitial sub-ref and wrap the call in another sub-ref that automatically deals with infinite values.

This would not break backwards compatability and would simplify the lives of developers seeking "simple" recurrences.

If a developer really had a need for handling infinite values, then this wrapping could be explicitely disabled with a parameter in the constructor.

Is this kind of nerfing of the API outweighed by the penalty of to subroutine calls per iteration?

Thanks,
Matt



Reply via email to