diff options
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: |