[Rt-commit] rt branch, 4.0-trunk, updated. rt-4.0.19-46-g8ad1f86

Jim Brandt jbrandt at bestpractical.com
Wed Mar 5 09:33:10 EST 2014


The branch, 4.0-trunk has been updated
       via  8ad1f8611769ff50f99aa90c02b8c1b3c87980bd (commit)
       via  d3bfd07b1d8812988e68165bdc61ec1fef52a1ab (commit)
      from  06ee3fbb1ced5f35cd4a5c3441e9b9bdcd27b146 (commit)

Summary of changes:
 lib/RT/Date.pm |  3 ++-
 t/api/date.t   | 10 +++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

- Log -----------------------------------------------------------------
commit d3bfd07b1d8812988e68165bdc61ec1fef52a1ab
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Mar 5 09:31:32 2014 -0500

    Failing test when passing 0 to AddDays

diff --git a/t/api/date.t b/t/api/date.t
index cc1c694..22c6f1b 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -4,7 +4,7 @@ use DateTime;
 
 use warnings;
 use strict;
-use RT::Test tests => 173;
+use RT::Test tests => 175;
 use RT::User;
 use Test::Warn;
 
@@ -440,6 +440,14 @@ my $year = (localtime(time))[5] + 1900;
     $date->Unix(0);
     $date->AddDays(31);
     is($date->ISO, '1970-02-01 00:00:00', "added one month");
+
+    $date->Unix(0);
+    $date->AddDays(0);
+    is($date->ISO, '1970-01-01 00:00:00', "added no days");
+
+    $date->Unix(0);
+    $date->AddDays();
+    is($date->ISO, '1970-01-02 00:00:00', "added one day with no argument");
 }
 
 {

commit 8ad1f8611769ff50f99aa90c02b8c1b3c87980bd
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Mar 5 09:31:42 2014 -0500

    Properly add zero days when zero is passed
    
    AddDays is documented to add one day if you pass no value, but
    the previous default handling also added a day if you passed 0.
    While uncommon, you may pass 0 in the context of date calculations
    where zero is a possible value. Correcly handle 0 while
    preserving the no argument default.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index d669964..4fd23b2 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -474,7 +474,8 @@ Returns new unix time.
 
 sub AddDays {
     my $self = shift;
-    my $days = shift || 1;
+    my $days = shift;
+    $days = 1 unless defined $days;
     return $self->AddSeconds( $days * $DAY );
 }
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list