From 7374bcda25b1dc89b30d7d239f0dcc737c2c187e Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 11 Feb 2016 10:30:09 -0500 Subject: [PATCH] Fixing bug with DateTime str test An issue with local daylight savings time causes a comparison error in some locales when checking against a hard-coded expected time string. The DateTime primitive string representation has been updated to output only UTC time strings. Fixes #124 --- kmip/core/primitives.py | 2 +- kmip/tests/unit/core/primitives/test_date_time.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/kmip/core/primitives.py b/kmip/core/primitives.py index 5b46787..a36759f 100644 --- a/kmip/core/primitives.py +++ b/kmip/core/primitives.py @@ -977,7 +977,7 @@ class DateTime(LongInteger): return "DateTime(value={0}, tag={1})".format(self.value, self.tag) def __str__(self): - return time.ctime(self.value) + return time.asctime(time.gmtime(self.value)) class Interval(Base): diff --git a/kmip/tests/unit/core/primitives/test_date_time.py b/kmip/tests/unit/core/primitives/test_date_time.py index 7393a1f..2ed334e 100644 --- a/kmip/tests/unit/core/primitives/test_date_time.py +++ b/kmip/tests/unit/core/primitives/test_date_time.py @@ -14,7 +14,6 @@ # under the License. import testtools -import time from kmip.core import primitives from kmip.core import utils @@ -90,8 +89,7 @@ class TestDateTime(testtools.TestCase): Test that the string representation of a DateTime is formatted properly. """ - t = (2015, 8, 11, 9, 18, 55, 1, 223, 1) - s = "Tue Aug 11 09:18:55 2015" + expected = 'Tue Aug 11 13:18:55 2015' + date_time = primitives.DateTime(1439299135) - date_time = primitives.DateTime(int(time.mktime(t))) - self.assertEqual(s, str(date_time)) + self.assertEqual(expected, str(date_time))