diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-03-14 14:53:44 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-03-17 19:46:07 +0100 |
commit | 5a70796bc297e8e2b64d3925e3c916697770ae9b (patch) | |
tree | 4928b092da84b3b5c70362eca7681d9d16e1bfa0 /ishtar_common | |
parent | 35cf272b8602d89fda1b13653442323fda46835c (diff) | |
download | Ishtar-5a70796bc297e8e2b64d3925e3c916697770ae9b.tar.bz2 Ishtar-5a70796bc297e8e2b64d3925e3c916697770ae9b.zip |
🐛 archaeological files: manage business for deadlines (refs #6218)
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/utils.py | 21 |
1 files changed, 21 insertions, 0 deletions
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: |