[Koha-bugs] [Bug 34117] Duplicate patron sets dateenrolled incorrectly

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Jul 20 15:23:43 CEST 2023


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=34117

--- Comment #9 from Jonathan Druart <jonathan.druart+koha at gmail.com> ---
(In reply to Emily Lamancusa from comment #8)
> (In reply to Jonathan Druart from comment #7)
> > Sorry, I haven't seen Emily's comment!
> > 
> > There is something weird here as well:
> > 105 sub get_expiry_date {
> > 109         $date = dt_from_string( $date ) unless ref $date;
> > 
> > Which means get_expiry_date should deal with DateTime object correctly.
> 
> Line 109 keeps the original object if one was passed, and creates a new
> object if a string was passed, right? And then in the next line...
> 
> 110 return $date->add( months => $self->enrolmentperiod, end_of_month =>
> 'limit' );
> 
> According to https://metacpan.org/pod/DateTime#Math-Methods:
> "Like the set methods, math related methods always return the object itself,
> to allow for chaining"
> 
> So unless I'm misunderstanding the Perl from line 109, if get_expiry_date is
> passed an object, it updates and returns that same object, which
> memberentry.pl doesn't take into account in line 725:
> $data{dateexpiry} = $category->get_expiry_date( $data{dateenrolled} );


DateTime modifies the original object.

For instance:
use Koha::DateUtils qw( dt_from_string );
my $dt = dt_from_string;
say $dt; 
say $dt->add( days => 2 ); 
say $dt; 

2023-07-20T13:14:51
2023-07-22T13:14:51
2023-07-22T13:14:51



So, if a DateTime object is passed to get_expiry_date
108         $date ||= dt_from_string;
=> $date is still the variable passed in parameter
109         $date = dt_from_string( $date ) unless ref $date;
=> same
110         return $date->add( months => $self->enrolmentperiod, end_of_month
=> 'limit' );
=> We return the object we passed (modified)

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list