[Rt-commit] rt branch, 4.2/date-isset, updated. rt-4.2.4-10-g78c96a2

Kevin Falcone falcone at bestpractical.com
Mon May 19 12:05:45 EDT 2014


The branch, 4.2/date-isset has been updated
       via  78c96a25c725c951149fc9d7c3ef3f6656df02b1 (commit)
      from  4fdde1654829bb689884f40cbe429fcaf71e2c69 (commit)

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

- Log -----------------------------------------------------------------
commit 78c96a25c725c951149fc9d7c3ef3f6656df02b1
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Mon May 19 10:56:07 2014 -0400

    Correct check for explicit undef argument
    
    The int(shift||0) is backcompat with the old behavior that
    Unix("") Unix(0) or Unix(undef) all ended up setting to 1970-01-01.
    Copy and tweak existing Unix setting tests that worked using Set() to
    have them test Unix() also so backwards incompatibility failures are
    caught in the future.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index 28c1c24..c9f9ca4 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -556,9 +556,9 @@ Returns the number of seconds since the epoch
 
 sub Unix {
     my $self = shift; 
-    my $time = shift;
 
-    if (defined $time) {
+    if (@_) {
+        my $time = int(shift || 0);
         if ($time < 0) {
             RT->Logger->notice("Passed a unix time less than 0, forcing to 0: [$time]");
             $time = 0;
diff --git a/t/api/date.t b/t/api/date.t
index 9fd71e4..dd22943 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -260,6 +260,17 @@ warning_like
         is($date->Unix, 0, "unix is 0 => unset");
         is($date->IsSet,0,"Date has been unset");
     }
+
+    foreach (undef, 0, '', -5){
+        $date->Unix(1);
+        is($date->ISO, '1970-01-01 00:00:01', "correct value");
+        is($date->IsSet,1,"Date has been set to a value");
+
+        $date->Unix($_);
+        is($date->ISO, '1970-01-01 00:00:00', "Set a date to midnight 1/1/1970 GMT due to wrong call");
+        is($date->Unix, 0, "unix is 0 => unset");
+        is($date->IsSet,0,"Date has been unset");
+    }
 }
 
 my $year = (localtime(time))[5] + 1900;

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


More information about the rt-commit mailing list