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: 58533
Status: resolved
Priority: 0/
Queue: DateTime

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

Bug Information
Severity: Important
Broken in:
  • 0.34
  • 0.4501
Fixed in: 0.56



Subject: add(months=>1) bug for end of month
I expect 8/31 + 1 month = 9/30 not 10/1. $ perl -MDateTime -e 'print DateTime->new(year=>2010,month=>8,day=>31)- Show quoted text
>add(months=>1), "\n", DateTime->VERSION, "\n";'
2010-10-01T00:00:00 0.34 $ perl -MDateTime -e 'print DateTime->new(year=>2010,month=>8,day=>31)- Show quoted text
>add(months=>1), "\n", DateTime->VERSION, "\n";'
2010-10-01T00:00:00 0.4501 Unfortunately, I do not have access to a DateTime 0.55 version. Mike mrdvt92
Subject: Re: [rt.cpan.org #58533] add(months=>1) bug for end of month
Date: Sun, 20 Jun 2010 10:41:14 -0500 (CDT)
To: "Michael R. Davis via RT" <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Sun, 20 Jun 2010, Michael R. Davis via RT wrote: Show quoted text
> I expect 8/31 + 1 month = 9/30 not 10/1. > > $ perl -MDateTime -e 'print DateTime->new(year=>2010,month=>8,day=>31)-
>> add(months=>1), "\n", DateTime->VERSION, "\n";'
> 2010-10-01T00:00:00 > 0.34 > > $ perl -MDateTime -e 'print DateTime->new(year=>2010,month=>8,day=>31)-
>> add(months=>1), "\n", DateTime->VERSION, "\n";'
> 2010-10-01T00:00:00 > 0.4501 > > Unfortunately, I do not have access to a DateTime 0.55 version.
perldoc DateTime::Duration and look for "end_of_month". Patches to add some docs about this to DateTime.pm itself would be quite welcome. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Show quoted text
> Patches to add some docs about this to DateTime.pm itself ...
DateTime::Duration states: "For positive durations, the "end_of_month" parameter defaults to wrap. For negative durations, the default is "limit". This should match how most people "intuitively" expect datetime math to work." I do not agree with this statement. I think most people would expect "preserve" or "limit" but never "wrap" especially when we add 31 days for September. (8/31 + 1m = 10/1) So, I think most people will want "preserve" or "limit", in it current implementation, I see no use for "wrap". I updated the $dt->add documentation, please accept the attached doc diff. This message including the attached document is here by released into the public domain. - Michael R. Davis mrdvt92
Subject: DateTime-add.diff.txt
--- org/DateTime.pm 2010-03-16 17:35:17.000000000 +0000 +++ mrdvt/DateTime.pm 2010-06-21 04:00:27.000000000 +0000 @@ -2944,6 +2944,12 @@ This method is syntactic sugar around th simply creates a new C<DateTime::Duration> object using the parameters given, and then calls the C<add_duration()> method. +L<DateTime::Duration> supports three different algorithms for adding months. The three end of month algorithms are "wrap" in to the next month (default), "limit" the date if calculations overflow the month, and "preserve" the end of month even if it requires more than 31 days. + + $dt->add(months=>1, end_of_month=>"wrap"); #2010-08-31 + 1 month = 2010-10-01 + $dt->add(months=>1, end_of_month=>"limit"); #2010-01-30 + 1 month = 2010-02-28 + $dt->add(months=>1, end_of_month=>"preserve"); #2010-04-30 + 1 month = 2010-05-31 + =item * $dt->subtract_duration( $duration_object ) When given a C<DateTime::Duration> object, this method simply calls
Subject: Re: [rt.cpan.org #58533] add(months=>1) bug for end of month
Date: Thu, 24 Jun 2010 13:59:45 -0500 (CDT)
To: "Michael R. Davis via RT" <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Mon, 21 Jun 2010, Michael R. Davis via RT wrote: Show quoted text
> DateTime::Duration states: "For positive durations, the "end_of_month" > parameter defaults to wrap. For negative durations, the default > is "limit". This should match how most people "intuitively" expect > datetime math to work." > > I do not agree with this statement. I think most people would > expect "preserve" or "limit" but never "wrap" especially when we add 31 > days for September. (8/31 + 1m = 10/1)
Well, that's the unfortunate fact of "intuitive". I guess it's intuitive for me, or was when I wrote the code. Show quoted text
> I updated the $dt->add documentation, please accept the attached doc > diff.
I'll take a closer look once I'm back from YAPC next week. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/