Subject: | between method |
Date: | Fri, 30 Apr 2010 10:53:27 -0400 |
To: | <bug-business-hours [...] rt.cpan.org> |
From: | "Peverill, Matthew" <mpeverill [...] pplm.org> |
Good morning,
I'm trying to calculate the number of business seconds
between two linux epoch formatted datetimes with the between method. I'm
using Business-Hours-0.09 off of CPAN. The method seems to be returning
-1 no matter what dates I feed it. Is this expected / has it been
addressed in the development version? I'd love to help get this fixed;
it would really help us get our reporting cleaned up. Here is my code:
#!/usr/bin/perl
use strict;
use DateTime;
use Business::Hours;
my %ISTsched = (
0 => { Name => 'Sunday',
Start => undef,
End => undef },
1 => { Name => 'Monday',
Start => '7:30',
End => '17:00' },
2 => { Name => 'Tuesday',
Start => '7:30',
End => '17:00' },
3 => { Name => 'Wednesday',
Start => '7:30',
End => '17:00' },
4 => { Name => 'Thursday',
Start => '7:30',
End => '17:00' },
5 => { Name => 'Friday',
Start => '7:30',
End => '17:00' },
6 => { Name => 'Saturday',
Start => '7:30',
End => '15:30' },
);
my $bdate = DateTime->new( year => 2010, month => 4, day => 30, hour =>
7, minute => 31, time_zone => 'America/New_York');
my $edate = DateTime->new( year => 2010, month => 4, day => 30, hour =>
10, minute => 30, time_zone => 'America/New_York');
my $bepoch = $bdate->epoch;
my $eepoch = $edate->epoch;
print "Raw
Times:\n"."begin:\t"."$bdate\t"."$bepoch\n"."end:\t"."$edate\t"."$eepoch
\n\n";
my $hours = Business::Hours->new();
$hours->business_hours(%ISTsched);
my $pbepoch = $hours->first_after($bepoch);
my $peepoch = $hours->first_after($eepoch);
my $pbdate = DateTime->from_epoch( epoch => $pbepoch, time_zone =>
'America/New_York' );
my $pedate = DateTime->from_epoch( epoch => $peepoch, time_zone =>
'America/New_York' );
print
"Returns:\n"."begin:\t"."$pbdate\t"."$pbepoch\n"."end:\t"."$pedate\t"."$
peepoch \n\n";
my $interval = $hours->between($pbepoch,$peepoch);
print "Interval:\t$interval\n";
Here are two examples of output, one with a value outside of business
hours being fed in to first_after (which seems to work fine) and one
without.
#1
scripts]# ./bhourtest
Raw Times:
begin: 2010-04-29T18:30:00 1272580200
end: 2010-04-30T10:30:00 1272637800
Returns:
begin: 2010-04-30T07:30:00 1272627000
end: 2010-04-30T10:30:00 1272637800
Interval: -1
#2
scripts]# ./bhourtest
Raw Times:
begin: 2010-04-30T07:31:00 1272627060
end: 2010-04-30T10:30:00 1272637800
Returns:
begin: 2010-04-30T07:31:00 1272627060
end: 2010-04-30T10:30:00 1272637800
Interval: -1
Matt Peverill
Applications Specialist
Planned Parenthood League of Massachusetts
Phone: 617-616-1656
Fax: 617-616-1665
Let's be friends. Find PPLM on Facebook
<blocked::http://www.facebook.com/plannedparenthoodma> and MySpace
<blocked::http://www.myspace.com/plannedparenthoodma> or visit us at
www.pplm.org <http://www.pplm.org> .
Message body is not shown because it is too large.