Dan Sully schreef:
> * Eugene van der Pijll <[EMAIL PROTECTED]> shaped the electrons to say...
>
> > TIMTOWTDI:
> >
> > my $dt2 = DateTime->new( month => $month, year => 2002)
> > ->add( months => 1 )
> > ->truncate( to => 'month' )
> > ->subtract( seconds => 1 );
> >
> > my $dt3 = DateTime->last_day_of_month( month => $month, year => 2002)
> > ->add( days => 1, seconds => -1 );
>
> Which yield
>
> 2002-12-01 00:00:-01
> 2003-01-01 00:00:-01
>
> respectivly. Not quite correct.
I tested them both, and I thought they worked. Looking a bit closer, I
am not so sure:
2002-12-31 23:59:59
2002-12-29 23:59:59
Forget the second one; because one of the units to be added has a minus
sign, DateTime thinks the whole duration should be negative, so
add( days => 1, seconds => -1 )
is equivalent to
add( days => -1, seconds => -1 )
This 'feature' is perhaps hard to fix, because of the way DT::Duration
is implemented (but I'm not sure about that).
This solution, OTOH, should work:
my $dt3 = DateTime->last_day_of_month( month => $month, year => 2002)
->add( days => 1 )
->subtract( seconds => 1 );
And it does. (DT version 0.1402, perl 5.8.0, linux)
Eugene