util.py 文件源码

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

项目:zing 作者: evernote 项目源码 文件源码
def get_max_month_datetime(dt):
    """Returns the datetime representing the last microsecond of the month with
    respect to the `dt` aware datetime.
    """
    days_in_month = calendar.monthrange(dt.year, dt.month)[1]

    tz = timezone.get_default_timezone()
    new_dt = tz.normalize(
        dt.replace(day=days_in_month),
    )

    # DST adjustments could have shifted the month or day
    if new_dt.month != dt.month:
        new_dt = new_dt.replace(month=dt.month)
    if new_dt.day != days_in_month:
        new_dt = new_dt.replace(day=days_in_month)

    return new_dt.replace(hour=23, minute=59, second=59, microsecond=999999)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号