From 09b341db792fa25fe67c560c65f278ce9c70957e Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Thu, 3 Jan 2013 11:23:30 -0800 Subject: Make time comparison functions accept strings This patch makes is_older_than() and is_newer_than() accept timestamps in string format, as returned from strtime(). Change-Id: I1dbf453cc08bd8aaeb4fee2491a1e8aa74f8bee3 --- openstack/common/timeutils.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'openstack') diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index ea69164..e518733 100644 --- a/openstack/common/timeutils.py +++ b/openstack/common/timeutils.py @@ -71,11 +71,15 @@ def normalize_time(timestamp): def is_older_than(before, seconds): """Return True if before is older than seconds.""" + if isinstance(before, str): + before = parse_strtime(before).replace(tzinfo=None) return utcnow() - before > datetime.timedelta(seconds=seconds) def is_newer_than(after, seconds): """Return True if after is newer than seconds.""" + if isinstance(after, str): + after = parse_strtime(after).replace(tzinfo=None) return after - utcnow() > datetime.timedelta(seconds=seconds) -- cgit