diff options
| author | Yunhong, Jiang <yunhong.jiang@intel.com> | 2012-10-23 16:07:29 +0800 |
|---|---|---|
| committer | Yunhong, Jiang <yunhong.jiang@intel.com> | 2012-10-23 16:39:03 +0800 |
| commit | 5b92d8c26ac75f1b2ef42510bd55a35be703d280 (patch) | |
| tree | 8b216b707bcf13e83720ac01b304c94d8b2b4a47 /nova/openstack | |
| parent | a0fcd1248071ad66b610eac4903adf36b314390b (diff) | |
| download | nova-5b92d8c26ac75f1b2ef42510bd55a35be703d280.tar.gz nova-5b92d8c26ac75f1b2ef42510bd55a35be703d280.tar.xz nova-5b92d8c26ac75f1b2ef42510bd55a35be703d280.zip | |
Sync with latest version of openstack.common.timeutils
Changes since last sync:
- Added is_newer_than function
- Normalize_time() always return naive object
- Use pep8 v1.3.3
Change-Id: I47c74671907a2f64a3fdd2caf857999c33033bdd
Diffstat (limited to 'nova/openstack')
| -rw-r--r-- | nova/openstack/common/timeutils.py | 21 |
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']) |
