From a956f7aab04f9914870980cb3acb0d5bcafbe1f0 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 23 Jan 2013 13:50:25 +0100 Subject: Import timeutils.is_soon from keystoneclient This is a function defined as will_expire_soon at least twice in python-keystoneclient, and it's actually quite handy. There is a comment on that code about moving to timeutils, and it actually sounds like a good idea since I'm likely to use it in Ceilometer, so here it is. Change-Id: Idf208ce9e7ce9048a38d98212b7f730c6b7c8288 Signed-off-by: Julien Danjou --- openstack/common/timeutils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'openstack') diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index 0f34608..572c829 100644 --- a/openstack/common/timeutils.py +++ b/openstack/common/timeutils.py @@ -162,3 +162,16 @@ def delta_seconds(before, after): except AttributeError: return ((delta.days * 24 * 3600) + delta.seconds + float(delta.microseconds) / (10 ** 6)) + + +def is_soon(dt, window): + """ + Determines if time is going to happen in the next window seconds. + + :params dt: the time + :params window: minimum seconds to remain to consider the time not soon + + :return: True if expiration is within the given duration + """ + soon = (utcnow() + datetime.timedelta(seconds=window)) + return normalize_time(dt) < soon -- cgit