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

--- Comment #8 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 189155
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=189155&action=edit
Bug 38940: Consider calendar holidays when extending loans to next opening time

This follow-up patch addresses a limitation in the previous fix where
ConsiderLibraryHoursInCirculation='open' mode would extend loans to
tomorrow's opening time even when tomorrow was marked as a holiday in
the calendar.

The issue: A library might have operating hours defined for every day of
the week (e.g., Monday-Sunday 09:00-17:00), but have specific days
marked as holidays in the calendar (e.g., public holidays, special
closures). The previous code only checked if operating hours were
defined, not whether the library was actually open according to the
calendar.

This patch modifies the logic to:
1. When in 'open' mode with Calendar daysmode, check if tomorrow is a
   holiday in the calendar
2. If tomorrow is a holiday, look forward up to 7 days to find the next
   day that is:
   - Not marked as a holiday in the calendar AND
   - Has defined operating hours
3. Extend the loan to that day's opening time
4. If no suitable day is found within 7 days, fall back to standard
   loan duration (ignoring library hours)

Note: 'close' mode is unaffected since we only need today's closing
time, and checkouts can only happen on open days.

Test plan:
1. Apply patch and run tests:
   prove t/db_dependent/Circulation/CalcDateDue.t

2. Note the current time and day of week for your testing.
   Configure Koha based on the current time to test the functionality.

3. Configure library operating hours at Administration > Libraries > [Select
your library] > Hours

   Set operating hours for multiple consecutive days:
   - TODAY (your current day): Set hours that include the current time
     Example: If it's currently 14:30, set hours like 09:00-17:00
   - TOMORROW: Set hours (e.g., 10:00-18:00)
   - DAY AFTER TOMORROW: Set hours (e.g., 10:00-18:00)
   - THIRD DAY: Set hours (e.g., 10:00-18:00)

   Example if testing on Friday at 14:30:
   - Friday: 09:00-17:00 (must include current time)
   - Saturday: 10:00-18:00
   - Sunday: 10:00-18:00
   - Monday: 10:00-18:00

4. Mark tomorrow as a holiday at Tools > Calendar > [Select your library]
   - Click "New holiday" or "Holidays repeating weekly"
   - If testing on Friday, mark Saturday as a single-day holiday
   - Save the holiday

   Note: This creates a scenario where tomorrow HAS operating hours
   defined, but is marked as closed in the calendar (e.g., a public
   holiday that falls on a normally-open day)

5. Set system preferences:
   - ConsiderLibraryHoursInCirculation: "extend the loan period to the
library's next opening time"
   - useDaysMode: "Use the calendar to skip days the library is closed"

6. Create a circulation rule with hourly loan period:
   - Go to Administration > Circulation and fine rules
   - Set loan period in hours that would extend past today's closing time
   - Calculate: (Closing time - Current time) + 1 hour minimum
     Example: If it's 14:30 now and library closes at 17:00, set loan
     period to 4 or 5 hours

7. Test the 'open' behavior with calendar holidays:
   - Check out an item using the hourly loan rule

   Without patch: Due date/time would extend to tomorrow's opening time
                  (e.g., Saturday 10:00), even though Saturday is a holiday

   With patch: Due date/time should extend to the next open day's opening
               time (e.g., if Saturday is a holiday, should extend to
               Sunday 10:00, or if Sunday is also a holiday, to Monday 10:00)

8. Verify the behavior:
   - The due date should skip over the calendar holiday
   - Check out multiple items - they should all have the same due time
     (next open day's opening time)

9. Test with multiple consecutive holidays:
   - Mark both TOMORROW and DAY AFTER as holidays in the calendar
   - Check out an item
   - Should extend to THIRD DAY's opening time (first non-holiday day
     with defined hours)

10. Test fallback behavior:
    - Configure library with NO operating hours for any day after today
    - Mark tomorrow as a holiday
    - Check out should fall back to standard loan duration since there's
      no suitable day to extend to

11. Test with 'close' mode to verify it's unaffected:
    - Change ConsiderLibraryHoursInCirculation to "shorten the loan
      period to end when the library closes"
    - Check out an item
    - Should still shorten to today's closing time (calendar holidays
      don't affect this mode since we only need today's hours)

NOTES FOR REVIEW:

This patch looks ahead up to 7 days to find a suitable open day. This
limit prevents infinite loops and matches typical library closure
patterns (weekend + public holiday = 3-4 days max).

When no suitable day is found within 7 days, the system falls back to
standard loan duration, which then uses the calendar's normal day-
skipping logic when the loan comes due.

This patch only affects Calendar daysmode. When using Days mode (ignore
calendar), the behavior is unchanged from the previous patch.

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to