From 5a70796bc297e8e2b64d3925e3c916697770ae9b Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 14 Mar 2025 14:53:44 +0100 Subject: 🐛 archaeological files: manage business for deadlines (refs #6218) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ishtar_common/utils.py') diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index af4ea06dc..4e80ac60a 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -3151,6 +3151,27 @@ def reverse_list_coordinates(lst): return list(reversed(lst)) +def add_business_days(from_date: datetime.datetime, + business_days_to_add: int) -> datetime.datetime: + """ + Add days to a date with exclusion of saturday and sunday. + """ + num_whole_weeks = business_days_to_add // 5 + extra_days = num_whole_weeks * 2 + + # manage the last week + first_weekday = from_date.weekday() + remainder_days = business_days_to_add % 5 + + if (first_weekday + remainder_days) > 4: + if first_weekday == 5: + extra_days += 1 + elif first_weekday != 6: + extra_days += 2 + + return from_date + datetime.timedelta(business_days_to_add + extra_days) + + class EachCharacterTypeValidator: def __init__(self, character_types=None): if not character_types: -- cgit v1.2.3