import rt 3.4.6
[freeside.git] / rt / lib / RT / Date.pm
index a000b8d..f951df3 100644 (file)
@@ -1,8 +1,8 @@
-# {{{ BEGIN BPS TAGGED BLOCK
+# BEGIN BPS TAGGED BLOCK {{{
 # 
 # COPYRIGHT:
 #  
-# This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
+# This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC 
 #                                          <jesse@bestpractical.com>
 # 
 # (Except where explicitly superseded by other copyright notices)
@@ -42,7 +42,8 @@
 # works based on those contributions, and sublicense and distribute
 # those contributions and any derivatives thereof.
 # 
-# }}} END BPS TAGGED BLOCK
+# END BPS TAGGED BLOCK }}}
+
 =head1 NAME
 
   RT::Date - a simple Object Oriented date.
@@ -225,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);
-    
-    
 }
 
 
@@ -398,6 +404,7 @@ sub AsString {
 # }}}
 
 # {{{ GetWeekday
+
 =head2 GetWeekday DAY
 
 Takes an integer day of week and returns a localized string for that day of week
@@ -420,6 +427,7 @@ sub GetWeekday {
 # }}}
 
 # {{{ GetMonth
+
 =head2 GetMonth DAY
 
 Takes an integer month and returns a localized string for that month 
@@ -572,6 +580,7 @@ sub W3CDTF {
 # }}}
 
 # {{{ sub LocalTimezone 
+
 =head2 LocalTimezone
 
   Returns the current timezone. For now, draws off a system timezone, RT::Timezone. Eventually, this may