+=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);
+}
+