caltrain.py 文件源码

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

项目:python-caltrain 作者: ownaginatious 项目源码 文件源码
def _resolve_time(t):
    """
    Resolves the time string into datetime.time. This method
    is needed because Caltrain arrival/departure time hours
    can exceed 23 (e.g. 24, 25), to signify trains that arrive
    after 12 AM. The 'day' variable is incremented from 0 in
    these situations, and the time resolved back to a valid
    datetime.time (e.g. 24:30:00 becomes days=1, 00:30:00).

    :param t: the time to resolve
    :type t: str or unicode

    :returns: tuple of days and datetime.time
    """
    hour, minute, second = [int(x) for x in t.split(":")]
    day, hour = divmod(hour, 24)
    r = _BASE_DATE + timedelta(hours=hour,
                               minutes=minute,
                               seconds=second)
    return day, r.time()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号