def get_months_with_last_same_as_first(start_date, months, include_year=False):
"""
Returns a list of months abbreviations starting from start_date, and last month
is the same is first month (i.e. extra month)
:param include_year:
:param start_date:
:param months: number of previous months to return
:return: list of months abbr if not include_year, else list of tuple [year, month]
"""
if include_year:
months = get_months(datetime.date.today(), 12, include_year=True)
# update last month to have current year
months = [[start_date.year, calendar.month_abbr[start_date.month]]] + months
else:
months = get_months(datetime.date.today(), 12)
# append current month to front of list
months = [months[-1]] + months
return months
评论列表
文章目录