def calculate_dates_for_week_of_year()

in assets/glue/scripts/business_aggregate_weekly.py [0:0]


def calculate_dates_for_week_of_year(date_str):
    """
        Returns a list of dates that belong to the week of year of the passed date
        20200827 --> week 35 --> dates for week 35 -->
        ['20200824', '20200825', '20200826', '20200827', '20200828', '20200829', '20200830']

    :param date_str:
    :return: list of dates as string with the format yyyyMMdd
    """
    date_time_obj = datetime.datetime.strptime(date_str, '%Y%m%d')

    # Starts with knowing the day of the week
    # -1 because the week starts with monday (instead of sunday) in this case
    week_day = date_time_obj.isocalendar()[2] - 1
    print(week_day)

    # Calculates Starting date (Monday) for this case by subtracting
    # current date with time delta of the day of the week
    start_date = date_time_obj - datetime.timedelta(days=week_day)

    return "({})".format(",".join(str((start_date + datetime.timedelta(days=i)).date().strftime("%Y%m%d")) for i in range(7)))