import rt 3.4.6
[freeside.git] / rt / lib / RT / Date.pm
index 620acc7..f951df3 100644 (file)
@@ -226,23 +226,28 @@ sub Set {
 
 # {{{ 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);
-    
-    
 }