utils.py 文件源码

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

项目:django-happenings 作者: natgeosociety 项目源码 文件源码
def format_time(hour_tuple):
    """
    Convert to a 12hour time
    """
    hour = hour_tuple[0]
    duration = hour_tuple[1]
    if hour is None:
        return ''
    elif isinstance(hour, datetime.time):
        time = _parse_time_to_string(hour)
        if duration:
            end_hour = _add_minutes(hour, duration)
            end_time = _parse_time_to_string(end_hour)
            time = '%s - %s' % (time, end_time)
        return time
    else:
        try:
            if hour < 12:
                return "%s AM" % str(hour)
            elif hour == 12:
                return "%s PM" % str(hour)
            else:
                return "%s PM" % str(hour - 12)
        except ValueError:
            return hour
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号