> > How about a DT::Duration::Set class?
> >
> > add() pushes a duration object into a DT::D::Set object
> >
> > _collapse() would call a 'sum' method on a DT::D::Set object
> >
> > _collapse_to_datetime() would call _collapse (or the 'sum' method
> > directly) on a DT::D::Set object and add the resulting DT::D object to a
> > DT object.
>
> And this is easier than "$dt->add( months => 1 )->add( days => -2 )" how?
Well DT::D could create one DT::D object for each parameter in it's constructor.
So DT::D->new( months => 1, days => -2 ) would create a DT::D::Set.
If DT understands these sets then your 'syntax sugar' should work with mixed signs.
$dt->add( months => 1, days => -2 );
The down side is it will be a bit complicated to add/subtract these sets.
Although I think this is pretty cool solution:
use DateTime;
my $dt = DateTime->now;
my $dur = sub { $_[0]->add( months => 3 )->subtract( hours => 3 ) };
print $dur->($dt)->datetime;
-J
--