Lines 1176-1181
sub open_hours_between {
Link Here
|
1176 |
return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours')); |
1176 |
return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours')); |
1177 |
} |
1177 |
} |
1178 |
|
1178 |
|
|
|
1179 |
=head2 open_minutes_between |
1180 |
|
1181 |
$minutes = $calendar->open_minutes_between($start_date, $end_date) |
1182 |
|
1183 |
Returns the number of minutes between C<$start_date> and C<$end_date>, taking into |
1184 |
account the opening hours of the library. |
1185 |
|
1186 |
=cut |
1187 |
|
1188 |
sub open_minutes_between { |
1189 |
my ($self, $start_date, $end_date) = @_; |
1190 |
my $branchcode = $self->{branchcode}; |
1191 |
my $schema = Koha::Database->new->schema; |
1192 |
my $dtf = $schema->storage->datetime_parser; |
1193 |
$start_date = $dtf->format_datetime($start_date); |
1194 |
$end_date = $dtf->format_datetime($end_date); |
1195 |
|
1196 |
my $working_minutes_between = $schema->resultset('DiscreteCalendar')->search( |
1197 |
{ |
1198 |
branchcode => $branchcode, |
1199 |
isopened => 1, |
1200 |
}, |
1201 |
{ |
1202 |
select => \['sum(time_to_sec(timediff(closehour, openhour)) / 60)'], |
1203 |
as => [qw /minutes_between/], |
1204 |
where => \['date BETWEEN DATE(?) AND DATE(?)', $start_date, $end_date] |
1205 |
} |
1206 |
); |
1207 |
|
1208 |
my $loan_day = $schema->resultset('DiscreteCalendar')->search( |
1209 |
{ |
1210 |
branchcode => $branchcode, |
1211 |
}, |
1212 |
{ |
1213 |
where => \['date = DATE(?)', $start_date], |
1214 |
} |
1215 |
); |
1216 |
|
1217 |
my $return_day = $schema->resultset('DiscreteCalendar')->search( |
1218 |
{ |
1219 |
branchcode => $branchcode, |
1220 |
}, |
1221 |
{ |
1222 |
where => \['date = DATE(?)', $end_date], |
1223 |
} |
1224 |
); |
1225 |
|
1226 |
#Capture the time portion of the date |
1227 |
$start_date =~ /\s(.*)/; |
1228 |
my $loan_date_time = $1; |
1229 |
$end_date =~ /\s(.*)/; |
1230 |
my $return_date_time = $1; |
1231 |
|
1232 |
my $not_used_minutes = $schema->resultset('DiscreteCalendar')->search( |
1233 |
{ |
1234 |
branchcode => $branchcode, |
1235 |
isopened => 1, |
1236 |
}, |
1237 |
{ |
1238 |
select => \[ '(time_to_sec(timediff(?, ?)) + time_to_sec(timediff(?, ?)) ) / 60', $return_day->next()->closehour(), $return_date_time, $loan_date_time, $loan_day->next()->openhour()], |
1239 |
as => [qw /not_used_minutes/], |
1240 |
} |
1241 |
); |
1242 |
|
1243 |
return DateTime::Duration->new( minutes => $working_minutes_between->next()->get_column('minutes_between') - $not_used_minutes->next()->get_column('not_used_minutes')); |
1244 |
} |
1245 |
|
1179 |
=head2 addDate |
1246 |
=head2 addDate |
1180 |
|
1247 |
|
1181 |
my $dt = $calendar->addDate($date, $dur, $unit) |
1248 |
my $dt = $calendar->addDate($date, $dur, $unit) |
Lines 1202-1207
sub addDate {
Link Here
|
1202 |
my $return_by_hour = 10; |
1269 |
my $return_by_hour = 10; |
1203 |
|
1270 |
|
1204 |
$dt = $self->addHours($startdate, $add_duration, $return_by_hour); |
1271 |
$dt = $self->addHours($startdate, $add_duration, $return_by_hour); |
|
|
1272 |
} elsif($unit eq 'minutes') { |
1273 |
$dt = $self->addMinutes($startdate, $add_duration); |
1205 |
} else { |
1274 |
} else { |
1206 |
# days |
1275 |
# days |
1207 |
$dt = $self->addDays($startdate, $add_duration); |
1276 |
$dt = $self->addDays($startdate, $add_duration); |
Lines 1244-1249
sub addHours {
Link Here
|
1244 |
return $base_date; |
1313 |
return $base_date; |
1245 |
} |
1314 |
} |
1246 |
|
1315 |
|
|
|
1316 |
=head2 addMinutes |
1317 |
|
1318 |
$end = $calendar->addMinutes($date, $dur) |
1319 |
|
1320 |
Add C<$dur> minutes to C<$start> date. |
1321 |
|
1322 |
=cut |
1323 |
|
1324 |
sub addMinutes { |
1325 |
my ( $self, $startdate, $minutes_duration) = @_; |
1326 |
my $base_date = $startdate->clone(); |
1327 |
|
1328 |
$base_date->add_duration($minutes_duration); |
1329 |
|
1330 |
my $dateInfo = $self->get_date_info($base_date); |
1331 |
|
1332 |
my $close_datetime = dt_from_string($dateInfo->{date} ." ". $dateInfo->{closehour}, 'iso'); |
1333 |
|
1334 |
if(DateTime->compare($base_date, $close_datetime) > 0) { |
1335 |
return $close_datetime; |
1336 |
} |
1337 |
|
1338 |
return $base_date; |
1339 |
} |
1340 |
|
1247 |
=head2 addDays |
1341 |
=head2 addDays |
1248 |
|
1342 |
|
1249 |
$date = $calendar->addDays($start, $duration) |
1343 |
$date = $calendar->addDays($start, $duration) |
1250 |
- |
|
|