|
Lines 4158-4172
sub CalcDateDue {
Link Here
|
| 4158 |
; # get open hours of next day |
4158 |
; # get open hours of next day |
| 4159 |
|
4159 |
|
| 4160 |
# Defend against missing library hours definitions |
4160 |
# Defend against missing library hours definitions |
| 4161 |
if ( !$todayhours || !$tomorrowhours ) { $considerlibraryhours = 'ignore' } |
4161 |
# For 'close' mode, we only need today's hours |
|
|
4162 |
# For 'open' mode, we need both today's and tomorrow's hours |
| 4163 |
if ( !$todayhours ) { |
| 4164 |
$considerlibraryhours = 'ignore'; |
| 4165 |
} elsif ( $considerlibraryhours eq 'open' && !$tomorrowhours ) { |
| 4166 |
$considerlibraryhours = 'ignore'; |
| 4167 |
} |
| 4162 |
|
4168 |
|
| 4163 |
my @open = undef; |
4169 |
my @open = undef; |
| 4164 |
if ( $considerlibraryhours ne 'ignore' and $todayhours->close_time and $tomorrowhours->open_time ) { |
4170 |
if ( $considerlibraryhours ne 'ignore' and $todayhours and $todayhours->close_time ) { |
| 4165 |
@close = split( ":", $todayhours->close_time ); |
4171 |
@close = split( ":", $todayhours->close_time ); |
| 4166 |
$library_close = $library_close->set( hour => $close[0], minute => $close[1] ); |
4172 |
$library_close = $library_close->set( hour => $close[0], minute => $close[1] ); |
| 4167 |
$potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ) |
4173 |
$potential_datedue = $potential_datedue->add( hours => $loanlength->{$length_key} ) |
| 4168 |
; # datedue without consideration for open hours |
4174 |
; # datedue without consideration for open hours |
| 4169 |
@open = split( ":", $tomorrowhours->open_time ); |
4175 |
if ( $considerlibraryhours eq 'open' and $tomorrowhours and $tomorrowhours->open_time ) { |
|
|
4176 |
@open = split( ":", $tomorrowhours->open_time ); |
| 4177 |
} |
| 4170 |
} |
4178 |
} |
| 4171 |
|
4179 |
|
| 4172 |
# calculate the datedue as normal |
4180 |
# calculate the datedue as normal |
|
Lines 4174-4195
sub CalcDateDue {
Link Here
|
| 4174 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
4182 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
| 4175 |
if ( $considerlibraryhours ne 'ignore' |
4183 |
if ( $considerlibraryhours ne 'ignore' |
| 4176 |
and $potential_datedue > $library_close |
4184 |
and $potential_datedue > $library_close |
| 4177 |
and $todayhours->close_time |
4185 |
and $todayhours->close_time ) |
| 4178 |
and $tomorrowhours->open_time ) |
|
|
| 4179 |
{ |
4186 |
{ |
| 4180 |
if ( $considerlibraryhours eq 'close' ) { |
4187 |
if ( $considerlibraryhours eq 'close' ) { |
| 4181 |
|
4188 |
|
| 4182 |
# datedue will be after the library closes on that day |
4189 |
# datedue will be after the library closes on that day |
| 4183 |
# shorten loan period to end when library closes |
4190 |
# shorten loan period to end when library closes |
| 4184 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
4191 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
| 4185 |
} elsif ( $considerlibraryhours eq 'open' ) { |
4192 |
} elsif ( $considerlibraryhours eq 'open' and $tomorrowhours and $tomorrowhours->open_time ) { |
| 4186 |
|
4193 |
|
| 4187 |
# datedue will be after the library closes on that day |
4194 |
# datedue will be after the library closes on that day |
| 4188 |
# extend loan period to when library opens following day |
4195 |
# extend loan period to when library opens following day |
| 4189 |
$datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); |
4196 |
$datedue->add( days => 1 )->set( hour => $open[0], minute => $open[1] ); |
| 4190 |
} else { |
4197 |
} else { |
| 4191 |
|
4198 |
|
| 4192 |
# ignore library open hours |
4199 |
# ignore library open hours or can't extend to tomorrow (no tomorrow hours) |
| 4193 |
$datedue->add( hours => $loanlength->{$length_key} ); |
4200 |
$datedue->add( hours => $loanlength->{$length_key} ); |
| 4194 |
} |
4201 |
} |
| 4195 |
} else { |
4202 |
} else { |
|
Lines 4207-4221
sub CalcDateDue {
Link Here
|
| 4207 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
4214 |
if ( $loanlength->{lengthunit} eq 'hours' ) { |
| 4208 |
if ( $considerlibraryhours ne 'ignore' |
4215 |
if ( $considerlibraryhours ne 'ignore' |
| 4209 |
and $potential_datedue > $library_close |
4216 |
and $potential_datedue > $library_close |
| 4210 |
and $todayhours->close_time |
4217 |
and $todayhours->close_time ) |
| 4211 |
and $tomorrowhours->open_time ) |
|
|
| 4212 |
{ |
4218 |
{ |
| 4213 |
if ( $considerlibraryhours eq 'close' ) { |
4219 |
if ( $considerlibraryhours eq 'close' ) { |
| 4214 |
|
4220 |
|
| 4215 |
# datedue will be after the library closes on that day |
4221 |
# datedue will be after the library closes on that day |
| 4216 |
# shorten loan period to end when library closes by hardcoding due time |
4222 |
# shorten loan period to end when library closes by hardcoding due time |
| 4217 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
4223 |
$datedue->set( hour => $close[0], minute => $close[1] ); |
| 4218 |
} elsif ( $considerlibraryhours eq 'open' ) { |
4224 |
} elsif ( $considerlibraryhours eq 'open' and $tomorrowhours and $tomorrowhours->open_time ) { |
| 4219 |
|
4225 |
|
| 4220 |
# datedue will be after the library closes on that day |
4226 |
# datedue will be after the library closes on that day |
| 4221 |
# extend loan period to when library opens following day by hardcoding due time for next open day |
4227 |
# extend loan period to when library opens following day by hardcoding due time for next open day |
|
Lines 4223-4229
sub CalcDateDue {
Link Here
|
| 4223 |
$datedue->set( hour => $open[0], minute => $open[1] ); |
4229 |
$datedue->set( hour => $open[0], minute => $open[1] ); |
| 4224 |
} else { |
4230 |
} else { |
| 4225 |
|
4231 |
|
| 4226 |
# ignore library open hours |
4232 |
# ignore library open hours or can't extend to tomorrow (no tomorrow hours) |
| 4227 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
4233 |
$dur = DateTime::Duration->new( hours => $loanlength->{$length_key} ); |
| 4228 |
} |
4234 |
} |
| 4229 |
} else { |
4235 |
} else { |