1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
use strict;
use warnings;
use Test::More tests => 17;
BEGIN { use_ok 'Business::Hours' }
{
my $hours = Business::Hours->new();
is(ref($hours), 'Business::Hours');
# how many business hours were there in the first week.
my $hours_span = $hours->for_timespan(Start => '0', End => ( (86400 * 7) - 1));
is(ref($hours_span), 'Set::IntSpan');
# Are there 45 working hours
is(cardinality $hours_span, (45 * 60 * 60));
}
{
my $hours = Business::Hours->new();
is(ref($hours), 'Business::Hours');
# how many business hours were there in the first week.
my $seconds = $hours->between( 0, ( (86400 * 7) - 1 ) );
ok( $seconds, "Got seconds" );
# Are there 45 working hours
is( $seconds, (45 * 60 * 60) );
}
{
my $hours = Business::Hours->new();
my $time;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
my $starttime;
# pick a date that's during business hours
$starttime = 0;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
while ($wday == 0 || $wday == 6) {
$starttime += ( 24 * 60 * 60);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
}
while ( $hour < 9 || $hour >= 18 ) {
$starttime += ( 4 * 60);
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($starttime);
}
$time = $hours->first_after( $starttime );
is($time, ( $starttime ));
# pick a date that's not during business hours
$starttime = 0;
my ($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
while ( $xwday != 0 ) {
$starttime += ( 24 * 60 * 60);
($xsec,$xmin,$xhour,$xmday,$xmon,$xyear,$xwday,$xyday,$xisdst) = localtime($starttime);
}
$time = $hours->first_after( $starttime );
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
is($wday, $xwday+1);
is($hour, 9);
is($min, 0);
is($sec, 0);
}
{
my $hours = Business::Hours->new();
my ($start, $time, $span);
# pick a date that's during business hours
$start = (20 * 60 * 60);
$time = $hours->add_seconds( $start, 30 * 60);
$span = $hours->for_timespan(Start => $start, End => $time);
# the first second is a business second, too
is(cardinality $span, (30 * 60)+1);
# pick a date that's not during business hours
$start = 0;
$time = $hours->add_seconds( $start, 30 * 60);
$span = $hours->for_timespan(Start => $start, End => $time);
# the first second is a business second, too
is(cardinality $span, (30 * 60)+1);
}
{
my %BUSINESS_HOURS = (
0 => {
Name => 'Sunday',
Start => undef,
End => undef,
},
1 => {
Name => 'Monday',
Start => '9:00',
End => '18:00',
Breaks => [
{
Start => '13:00',
End => '14:00',
},
],
},
2 => {
Name => 'Tuesday',
Start => '9:00',
End => '18:00',
Breaks => [
{
Start => '13:00',
End => '14:00',
},
],
},
3 => {
Name => 'Wednesday',
Start => '9:00',
End => '18:00',
Breaks => [
{
Start => '13:00',
End => '14:00',
},
],
},
4 => {
Name => 'Thursday',
Start => '9:00',
End => '18:00',
Breaks => [
{
Start => '13:00',
End => '14:00',
},
],
},
5 => {
Name => 'Friday',
Start => '9:00',
End => '18:00',
Breaks => [
{
Start => '13:00',
End => '14:00',
},
],
},
6 => {
Name => 'Saturday',
Start => undef,
End => undef,
});
my $hours = Business::Hours->new();
$hours->business_hours(%BUSINESS_HOURS);
is(ref($hours), 'Business::Hours');
# how many business hours were there in the first week.
my $hours_span = $hours->for_timespan(Start => '0', End => ( (86400 * 7) - 1));
is(ref($hours_span), 'Set::IntSpan');
# Are there 40 working hours
is(cardinality $hours_span, (40 * 60 * 60));
}
|