option to include resolved tickets in search, RT#11658
[freeside.git] / rt / lib / RT / Date.pm
index fc4c43c..cc66e0f 100644 (file)
@@ -1,40 +1,40 @@
 # BEGIN BPS TAGGED BLOCK {{{
-# 
+#
 # COPYRIGHT:
-# 
-# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
-#                                          <jesse@bestpractical.com>
-# 
+#
+# This software is Copyright (c) 1996-2011 Best Practical Solutions, LLC
+#                                          <sales@bestpractical.com>
+#
 # (Except where explicitly superseded by other copyright notices)
-# 
-# 
+#
+#
 # LICENSE:
-# 
+#
 # This work is made available to you under the terms of Version 2 of
 # the GNU General Public License. A copy of that license should have
 # been provided with this software, but in any event can be snarfed
 # from www.gnu.org.
-# 
+#
 # This work is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301 or visit their web page on the internet at
 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-# 
-# 
+#
+#
 # CONTRIBUTION SUBMISSION POLICY:
-# 
+#
 # (The following paragraph is not intended to limit the rights granted
 # to you to modify and distribute this software under the terms of
 # the GNU General Public License and is only of importance to you if
 # you choose to contribute your changes and enhancements to the
 # community by submitting them to Best Practical Solutions, LLC.)
-# 
+#
 # By intentionally submitting any modifications, corrections or
 # derivatives to this work, or any other work intended for use with
 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
@@ -43,7 +43,7 @@
 # royalty-free, perpetual, license to use, copy, create derivative
 # works based on those contributions, and sublicense and distribute
 # those contributions and any derivatives thereof.
-# 
+#
 # END BPS TAGGED BLOCK }}}
 
 =head1 NAME
@@ -273,6 +273,39 @@ sub SetToMidnight {
     return $self->Unix( $new );
 }
 
+=head2 SetToStart PERIOD[, Timezone => 'utc' ]
+
+Set to the beginning of the current PERIOD, which can be 
+"year", "month", "day", "hour", or "minute".
+
+=cut
+
+sub SetToStart {
+    my $self = shift;
+    my $p = uc(shift);
+    my %args = @_;
+    my $tz = $args{'Timezone'} || '';
+    my @localtime = $self->Localtime($tz);
+
+    # This is the cleanest way to implement it, I swear.
+    {
+        $localtime[0]=0;
+        last if ($p eq 'MINUTE');
+        $localtime[1]=0;
+        last if ($p eq 'HOUR');
+        $localtime[2]=0;
+        last if ($p eq 'DAY');
+        $localtime[3]=1;
+        last if ($p eq 'MONTH');
+        $localtime[4]=0;
+        last if ($p eq 'YEAR');
+        $RT::Logger->warning("Couldn't find start date of '$p'.");
+        return;
+    }
+    my $new = $self->Timelocal($tz, @localtime);
+    return $self->Unix($new);
+}
+
 =head2 Diff
 
 Takes either an C<RT::Date> object or the date in unixtime format as a string,
@@ -479,6 +512,25 @@ Adds 24 hours to the current time. Returns new unix time.
 
 sub AddDay { return $_[0]->AddSeconds($DAY) }
 
+=head2 AddMonth
+
+Adds one month to the current time. Returns new 
+unix time.
+
+=cut
+
+sub AddMonth {
+    require Time::ParseDate;
+    my $self = shift;
+    my $date = ( 
+        Time::ParseDate::parsedate(
+            '1 month',
+            NOW => $self->Unix
+        )
+    );
+    return $self->Unix($date);
+}
+
 =head2 Unix [unixtime]
 
 Optionally takes a date in unix seconds since the epoch format.
@@ -858,7 +910,7 @@ sub RFC2616 {
                  Seconds => 1, DayOfWeek => 1,
                );
 
-    my $res = $self->RFC2822( @_ );
+    my $res = $self->RFC2822( %args );
     $res =~ s/\s*[+-]\d\d\d\d$/ GMT/ if $args{'Time'};
     return $res;
 }