[Rt-commit] rt branch, 4.2/date-isset, updated. rt-4.2.4-9-g4fdde16

Kevin Falcone falcone at bestpractical.com
Fri May 16 19:25:49 EDT 2014


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

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

- Log -----------------------------------------------------------------
commit 4fdde1654829bb689884f40cbe429fcaf71e2c69
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Fri May 16 16:39:34 2014 -0400

    Some bulletproofing on bad input to Unix as a setter
    
    Since you can technically say
        $date->Unix(-5);
    and
        $date->IsSet
    would return 1
        but $date->ISO
    would return 1970-01-01 00:00:00
    we should bulletproof for insane inputs.
    
    This lets IsSet just assume that unix time starts at 0 as intended, and
    avoids all the code shenanigans removed in the previous commit which
    checked for $date->Unix <= 0  or $date->Unix < 1

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index ccd23ae..28c1c24 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -556,7 +556,15 @@ Returns the number of seconds since the epoch
 
 sub Unix {
     my $self = shift; 
-    $self->{'time'} = int(shift || 0) if @_;
+    my $time = shift;
+
+    if (defined $time) {
+        if ($time < 0) {
+            RT->Logger->notice("Passed a unix time less than 0, forcing to 0: [$time]");
+            $time = 0;
+        }
+        $self->{'time'} = int $time;
+    }
     return $self->{'time'};
 }
 
diff --git a/t/api/date.t b/t/api/date.t
index 1d746f8..9fd71e4 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -83,7 +83,7 @@ my $current_user;
 
 {
     my $date = RT::Date->new(RT->SystemUser);
-    is($date->IsSet,0,"new date isn't set");
+    is($date->IsSet,0, "new date isn't set");
     is($date->Unix, 0, "new date returns 0 in Unix format");
     is($date->Get, '1970-01-01 00:00:00', "default is ISO format");
     warning_like {
@@ -250,7 +250,7 @@ warning_like
     $date->Unix(1);
     is($date->ISO, '1970-01-01 00:00:01', "correct value");
 
-    foreach (undef, 0, ''){
+    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");

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


More information about the rt-commit mailing list