helpers.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:Githeat 作者: AmmsA 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号