projects
/
koha.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Bug 8015: Add unit tests for SimpleMARC and MarcModificationTemplates routines
[koha.git]
/
Koha
/
Calendar.pm
diff --git
a/Koha/Calendar.pm
b/Koha/Calendar.pm
index
90069b6
..
6a12530
100644
(file)
--- a/
Koha/Calendar.pm
+++ b/
Koha/Calendar.pm
@@
-33,28
+33,31
@@
sub _init {
my $self = shift;
my $branch = $self->{branchcode};
my $dbh = C4::Context->dbh();
my $self = shift;
my $branch = $self->{branchcode};
my $dbh = C4::Context->dbh();
- my $
repeat
_sth = $dbh->prepare(
-'SELECT
* from repeatable_holidays WHERE branchcode = ? AND ISNULL(weekday) = ?
'
+ my $
weekly_closed_days
_sth = $dbh->prepare(
+'SELECT
weekday FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NOT NULL
'
);
);
- $
repeat_sth->execute( $branch, 0
);
+ $
weekly_closed_days_sth->execute( $branch
);
$self->{weekly_closed_days} = [ 0, 0, 0, 0, 0, 0, 0 ];
Readonly::Scalar my $sunday => 7;
$self->{weekly_closed_days} = [ 0, 0, 0, 0, 0, 0, 0 ];
Readonly::Scalar my $sunday => 7;
- while ( my $tuple = $
repeat
_sth->fetchrow_hashref ) {
+ while ( my $tuple = $
weekly_closed_days
_sth->fetchrow_hashref ) {
$self->{weekly_closed_days}->[ $tuple->{weekday} ] = 1;
}
$self->{weekly_closed_days}->[ $tuple->{weekday} ] = 1;
}
- $repeat_sth->execute( $branch, 1 );
+ my $day_month_closed_days_sth = $dbh->prepare(
+'SELECT day, month FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NULL'
+ );
+ $day_month_closed_days_sth->execute( $branch );
$self->{day_month_closed_days} = {};
$self->{day_month_closed_days} = {};
- while ( my $tuple = $
repeat
_sth->fetchrow_hashref ) {
+ while ( my $tuple = $
day_month_closed_days
_sth->fetchrow_hashref ) {
$self->{day_month_closed_days}->{ $tuple->{month} }->{ $tuple->{day} } =
1;
}
$self->{day_month_closed_days}->{ $tuple->{month} }->{ $tuple->{day} } =
1;
}
- my $
special
= $dbh->prepare(
-'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception =
?
'
+ my $
exception_holidays_sth
= $dbh->prepare(
+'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception =
1
'
);
);
- $
special->execute( $branch, 1
);
+ $
exception_holidays_sth->execute( $branch
);
my $dates = [];
my $dates = [];
- while ( my ( $day, $month, $year ) = $
special
->fetchrow ) {
+ while ( my ( $day, $month, $year ) = $
exception_holidays_sth
->fetchrow ) {
push @{$dates},
DateTime->new(
day => $day,
push @{$dates},
DateTime->new(
day => $day,
@@
-66,9
+69,12
@@
sub _init {
$self->{exception_holidays} =
DateTime::Set->from_datetimes( dates => $dates );
$self->{exception_holidays} =
DateTime::Set->from_datetimes( dates => $dates );
- $special->execute( $branch, 0 );
+ my $single_holidays_sth = $dbh->prepare(
+'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0'
+ );
+ $single_holidays_sth->execute( $branch );
$dates = [];
$dates = [];
- while ( my ( $day, $month, $year ) = $s
pecial
->fetchrow ) {
+ while ( my ( $day, $month, $year ) = $s
ingle_holidays_sth
->fetchrow ) {
push @{$dates},
DateTime->new(
day => $day,
push @{$dates},
DateTime->new(
day => $day,
@@
-241,6
+247,13
@@
sub days_between {
my $start_dt = shift;
my $end_dt = shift;
my $start_dt = shift;
my $end_dt = shift;
+ if ( $start_dt->compare($end_dt) > 0 ) {
+ # swap dates
+ my $int_dt = $end_dt;
+ $end_dt = $start_dt;
+ $start_dt = $int_dt;
+ }
+
# start and end should not be closed days
my $days = $start_dt->delta_days($end_dt)->delta_days;
# start and end should not be closed days
my $days = $start_dt->delta_days($end_dt)->delta_days;