summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlaper Fesp <flaper87@gmail.com>2013-01-21 16:31:51 +0100
committerFlaper Fesp <flaper87@gmail.com>2013-01-21 18:20:27 +0100
commitd3a4c8e8f466d5c7b2f5f8c076a48326e5bbaa40 (patch)
tree8492c6427d2b2c1f570709e2fe7f1da849ef5784
parentb1c5269b20e58213da93254537435b67c258f236 (diff)
downloadoslo-d3a4c8e8f466d5c7b2f5f8c076a48326e5bbaa40.tar.gz
oslo-d3a4c8e8f466d5c7b2f5f8c076a48326e5bbaa40.tar.xz
oslo-d3a4c8e8f466d5c7b2f5f8c076a48326e5bbaa40.zip
UTC ISO8601 from timestamp
Taken from glance xattr.py module. This function converts timestamp formated dates into a UTC Iso 8601 date. It is being required in multiple places now (mostly on clients printing dates) in order to make dates human readable. Change-Id: I6f19325a4c2df241a0ef76bd256280a2930d9265
-rw-r--r--openstack/common/timeutils.py5
-rw-r--r--tests/unit/test_timeutils.py7
2 files changed, 12 insertions, 0 deletions
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py
index 0f34608..5fd158d 100644
--- a/openstack/common/timeutils.py
+++ b/openstack/common/timeutils.py
@@ -98,6 +98,11 @@ def utcnow():
return datetime.datetime.utcnow()
+def iso8601_from_timestamp(timestamp):
+ """Returns a iso8601 formated date from timestamp"""
+ return isotime(datetime.datetime.utcfromtimestamp(timestamp))
+
+
utcnow.override_time = None
diff --git a/tests/unit/test_timeutils.py b/tests/unit/test_timeutils.py
index 1407f29..04ddd4d 100644
--- a/tests/unit/test_timeutils.py
+++ b/tests/unit/test_timeutils.py
@@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import calendar
import datetime
import unittest
@@ -148,6 +149,12 @@ class TimeUtilsTest(unittest.TestCase):
self.assertAlmostEquals(604859.123456,
timeutils.delta_seconds(before, after))
+ def test_iso8601_from_timestamp(self):
+ utcnow = timeutils.utcnow()
+ iso = timeutils.isotime(utcnow)
+ ts = calendar.timegm(utcnow.timetuple())
+ self.assertEqual(iso, timeutils.iso8601_from_timestamp(ts))
+
class TestIso8601Time(unittest.TestCase):