docker-tidy/docker_custodian/args.py

20 lines
511 B
Python
Raw Normal View History

2015-06-30 22:33:43 +00:00
import datetime
from dateutil import tz
from pytimeparse import timeparse
def timedelta_type(value):
"""Retrun the :class:`datetime.datetime.DateTime` for a time in the past.
:param value: a string containing a time format supported by :mod:`pytimeparse`
"""
if value is None:
return None
return datetime_seconds_ago(timeparse.timeparse(value))
def datetime_seconds_ago(seconds):
now = datetime.datetime.now(tz.tzutc())
return now - datetime.timedelta(seconds=seconds)