[Rt-commit] r5216 - rt/branches/3.4-RELEASE/lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Fri May 12 16:54:44 EDT 2006


Author: ruz
Date: Fri May 12 16:54:41 2006
New Revision: 5216

Modified:
   rt/branches/3.4-RELEASE/lib/RT/Date.pm

Log:
* add Timezone argument in SetToMidnight

Modified: rt/branches/3.4-RELEASE/lib/RT/Date.pm
==============================================================================
--- rt/branches/3.4-RELEASE/lib/RT/Date.pm	(original)
+++ rt/branches/3.4-RELEASE/lib/RT/Date.pm	Fri May 12 16:54:41 2006
@@ -226,23 +226,28 @@
 
 # {{{ sub SetToMidnight 
 
-=head2 SetToMidnight
+=head2 SetToMidnight [Timezone => 'utc']
 
-Sets the date to midnight (at the beginning of the day) GMT
+Sets the date to midnight (at the beginning of the day).
 Returns the unixtime at midnight.
 
+Arguments:
+
+=over 4
+
+=item Timezone - Timezone context C<server> or C<UTC>
+
 =cut
 
 sub SetToMidnight {
     my $self = shift;
-    
-    use Time::Local;
-    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime($self->Unix);
-    $self->Unix(timegm (0,0,0,$mday,$mon,$year,$wday,$yday));
-    
+    my %args = ( Timezone => 'UTC', @_ );
+    if ( lc $args{'Timezone'} eq 'server' ) {
+        $self->Unix( Time::Local::timelocal( 0,0,0,(localtime $self->Unix)[3..7] ) );
+    } else {
+        $self->Unix( Time::Local::timegm( 0,0,0,(gmtime $self->Unix)[3..7] ) );
+    }
     return ($self->Unix);
-    
-    
 }
 
 


More information about the Rt-commit mailing list