|
Lines 1145-1150
sub open_hours_between {
Link Here
|
| 1145 |
return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours')); |
1145 |
return ($working_hours_between->next()->get_column('hours_between') - $not_used_hours->next()->get_column('not_used_hours')); |
| 1146 |
} |
1146 |
} |
| 1147 |
|
1147 |
|
|
|
1148 |
=head2 open_minutes_between |
| 1149 |
|
| 1150 |
$minutes = $calendar->open_minutes_between($start_date, $end_date) |
| 1151 |
|
| 1152 |
Returns the number of minutes between C<$start_date> and C<$end_date>, taking into |
| 1153 |
account the opening hours of the library. |
| 1154 |
|
| 1155 |
=cut |
| 1156 |
|
| 1157 |
sub open_minutes_between { |
| 1158 |
my ($self, $start_date, $end_date) = @_; |
| 1159 |
my $branchcode = $self->{branchcode}; |
| 1160 |
my $schema = Koha::Database->new->schema; |
| 1161 |
my $dtf = $schema->storage->datetime_parser; |
| 1162 |
$start_date = $dtf->format_datetime($start_date); |
| 1163 |
$end_date = $dtf->format_datetime($end_date); |
| 1164 |
|
| 1165 |
my $working_minutes_between = $schema->resultset('DiscreteCalendar')->search( |
| 1166 |
{ |
| 1167 |
branchcode => $branchcode, |
| 1168 |
isopened => 1, |
| 1169 |
}, |
| 1170 |
{ |
| 1171 |
select => \['sum(time_to_sec(timediff(closehour, openhour)) / 60)'], |
| 1172 |
as => [qw /minutes_between/], |
| 1173 |
where => \['date BETWEEN DATE(?) AND DATE(?)', $start_date, $end_date] |
| 1174 |
} |
| 1175 |
); |
| 1176 |
|
| 1177 |
my $loan_day = $schema->resultset('DiscreteCalendar')->search( |
| 1178 |
{ |
| 1179 |
branchcode => $branchcode, |
| 1180 |
}, |
| 1181 |
{ |
| 1182 |
where => \['date = DATE(?)', $start_date], |
| 1183 |
} |
| 1184 |
); |
| 1185 |
|
| 1186 |
my $return_day = $schema->resultset('DiscreteCalendar')->search( |
| 1187 |
{ |
| 1188 |
branchcode => $branchcode, |
| 1189 |
}, |
| 1190 |
{ |
| 1191 |
where => \['date = DATE(?)', $end_date], |
| 1192 |
} |
| 1193 |
); |
| 1194 |
|
| 1195 |
#Capture the time portion of the date |
| 1196 |
$start_date =~ /\s(.*)/; |
| 1197 |
my $loan_date_time = $1; |
| 1198 |
$end_date =~ /\s(.*)/; |
| 1199 |
my $return_date_time = $1; |
| 1200 |
|
| 1201 |
my $not_used_minutes = $schema->resultset('DiscreteCalendar')->search( |
| 1202 |
{ |
| 1203 |
branchcode => $branchcode, |
| 1204 |
isopened => 1, |
| 1205 |
}, |
| 1206 |
{ |
| 1207 |
select => \[ '(time_to_sec(timediff(?, ?)) + time_to_sec(timediff(?, ?)) ) / 60', $return_day->next()->closehour(), $return_date_time, $loan_date_time, $loan_day->next()->openhour()], |
| 1208 |
as => [qw /not_used_minutes/], |
| 1209 |
} |
| 1210 |
); |
| 1211 |
|
| 1212 |
return DateTime::Duration->new( minutes => $working_minutes_between->next()->get_column('minutes_between') - $not_used_minutes->next()->get_column('not_used_minutes')); |
| 1213 |
} |
| 1214 |
|
| 1148 |
=head2 addDate |
1215 |
=head2 addDate |
| 1149 |
|
1216 |
|
| 1150 |
my $dt = $calendar->addDate($date, $dur, $unit) |
1217 |
my $dt = $calendar->addDate($date, $dur, $unit) |
|
Lines 1171-1176
sub addDate {
Link Here
|
| 1171 |
my $return_by_hour = 10; |
1238 |
my $return_by_hour = 10; |
| 1172 |
|
1239 |
|
| 1173 |
$dt = $self->addHours($startdate, $add_duration, $return_by_hour); |
1240 |
$dt = $self->addHours($startdate, $add_duration, $return_by_hour); |
|
|
1241 |
} elsif($unit eq 'minutes') { |
| 1242 |
$dt = $self->addMinutes($startdate, $add_duration); |
| 1174 |
} else { |
1243 |
} else { |
| 1175 |
# days |
1244 |
# days |
| 1176 |
$dt = $self->addDays($startdate, $add_duration); |
1245 |
$dt = $self->addDays($startdate, $add_duration); |
|
Lines 1213-1218
sub addHours {
Link Here
|
| 1213 |
return $base_date; |
1282 |
return $base_date; |
| 1214 |
} |
1283 |
} |
| 1215 |
|
1284 |
|
|
|
1285 |
=head2 addMinutes |
| 1286 |
|
| 1287 |
$end = $calendar->addMinutes($date, $dur) |
| 1288 |
|
| 1289 |
Add C<$dur> minutes to C<$start> date. |
| 1290 |
|
| 1291 |
=cut |
| 1292 |
|
| 1293 |
sub addMinutes { |
| 1294 |
my ( $self, $startdate, $minutes_duration) = @_; |
| 1295 |
my $base_date = $startdate->clone(); |
| 1296 |
|
| 1297 |
$base_date->add_duration($minutes_duration); |
| 1298 |
|
| 1299 |
my $dateInfo = $self->get_date_info($base_date); |
| 1300 |
|
| 1301 |
my $close_datetime = dt_from_string($dateInfo->{date} ." ". $dateInfo->{closehour}, 'iso'); |
| 1302 |
|
| 1303 |
if(DateTime->compare($base_date, $close_datetime) > 0) { |
| 1304 |
return $close_datetime; |
| 1305 |
} |
| 1306 |
|
| 1307 |
return $base_date; |
| 1308 |
} |
| 1309 |
|
| 1216 |
=head2 addDays |
1310 |
=head2 addDays |
| 1217 |
|
1311 |
|
| 1218 |
$date = $calendar->addDays($start, $duration) |
1312 |
$date = $calendar->addDays($start, $duration) |
| 1219 |
- |
|
|