[Rt-commit] r18834 - rt/3.999/branches/datetime/lib/RT

sartak at bestpractical.com sartak at bestpractical.com
Wed Mar 18 12:30:41 EDT 2009


Author: sartak
Date: Wed Mar 18 12:30:40 2009
New Revision: 18834

Modified:
   rt/3.999/branches/datetime/lib/RT/DateTime.pm

Log:
"new_unset" method for abstracting away the epoch=0 being unset logic

Modified: rt/3.999/branches/datetime/lib/RT/DateTime.pm
==============================================================================
--- rt/3.999/branches/datetime/lib/RT/DateTime.pm	(original)
+++ rt/3.999/branches/datetime/lib/RT/DateTime.pm	Wed Mar 18 12:30:40 2009
@@ -10,8 +10,6 @@
 
 sub _stringify { shift->config_format }
 
-sub is_unset { shift->epoch == 0 }
-
 sub age {
     my $self  = shift;
     my $until = shift || RT::DateTime->now;
@@ -28,8 +26,8 @@
         $tz = $self->current_user->user_object->time_zone;
     }
 
-    # if the user time zone is requested and the user has none, use the server's
-    # time zone
+    # if the "user" time zone is requested and the user has none, use the
+    # "server" time zone
     if (!$tz || lc($tz) eq 'server' || lc($tz) eq 'system') {
         $tz = RT->config->get('TimeZone');
     }
@@ -68,8 +66,9 @@
 
     my $dt = $class->SUPER::new_from_string($string, %args);
 
+    # always return a valid RT::DateTime object
     if (!defined($dt)) {
-        return RT::DateTime->from_epoch(epoch => 0);
+        return RT::DateTime->new_unset;
     }
 
     return $dt;
@@ -117,5 +116,9 @@
     return $self->strftime(RT->config->get('DateTimeFormat'));
 }
 
+sub is_unset { shift->epoch == 0 }
+
+sub new_unset { RT::DateTime->from_epoch(epoch => 0) }
+
 1;
 


More information about the Rt-commit mailing list