diff options
author | Julien Danjou <julien@danjou.info> | 2013-01-23 13:50:25 +0100 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2013-01-23 17:49:01 +0100 |
commit | a956f7aab04f9914870980cb3acb0d5bcafbe1f0 (patch) | |
tree | 91c073e9a4791d922df701f677d10ccab91693be /openstack/common | |
parent | cf7f75d66ca8e20e1058758ce5f0fb9859f413de (diff) | |
download | oslo-a956f7aab04f9914870980cb3acb0d5bcafbe1f0.tar.gz oslo-a956f7aab04f9914870980cb3acb0d5bcafbe1f0.tar.xz oslo-a956f7aab04f9914870980cb3acb0d5bcafbe1f0.zip |
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 <julien@danjou.info>
Diffstat (limited to 'openstack/common')
-rw-r--r-- | openstack/common/timeutils.py | 13 |
1 files changed, 13 insertions, 0 deletions
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 |