Beispiel #1
0
def time2utc(st):
    st_time = strp_lenient(st)
    if st_time is not None:
        dt_ts = datetime.fromtimestamp(time2epoch(st_time), tz=timezone.utc)
        return dt_ts.isoformat().replace("+00:00", "Z")
    else:
        sys.exit("Could not parse time {}: check and retry".format(st))
def test_strp_lenient():
    for spec in [
            '2017-02-02T16:45:43.887484+00:00',
            '2017-02-02T16:45:43.887484+00',
            '2017-02-02T16:45:43.887484',
            '2017-02-02T16:45:43',
            '2017-02-02T16:45',
            '2017-02-02T16',
            '2017-02-02',
    ]:
        p = utils.strp_lenient(spec)
        assert p is not None, spec + " failed"
        assert datetime.strftime(p, utils._ISO_FMT).startswith(spec)

    withz = '2017-02-02T16:45:43Z'
    assert utils.strp_lenient(withz) == utils.strp_lenient(withz[:-1])
def test_strp_lenient():
    for spec in [
        '2017-02-02T16:45:43.887484+00:00',
        '2017-02-02T16:45:43.887484+00',
        '2017-02-02T16:45:43.887484',
        '2017-02-02T16:45:43',
        '2017-02-02T16:45',
        '2017-02-02T16',
        '2017-02-02',
    ]:
        p = utils.strp_lenient(spec)
        assert p is not None, spec + " failed"
        assert datetime.strftime(p, utils._ISO_FMT).startswith(spec)

    withz = '2017-02-02T16:45:43Z'
    assert utils.strp_lenient(withz) == utils.strp_lenient(withz[:-1])
Beispiel #4
0
    def convert(self, val, param, ctx):
        dates = val.split('/')
        if len(dates) > 2:
            raise click.BadParameter('Too many dates')

        for date in dates:
            if date != '..' and strp_lenient(date) is None:
                raise click.BadParameter('Invalid date: {}'.format(date))
Beispiel #5
0
 def _parse(self, val, param, ctx):
     parsed = strp_lenient(val)
     if parsed is None:
         self.fail('invalid date: %s.' % val, param, ctx)
     return parsed
 def _parse(self, val, param, ctx):
     parsed = strp_lenient(val)
     if parsed is None:
         self.fail('invalid date: %s.' % val, param, ctx)
     return parsed