Hi All,

A little OT, but also related to RT. I'm getting an unexpected result using Business::Hours to compute a due date in an RT ticket (I lifted the example from the wiki). Since a real week is 5 business days and each business day is 8.5 hours, 1 business week should be exactly 42.5 business hours. Doing the math using real days sets the due date for a ticket created on Friday and due in 5 days to next Wednesday, but using business days (Sat/Sun are not business days), it should be 2 days later, next Friday. I'd appreciate it if anyone familiar with this module would take a quick look at my code and point out what I'm doing wrong.

Here is the code (with some debug logs) from my scrip:
### Set due date so that it accounts for business days
use Business::Hours;
my $duedate = RT::Date->new($RT::SystemUser);
my $daysuntildue = 5;
my $secondsuntildue = $daysuntildue * 8.5 * 60 * 60;

$RT::Logger->debug("$MyName: daysuntildue: $daysuntildue, seconds: $secondsuntildue");
my $hours = Business::Hours->new();
$hours->business_hours(
  { 0 => { Name => 'Sunday', Start => undef, End => undef },
    1 => { Name => 'Monday', Start => '08:00', End => '16:30' },
    2 => { Name => 'Tuesday', Start => '08:00', End => '16:30' },
    3 => { Name => 'Wednesday', Start => '08:00', End => '16:30' },
    4 => { Name => 'Thursday', Start => '08:00', End => '16:30' },
    5 => { Name => 'Friday', Start => '08:00', End => '16:30' },
    6 => { Name => 'Saturday', Start => undef, End => undef }
  } );
my $curtime = time;
my $bus_hours_duetime = $hours->add_seconds ($curtime, $secondsuntildue);
$RT::Logger->debug("$MyName: curtime: $curtime, bus_hours_duetime: $bus_hours_duetime");

The debug log entries for this scrip show that $bus_hours_duetime is -1. The docs at cpan seem to indicate that this means there are no business hours within 30 days of $curtime. If so, I must have messed up setting my business hours, but I can't see where.

[Fri Apr 20 18:32:46 2007] [debug]: Scrip DNS:35:Commit (New Ticket): daysuntildue: 5, seconds: 153000 ((eval 327):30) [Fri Apr 20 18:32:46 2007] [debug]: Scrip DNS:35:Commit (New Ticket): curtime: 1177093966, bus_hours_duetime: -1 ((eval 327):43)

Thanks,
Gene



--
Gene LeDuc, GSEC
Security Analyst
San Diego State University
_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: [EMAIL PROTECTED]


Discover RT's hidden secrets with RT Essentials from O'Reilly Media. Buy a copy at http://rtbook.bestpractical.com

Reply via email to