Bug 30518: Correct DateTime maths for needs_advancing
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 13 Apr 2022 07:24:22 +0000 (08:24 +0100)
committerKyle Hall <kyle@bywatersolutions.com>
Fri, 29 Apr 2022 15:15:09 +0000 (11:15 -0400)
commit3929335cdbea81c7c891a8a979d69861468502fd
tree6725f9cb049e0871f7de40b93331cff0472dad12
parent4450ad21100a02055e3f0f05918b2d4b17852107
Bug 30518: Correct DateTime maths for needs_advancing

The needs_advancing method prior to this patch used basic DateTime
arithmatic, adding a DateTime::Duration in Days to the Arrival date of
the item and then comparing that to today. This, however, can cause bugs
when the arrival + duration date coincides with a DST boundary and as
such may result in an invalid local date.  See
https://metacpan.org/pod/DateTime#Making-Things-Simple for further
details.

This patch updates the code to use the DST safe delta_days method to
count the days between arrival and now instead and then compares this
integer to the defined duration of the stage.

To test:
1. Re-run the unit tests, they should now pass.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Koha/StockRotationItem.pm