jobs.py 文件源码

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

项目:jobs 作者: josiahcarlson 项目源码 文件源码
def _to_ts(val):
    if isinstance(val, (int, float)):
        return val
    elif isinstance(val, (datetime, date)):
        return (val-EPOCH).total_seconds()
    v = TS_RE.match(val)
    if v:
        return float(v.group(0))
    v = DT_RE.match(val)
    if v:
        # get all of the passed datetime pieces, don't worry about them being
        # terribly valid, the datetime constructor will handle that ;)
        v = list(filter(None, v.groups()))
        if len(v) == 7:
            # truncate to microseconds as necessary
            v[6] = v[6][:6]
            # extend to microseconds as necessary
            v[6] += (6 - len(v[6])) * '0'
        v = list(map(int, v))
        dt = datetime(*v)
        return (dt-EPOCH).total_seconds()
    raise Exception("Value %r is not a timestamp, datetime, or date"%(val,))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号