Bug 34435: Remove side effect from get_password_expiry_date

If get_password_expiry_date is passed a DateTime object
as a parameter, it modifies and returns the original
object. This can create possible side effects.

This patch modifies get_password_expiry_date to clone the
DateTime object that it receives as a parameter and
return the modified clone, so that object references can
be passed in safely.

To test:
prove t/db_dependent/Koha/Patron/Category.t

Signed-off-by: Sam Lau <samalau@gmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit dae5607fd1)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
emlam 2023-07-27 16:36:34 +00:00 committed by Fridolin Somers
parent ef24af8da3
commit f067a82e3a
1 changed files with 1 additions and 1 deletions

View File

@ -126,7 +126,7 @@ sub get_password_expiry_date {
my ($self, $date ) = @_;
if ( $self->password_expiry_days ) {
$date ||= dt_from_string;
$date = dt_from_string( $date ) unless ref $date;
$date = ref $date ? $date->clone() : dt_from_string( $date );
return $date->add( days => $self->password_expiry_days )->ymd;
} else {
return;