+=head2 _get_chargeable_units
+
+ _get_chargeable_units($unit, $start_date_ $end_date, $branchcode);
+
+return integer value of units between C<$start_date> and C<$end_date>, factoring in holidays for C<$branchcode>.
+
+C<$unit> is 'days' or 'hours' (default is 'days').
+
+C<$start_date> and C<$end_date> are the two DateTimes to get the number of units between.
+
+C<$branchcode> is the branch whose calendar to use for finding holidays.
+
+=cut
+
+sub _get_chargeable_units {
+ my ($unit, $dt1, $dt2, $branchcode) = @_;
+ my $charge_units = 0;
+ my $charge_duration;
+ if ($unit eq 'hours') {
+ if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
+ my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ $charge_duration = $calendar->hours_between( $dt1, $dt2 );
+ } else {
+ $charge_duration = $dt2->delta_ms( $dt1 );
+ }
+ if($charge_duration->in_units('hours') == 0 && $charge_duration->in_units('seconds') > 0){
+ return 1;
+ }
+ return $charge_duration->in_units('hours');
+ }
+ else { # days
+ if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') {
+ my $calendar = Koha::Calendar->new( branchcode => $branchcode );
+ $charge_duration = $calendar->days_between( $dt1, $dt2 );
+ } else {
+ $charge_duration = $dt2->delta_days( $dt1 );
+ }
+ return $charge_duration->in_units('days');
+ }
+}
+
+