summaryrefslogtreecommitdiffstats
path: root/nova/openstack
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-10-23 16:49:45 +0000
committerGerrit Code Review <review@openstack.org>2012-10-23 16:49:45 +0000
commit3fddbb2dffc50178cf9898aa2cce877c225b92d0 (patch)
treedbeccff7c898701c635efadff0bba9d44f810adb /nova/openstack
parent97f33b349ee267c14f473e6e0cca1b091d22fbf1 (diff)
parent5b92d8c26ac75f1b2ef42510bd55a35be703d280 (diff)
downloadnova-3fddbb2dffc50178cf9898aa2cce877c225b92d0.tar.gz
nova-3fddbb2dffc50178cf9898aa2cce877c225b92d0.tar.xz
nova-3fddbb2dffc50178cf9898aa2cce877c225b92d0.zip
Merge "Sync with latest version of openstack.common.timeutils"
Diffstat (limited to 'nova/openstack')
-rw-r--r--nova/openstack/common/timeutils.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/nova/openstack/common/timeutils.py b/nova/openstack/common/timeutils.py
index c4f6cf049..86004391d 100644
--- a/nova/openstack/common/timeutils.py
+++ b/nova/openstack/common/timeutils.py
@@ -62,9 +62,11 @@ def parse_strtime(timestr, fmt=PERFECT_TIME_FORMAT):
def normalize_time(timestamp):
- """Normalize time in arbitrary timezone to UTC"""
+ """Normalize time in arbitrary timezone to UTC naive object"""
offset = timestamp.utcoffset()
- return timestamp.replace(tzinfo=None) - offset if offset else timestamp
+ if offset is None:
+ return timestamp
+ return timestamp.replace(tzinfo=None) - offset
def is_older_than(before, seconds):
@@ -72,6 +74,11 @@ def is_older_than(before, seconds):
return utcnow() - before > datetime.timedelta(seconds=seconds)
+def is_newer_than(after, seconds):
+ """Return True if after is newer than seconds."""
+ return after - utcnow() > datetime.timedelta(seconds=seconds)
+
+
def utcnow_ts():
"""Timestamp version of our utcnow function."""
return calendar.timegm(utcnow().timetuple())
@@ -121,6 +128,10 @@ def marshall_now(now=None):
def unmarshall_time(tyme):
"""Unmarshall a datetime dict."""
- return datetime.datetime(day=tyme['day'], month=tyme['month'],
- year=tyme['year'], hour=tyme['hour'], minute=tyme['minute'],
- second=tyme['second'], microsecond=tyme['microsecond'])
+ return datetime.datetime(day=tyme['day'],
+ month=tyme['month'],
+ year=tyme['year'],
+ hour=tyme['hour'],
+ minute=tyme['minute'],
+ second=tyme['second'],
+ microsecond=tyme['microsecond'])