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

--- Comment #2 from Tomás Cohen Arazi (tcohen) <[email protected]> ---
Created attachment 208481
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208481&action=edit
Bug 42334: Add Koha::Library::Calendar::DateCalculator

Koha::Library::Calendar mixes two concerns: calendar data (which days
are closed) and date arithmetic that applies a useDaysMode policy
(calculating due dates, suspension end dates, etc). The policy is not
a property of the calendar, but it is currently passed to its
constructor as days_mode.

This patch introduces Koha::Library::Calendar::DateCalculator, which
takes a calendar and a days_mode and implements the policy-dependent
arithmetic:

- add_duration (replaces addDuration, addDays and addHours)
- next_open_days / prev_open_days

days_mode is mandatory and validated once in the constructor
(Days, Calendar, Datedue or Dayweek).

Koha::Library::Calendar gets:

- date_calculator( { days_mode => $days_mode } ): accessor returning a
  calculator for the calendar, so callers don't need to load the class
- library_id: accessor for the library the calendar belongs to
- is_weekly_closure( $dt ): tells if the weekday of $dt is a weekly
  closure, needed by the Dayweek policy without reaching into the
  calendar internals

The logic is moved from Koha::Library::Calendar, including the bug
43838 fix (next_open_days and prev_open_days step one day at a time,
and only weekly Dayweek periods move to the next open matching weekday).
The old methods are removed in the next patch.

Test plan:
1. Apply patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/Koha/Library/Calendar/DateCalculator.t \
           t/db_dependent/Koha/Library/Calendar.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Assisted-by: Opus 5.5 (Anthropic)

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to