diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-23 22:02:03 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-23 22:02:03 +0000 |
| commit | 416e92d728b351a5ffbbbf0dda4973d41b1a7947 (patch) | |
| tree | 294a06323d123c9bfd1a594ae04a31a7cc28dde7 | |
| parent | e59f763b2a4325b583a40afe29b95e41bd0e5a5e (diff) | |
| parent | d3a4c8e8f466d5c7b2f5f8c076a48326e5bbaa40 (diff) | |
| download | oslo-416e92d728b351a5ffbbbf0dda4973d41b1a7947.tar.gz oslo-416e92d728b351a5ffbbbf0dda4973d41b1a7947.tar.xz oslo-416e92d728b351a5ffbbbf0dda4973d41b1a7947.zip | |
Merge "UTC ISO8601 from timestamp"
| -rw-r--r-- | openstack/common/timeutils.py | 5 | ||||
| -rw-r--r-- | tests/unit/test_timeutils.py | 7 |
2 files changed, 12 insertions, 0 deletions
diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index 572c829..5a011e8 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 3ad07a8..9c3469e 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): |
