summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorGuang Yee <guang.yee@hp.com>2013-02-28 14:51:24 -0800
committerAdam Young <ayoung@redhat.com>2013-03-04 19:14:22 -0500
commit2cb8e4557b05f92fbd9f56b7a6a6d4f35c8a883a (patch)
tree68c469bc01883bccc845f9b1b1a6bad5b14bbd3f /openstack
parentf39d38e08b187e2dbff0f57f487e022512b3a106 (diff)
downloadoslo-2cb8e4557b05f92fbd9f56b7a6a6d4f35c8a883a.tar.gz
oslo-2cb8e4557b05f92fbd9f56b7a6a6d4f35c8a883a.tar.xz
oslo-2cb8e4557b05f92fbd9f56b7a6a6d4f35c8a883a.zip
support ISO 8601 micro-second precision
Bug 1134802 Change-Id: I9cc3c9d9324314d293f01f047882eb6be06e02dd
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/timeutils.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py
index e2c2740..8e40660 100644
--- a/openstack/common/timeutils.py
+++ b/openstack/common/timeutils.py
@@ -25,18 +25,22 @@ import datetime
import iso8601
-TIME_FORMAT = "%Y-%m-%dT%H:%M:%S"
-PERFECT_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
+# ISO 8601 extended time format with microseconds
+_ISO8601_TIME_FORMAT_SUBSECOND = '%Y-%m-%dT%H:%M:%S.%f'
+_ISO8601_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
+PERFECT_TIME_FORMAT = _ISO8601_TIME_FORMAT_SUBSECOND
-def isotime(at=None):
+def isotime(at=None, subsecond=False):
"""Stringify time in ISO 8601 format"""
if not at:
at = utcnow()
- str = at.strftime(TIME_FORMAT)
+ st = at.strftime(_ISO8601_TIME_FORMAT
+ if not subsecond
+ else _ISO8601_TIME_FORMAT_SUBSECOND)
tz = at.tzinfo.tzname(None) if at.tzinfo else 'UTC'
- str += ('Z' if tz == 'UTC' else tz)
- return str
+ st += ('Z' if tz == 'UTC' else tz)
+ return st
def parse_isotime(timestr):