def get_months(start_date, months, include_year=False):
"""
Returns a list of months abbreviations starting from start_date
: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 list [year, month]
"""
result = []
for i in range(months):
start_date -= datetime.timedelta(days=calendar.monthrange(start_date.year,
start_date.month)[1])
if include_year:
result.append([start_date.year, calendar.month_abbr[start_date.month]])
else:
result.append(calendar.month_abbr[start_date.month])
return result
评论列表
文章目录