Skip to content

Commit

Permalink
Fix year overrides (#123)
Browse files Browse the repository at this point in the history
* better handle overrides between years

* update changelog

* Update CHANGES.rst

---------

Co-authored-by: Mauro Amico <[email protected]>
  • Loading branch information
cekk and mamico authored Nov 20, 2023
1 parent 9178b7f commit da7d692
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Changelog
- Add booking_refuse_message to Prenotazione stringinterp variables.
[folix-01]

- Better handle overrides between years.
[cekk]


2.1.5 (2023-11-10)
------------------
Expand Down
14 changes: 11 additions & 3 deletions src/redturtle/prenotazioni/browser/prenotazioni_context_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,21 @@ def get_week_overrides(self, day):
to_date = date(to_year, to_month, to_day)
else:
# ends next year (i.e. from "20 dec" to "7 jan")
today_year = date.today().year
if today_year < to_year:
from_date = date(today_year, from_month, from_day)
if day.month < from_month:
# i.e day is 03 jan
from_date = date(to_year - 1, from_month, from_day)
to_date = date(to_year, to_month, to_day)
else:
# i.e day is 28 dec
from_date = date(to_year, from_month, from_day)
to_date = date(to_year + 1, to_month, to_day)
# today_year = date.today().year
# if today_year < to_year:
# from_date = date(today_year, from_month, from_day)
# to_date = date(to_year, to_month, to_day)
# else:
# from_date = date(to_year, from_month, from_day)
# to_date = date(to_year + 1, to_month, to_day)

if isinstance(day, datetime):
if from_date <= day.date() <= to_date:
Expand Down
6 changes: 6 additions & 0 deletions src/redturtle/prenotazioni/tests/test_week_table_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def test_override_between_year(self):
json.loads(self.folder_prenotazioni.week_table_overrides)[0]["week_table"],
)

# if in range and next year +1, return table overrides
self.assertEqual(
self.view.get_week_table(date(now.year + 1, 12, 25)),
json.loads(self.folder_prenotazioni.week_table_overrides)[0]["week_table"],
)

# if out of range, return base table
self.assertEqual(
self.view.get_week_table(date(now.year, 10, 10)),
Expand Down

0 comments on commit da7d692

Please sign in to comment.