0

I am trying to build a function that creates a list of start and end dates. I am implementing it using a recursive function. Problem is my list isn't returned. When I run the code below:

from dateutil import parser

def dateinterval(listing_date, dates=[]):
    period = 1000

    dates.append(listing_date)
    base = parser.parse(listing_date)
    next_date = base + datetime.timedelta(days=period)
    dates.append(next_date.strftime('%Y-%m-%d'))
    if base > datetime.datetime.now():
        dates.append(datetime.datetime.now().strftime('%Y-%m-%d'))
        print dates
        return dates
    dateinterval(next_date.strftime('%Y-%m-%d'), dates)


a = dateinterval('2017-01-01')
print(a)

I get the following result:

['2017-01-01', '2019-09-28', '2019-09-28', '2022-06-24', '2022-06-24', '2025-03-20', '2025-03-20', '2027-12-15', '2022-10-03']
None

What am I missing?

A39-A20
  • 35
  • 2
  • 9

0 Answers0