Bug 15260: Fix calculation of add amount

In a sequence of closed days, we should take into account the nature
of each closed day as we encounter it in order to calculate the amount
to add to reach the next potential closed date. We are now doing this.

Sponsored-by: Cheshire West and Chester Council
Sponsored-by: Cheshire East Council
Sponsored-by: Newcastle City Council
Sponsored-by: Sefton Council
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Andrew Isherwood 2019-03-26 14:43:34 +00:00 committed by Martin Renvoize
parent d39c14561f
commit bca351113d
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -217,14 +217,9 @@ sub addDays {
if ( $self->is_holiday($base_date) ) { if ( $self->is_holiday($base_date) ) {
my $dow = $base_date->day_of_week; my $dow = $base_date->day_of_week;
my $days = $days_duration->in_units('days'); my $days = $days_duration->in_units('days');
my $push_amt = ( # Is it a period based on weeks
# We're using Dayweek useDaysMode option my $push_amt = $days_duration % 7 == 0 ?
$self->{days_mode} eq 'Dayweek' && $self->get_push_amt($base_date) : 1;
# It's period based on weeks
$days % 7 == 0 &&
# It's not a permanently closed day
!$self->{weekly_closed_days}->[$dow] == 1
) ? 7 : 1;
if ( $days_duration->is_negative() ) { if ( $days_duration->is_negative() ) {
$base_date = $self->prev_open_days($base_date, $push_amt); $base_date = $self->prev_open_days($base_date, $push_amt);
} else { } else {
@ -237,6 +232,18 @@ sub addDays {
return $base_date; return $base_date;
} }
sub get_push_amt {
my ( $self, $base_date) = @_;
my $dow = $base_date->day_of_week;
return (
# We're using Dayweek useDaysMode option
$self->{days_mode} eq 'Dayweek' &&
# It's not a permanently closed day
!$self->{weekly_closed_days}->[$dow] == 1
) ? 7 : 1;
}
sub is_holiday { sub is_holiday {
my ( $self, $dt ) = @_; my ( $self, $dt ) = @_;
@ -285,7 +292,8 @@ sub next_open_days {
$base_date->add(days => $to_add); $base_date->add(days => $to_add);
while ($self->is_holiday($base_date)) { while ($self->is_holiday($base_date)) {
$base_date->add(days => $to_add); my $add_next = $self->get_push_amt($base_date);
$base_date->add(days => $add_next);
} }
return $base_date; return $base_date;
} }
@ -301,7 +309,8 @@ sub prev_open_days {
$base_date->add(days => $to_sub); $base_date->add(days => $to_sub);
while ($self->is_holiday($base_date)) { while ($self->is_holiday($base_date)) {
$base_date->add(days => $to_sub); my $sub_next = $self->get_push_amt($base_date);
$base_date->add(days => $sub_next);
} }
return $base_date; return $base_date;