[Rt-commit] rt branch, 4.2/date-isset, created. rt-4.2.4-7-g5149153

Kevin Falcone falcone at bestpractical.com
Wed May 14 17:10:26 EDT 2014


The branch, 4.2/date-isset has been created
        at  5149153fe8c63cac98b43e24e33f229e1beb9f0c (commit)

- Log -----------------------------------------------------------------
commit 5149153fe8c63cac98b43e24e33f229e1beb9f0c
Author: Kevin Falcone <falcone at bestpractical.com>
Date:   Wed May 14 17:05:28 2014 -0400

    Add a new RT::Date->IsSet method
    
    This lets you never try to remember if it was ISO or Unix that was best,
    and what about timezones?  Just have a simple boolean check.

diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
index d99c26f..8a2dfa0 100644
--- a/lib/RT/Date.pm
+++ b/lib/RT/Date.pm
@@ -1135,6 +1135,20 @@ sub Timezone {
     return $tz;
 }
 
+=head3 IsSet
+
+Returns true if this Date is set in the database, otherwise returns a false value.
+
+This avoids needing to compare to 1970-01-01 in any of your code
+
+=cut
+
+sub IsSet {
+    my $self = shift;
+    return $self->Unix ? 1 : 0;
+
+}
+
 
 RT::Base->_ImportOverlays();
 
diff --git a/t/api/date.t b/t/api/date.t
index 1619d00..ec04b5a 100644
--- a/t/api/date.t
+++ b/t/api/date.t
@@ -83,6 +83,7 @@ my $current_user;
 
 {
     my $date = RT::Date->new(RT->SystemUser);
+    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 {
@@ -207,6 +208,7 @@ my $current_user;
     $current_user->UserObj->__Set( Field => 'Timezone', Value => 'Europe/Moscow');
     my $date = RT::Date->new( $current_user );
     $date->Set( Format => 'ISO', Timezone => 'utc', Value => '2005-01-01 15:10:00' );
+    is($date->IsSet,1,"Date has been set");
     is($date->ISO( Timezone => 'user' ), '2005-01-01 18:10:00', "ISO");
     is($date->W3CDTF( Timezone => 'user' ), '2005-01-01T18:10:00+03:00', "W3C DTF");
     is($date->RFC2822( Timezone => 'user' ), 'Sat, 01 Jan 2005 18:10:00 +0300', "RFC2822");
@@ -251,10 +253,12 @@ warning_like
     foreach (undef, 0, ''){
         $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->Set(Format => 'unix', Value => $_);
         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");
     }
 }
 

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


More information about the rt-commit mailing list