Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 35936
Status: rejected
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: DEEPFRYED [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.42
Fixed in: (no value)



Subject: adding duration gives inconsistent values
$dt = DateTime->new(year => 2008, month => 5, day => 1); One would expect the following to give the last day of May, $dt->add(months => 1, days => -1) but DateTime returns 2008-05-30T00:00:00 instead.
Subject: datetime.t
#!/usr/bin/perl use strict; use Test::More tests => 2; use DateTime (); my $a = DateTime->new(year => 2008, month => 5, day => 1); my $b = $a->clone->add(months => 1, hours => -24); is($b->delta_days($a)->delta_days, 30, 'hours => -24 works on month boundary'); $b = $a->clone->add(months => 1, days => -1); is($b->delta_days($a)->delta_days, 30, 'days => -1 works on month boundary');
Subject: Re: [rt.cpan.org #35936] adding duration gives inconsistent values
Date: Fri, 16 May 2008 08:35:50 -0500 (CDT)
To: Bharanee Rathnasabapathy via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Fri, 16 May 2008, Bharanee Rathnasabapathy via RT wrote: Show quoted text
> $dt = DateTime->new(year => 2008, month => 5, day => 1); > > One would expect the following to give the last day of May, > $dt->add(months => 1, days => -1) > > but DateTime returns 2008-05-30T00:00:00 instead.
The problem is that DateTime adds days before months. You could get the result you want by doing this: $dt->add( months => 1 )->add( days => -1 ) This is all well-documented in the section "How DateTime Math is Done" in the docs. -dave /*========================== VegGuide.Org Your guide to all that's veg ==========================*/