diff options
Diffstat (limited to 'rt/lib/RT/Date.pm')
-rw-r--r-- | rt/lib/RT/Date.pm | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/rt/lib/RT/Date.pm b/rt/lib/RT/Date.pm index 2b6a3e3f4..e68526c07 100644 --- a/rt/lib/RT/Date.pm +++ b/rt/lib/RT/Date.pm @@ -273,6 +273,41 @@ 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); + #remove 'offset' so that DST is figured based on the resulting time. + pop @localtime; + + # 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 +514,30 @@ 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 { + my $self = shift; + my %args = @_; + my @localtime = $self->Localtime($args{'Timezone'}); + # remove offset, as with SetToStart + pop @localtime; + + $localtime[4]++; #month + if ( $localtime[4] == 12 ) { + $localtime[4] = 0; + $localtime[5]++; #year + } + + my $new = $self->Timelocal($args{'Timezone'}, @localtime); + return $self->Unix($new); +} + =head2 Unix [unixtime] Optionally takes a date in unix seconds since the epoch format. @@ -1040,6 +1099,9 @@ sub Timezone { } -RT::Base->_ImportOverlays(); +eval "require RT::Date_Vendor"; +die $@ if ($@ && $@ !~ qr{^Can't locate RT/Date_Vendor.pm}); +eval "require RT::Date_Local"; +die $@ if ($@ && $@ !~ qr{^Can't locate RT/Date_Local.pm}); 1; |