[rt-users] Hours Worked

Gene LeDuc gleduc at mail.sdsu.edu
Fri Feb 8 11:10:17 EST 2008


I wrote a mod to the Business::Hours package that lets you subtract one 
date from another.  It's on the wiki as part of something else I posted, 
but since I don't remember where I'll post it below.  It works just like 
the add_seconds() method, but it subtracts instead.  You can either append 
it to the end of your program or (I think) put it into your RT config file.

########## start of code
### Need to add this to Business::Hours so I can count backwards from due date
{ package Business::Hours;
   sub sub_seconds {
       ### This method is hacked version of add_seconds(), written by Gene 
LeDuc
       my $self = shift;
       my $start = shift;
       my $seconds = shift;

       # the maximum time after which we stop searching for business hours
       my $MAXTIME = (30 * 24 * 60 * 60); # 30 days
       my $first;
       my $period = (24 * 60 * 60);
       my $begin = $start - $period;
       my $hours = new Set::IntSpan;
       while ($hours->empty or $self->between($hours->first, $start) <= 
$seconds) {
         if ($begin <= $start - $MAXTIME) {
           return -1;
         if ($begin <= $start - $MAXTIME) {
           return -1;
         }
         $hours = $self->for_timespan(Start => $begin, End => $start);
         $begin -= $period;
       }
       my @elements = reverse elements $hours;
       $first = $elements[$seconds];
       return $first;
   }
1; #this line is important and will help the module return a true value
}
############## end of code

Regards,
Gene

At 10:37 PM 2/7/2008, Chaitanya Veludandi wrote:
>Hi,
>
>Is there a way to calculate Hours Worked (using Business Hours) based on 
>the difference betwee Resolved Time and Created Time and then move it to a 
>custom Field?
>
>Regards,
>
>Chaitanya
>_______________________________________________
>http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users
>
>Community help: http://wiki.bestpractical.com
>Commercial support: sales at bestpractical.com
>
>
>Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
>Buy a copy at http://rtbook.bestpractical.com


-- 
Gene LeDuc, GSEC
Security Analyst
San Diego State University 




More information about the rt-users mailing list