[Rt-devel] Using Business::Hours to set the CF Response Time

Anders Ekstrand Anders.Ekstrand at drutt.com
Thu Aug 30 05:58:47 EDT 2007


Hi,

and many thanks for your reply.

I still can't get it to work, unfortunately.

I tried it as simple as possible, and it came down to a stand-alone perl
script as below:

--- cut here ------ cut here ------ cut here ------ cut here ---
use Business::Hours;

my $BusinessHours = Business::Hours->new();

$BusinessHours->business_hours( 
        0 => { Name  => 'Sunday',    Start => '7:00', End   => '16:00'
},
        1 => { Name  => 'Monday',    Start => '9:00', End   => '18:00'
},
        2 => { Name  => 'Tuesday',   Start => '9:00', End   => '18:00'
},
        3 => { Name  => 'Wednesday', Start => '9:00', End   => '18:00'
},
        4 => { Name  => 'Thursday',  Start => '9:00', End   => '18:00'
},
        5 => { Name  => 'Friday',    Start => '9:00', End   => '18:00'
},
        6 => { Name  => 'Saturday',  Start => '8:00', End   => '17:00' }
 );
 
print $BusinessHours->between( time + 3600, time + 7200 );
print "\n";
--- cut here ------ cut here ------ cut here ------ cut here ---

This one also returns -1...


I added a few debug lines into the 'between' sub in 'Hours.pm', to see
what happened:



--- cut here ------ cut here ------ cut here ------ cut here ---
sub between {
    my $self = shift;
    my $start = shift;
    my $end = shift;

    if ($start < $self->{'start'}) {
	  print "DEBUG1: start=".$start.",
self->start=".$self->{'start'}."\n";
        return (-1);
    } 
    if ($end > $self->{'end'}) {
	  print "DEBUG2: end=".$end.", self->end=".$self->{'end'}."\n";
        return(-1);
    }

    my $period = Set::IntSpan->new($start."-".$end);
    my $intersection = intersect $period $self->{'calculated'};

    return cardinality $intersection;


}
--- cut here ------ cut here ------ cut here ------ cut here ---

The output then is:
DEBUG2: end=1188474497, self->end=
-1


I also get the same result if not defining my business hours hash at
all, which should make Business::Hours to use the default value.


It seems like the issue lies deeper :-(

Best Regards - Anders

> -----Original Message-----
> From: Richard Fojta [mailto:rfojta at gmail.com]
> Sent: den 28 augusti 2007 17:53
> To: Anders Ekstrand
> Cc: rt-devel at lists.bestpractical.com
> Subject: Re: [Rt-devel] Using Business::Hours to set the CF Response
> Time
> 
> Hello,
> documentation says
> 
> between START, END
> 
> Returns the number of business seconds between START and END Both
> Start and End should be specified in Seconds since the Epoch
> 
> Returns -1 if Start or End is outside the calculated business hours
> 
> See http://search.cpan.org/dist/Business-Hours/lib/Business/Hours.pm
> and use method business_hours. Documenation is copied beneath.
> 
> Set the business_hours.
> for this Business::Hours object. Takes a hash of the form :
> 
> { 0 => { Name => 'Sunday', Start => 'HH:MM', End => 'HH:MM'},
> 
>     1 => { Name => 'Monday',
>             Start => 'HH:MM',
>                End => 'HH:MM'},
>     ....
> 
>     6 => { Name => 'Saturday',
>             Start => 'HH:MM',
>                End => 'HH:MM'},
>     };
> 
>     Start and end times are of the form HH:MM.  Valid times are
>     from 00:00 to 23:59.  If your hours are from 9am to 6pm, use
>     Start => '9:00', End => '18:00'.  A given day MUST have a start
>     and end time OR may declare both Start and End to be undef, if
>     there are no valid hours on that day.
> 
>     Note that the ending time is really "what is the first minute
we're
> closed.
>     If you specifiy an "End" of 18:00, that means that at 6pm, you are
> closed.
>     The last business second was 17:59:59. \
> 
> Greetings.
> Richard Fojta
> 
> On 8/28/07, Anders Ekstrand <Anders.Ekstrand at drutt.com> wrote:
> > Hi all,
> >
> > I was up to using a scrip to automatically set my custom field
> "Response
> > Time" to a proper value, when sending the first response to a
> customer
> > in a ticket.
> >
> > I found nothing on the RT Wiki that I could use, so I installed
> > Business::Hours and Set::IntSpan and tried the following scrip on my
> RT
> > 3.6.5RC2 installation:
> >
> >
> >
> > use Business::Hours;
> >
> > my $BusinessHours = Business::Hours->new();
> > my $Ticket = $self->TicketObj;
> > my $cfResponseTime = new RT::CustomField( $RT::SystemUser );
> > my $responseTime = $Ticket->FirstCustomFieldValue( 'Response Time'
);
> >
> > if ( !$responseTime ) {
> >
> >   my $createdTime = $Ticket->CreatedObj->Unix;
> >   my $responseTime = $BusinessHours->between( $createdTime, time()
);
> >
> >   $cfResponseTime->LoadByNameAndQueue ( Name=>'Response Time',
> Queue=>0
> > );
> >   $Ticket->AddCustomFieldValue( Field => $cfResponseTime, Value =>
> > $responseTime );
> > }
> >
> > return(1);
> >
> >
> >
> > Unfortunately, the "between" method only returns -1 for me...
> >
> > Anybody that has a hint regarding what I could have missed here?
> >
> >
> > Best Regards - Anders Ekstrand
> > _______________________________________________
> > List info: http://lists.bestpractical.com/cgi-
> bin/mailman/listinfo/rt-devel
> >


More information about the Rt-devel mailing list