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
This commit is contained in:
Flaper Fesp
2013-01-21 16:31:51 +01:00
parent b1c5269b20
commit d3a4c8e8f4
2 changed files with 12 additions and 0 deletions

View File

@@ -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

View File

@@ -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):