Bugzilla – Attachment 95065 Details for
Bug 23974
hours_between and days_between lack tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23974: both methods should have the same logic/construction
Bug-23974-both-methods-should-have-the-same-logicc.patch (text/plain), 2.04 KB, created by
Jonathan Druart
on 2019-11-05 16:45:09 UTC
(
hide
)
Description:
Bug 23974: both methods should have the same logic/construction
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2019-11-05 16:45:09 UTC
Size:
2.04 KB
patch
obsolete
>From 13fbb24f20203387e70ace1468610229976d4c10 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 5 Nov 2019 17:44:36 +0100 >Subject: [PATCH] Bug 23974: both methods should have the same > logic/construction > >--- > Koha/Calendar.pm | 19 +++++++++---------- > 1 file changed, 9 insertions(+), 10 deletions(-) > >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >index e56c39ddd5..bc8ec82d8e 100644 >--- a/Koha/Calendar.pm >+++ b/Koha/Calendar.pm >@@ -347,34 +347,33 @@ sub days_between { > } > > # start and end should not be closed days >- my $days = $start_dt->delta_days($end_dt)->delta_days; >+ my $delta_days = $start_dt->delta_days($end_dt)->delta_days; > while( $start_dt->compare($end_dt) < 1 ) { >- $days-- if $self->is_holiday($start_dt); >+ $delta_days-- if $self->is_holiday($start_dt); > $start_dt->add( days => 1 ); > } >- return DateTime::Duration->new( days => $days ); >+ return DateTime::Duration->new( days => $delta_days ); > } > > sub hours_between { > my ($self, $start_date, $end_date) = @_; > my $start_dt = $start_date->clone()->set_time_zone('floating'); > my $end_dt = $end_date->clone()->set_time_zone('floating'); >+ > my $duration = $end_dt->delta_ms($start_dt); > $start_dt->truncate( to => 'day' ); > $end_dt->truncate( to => 'day' ); >+ > # NB this is a kludge in that it assumes all days are 24 hours > # However for hourly loans the logic should be expanded to > # take into account open/close times then it would be a duration > # of library open hours > my $skipped_days = 0; >- for (my $dt = $start_dt->clone(); >- $dt <= $end_dt; >- $dt->add(days => 1) >- ) { >- if ($self->is_holiday($dt)) { >- ++$skipped_days; >- } >+ while( $start_dt->compare($end_dt) < 1 ) { >+ $skipped_days++ if $self->is_holiday($start_dt); >+ $start_dt->add( days => 1 ); > } >+ > if ($skipped_days) { > $duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); > } >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23974
:
95062
|
95063
|
95064
|
95065
|
95210
|
95211
|
95212
|
95213
|
95214
|
95889
|
95890
|
95891
|
95893
|
95894
|
95895
|
95896
|
96778
|
96779
|
96780
|
96781
|
96782
|
96783
|
96784
|
96785
|
96786
|
97129
|
97130
|
97131
|
97132
|
97133
|
97134
|
97135
|
97136
|
97137