Created
May 8, 2020 06:48
-
-
Save begimai/7488501ebcc59b4d051458ddb0e97c39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from typing import Dict, List | |
from apps.orders.models import OrderQuerySet | |
def split_by_order_dates(available_dates: List[Dict[str, datetime.datetime]], | |
ordered_dates: 'OrderQuerySet') -> List[Dict[str, datetime.datetime]]: | |
""" | |
It removes dates allocated by accepted Orders from available schedule dates. | |
:param available_dates: list of advert's available Schedule, | |
:param ordered_dates: list of start/end dates of accepted orders by this particular advert, | |
:return: list available schedule subtract accepted orders dates. | |
""" | |
return_dates = list(available_dates) | |
if len(ordered_dates) == 0: | |
return return_dates | |
for out in ordered_dates: | |
for inner in return_dates: | |
if inner['start_date'] < out['end_date'] <= inner['end_date'] and inner['end_date'] > out['start_date']: | |
return_dates += [{'start_date': inner['start_date'], 'end_date': out['start_date']}, | |
{'start_date': out['end_date'], 'end_date': inner['end_date']}] | |
return_dates.remove(inner) | |
return return_dates |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment