From 0c41e17476c5a08402d56ca5e30f8c80c40a9631 Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Oct 05 2017 08:10:26 +0000
Subject: [PATCH 1/2] fix formatTime for DateTime


Related: https://pagure.io/koji/issue/623

---

diff --git a/koji/__init__.py b/koji/__init__.py
index 0dad3db..cfc47d2 100644
--- a/koji/__init__.py
+++ b/koji/__init__.py
@@ -78,7 +78,7 @@ import warnings
 import xml.sax
 import xml.sax.handler
 import six.moves.urllib
-from koji.xmlrpcplus import getparser, loads, dumps, Fault
+from koji.xmlrpcplus import getparser, loads, dumps, Fault, xmlrpc_client
 
 
 PROFILE_MODULES = {}  # {module_name: module_instance}
@@ -2766,7 +2766,9 @@ def formatTime(value):
     """Format a timestamp so it looks nicer"""
     if not value:
         return ''
-    elif isinstance(value, datetime.datetime):
+    if isinstance(value, xmlrpc_client.DateTime):
+        value = datetime.datetime.strptime(value.value, "%Y%m%dT%H:%M:%S")
+    if isinstance(value, datetime.datetime):
         return value.strftime('%Y-%m-%d %H:%M:%S')
     else:
         # trim off the microseconds, if present
diff --git a/tests/test_lib/test_format_time.py b/tests/test_lib/test_format_time.py
new file mode 100644
index 0000000..7ba28a8
--- /dev/null
+++ b/tests/test_lib/test_format_time.py
@@ -0,0 +1,48 @@
+from __future__ import absolute_import
+import datetime
+import unittest
+import six.moves.xmlrpc_client as xmlrpc_client
+
+from koji import formatTime, formatTimeLong
+
+class TestFormatTime(unittest.TestCase):
+    def test_format_time(self):
+        self.assertEqual(formatTime(None), '')
+        self.assertEqual(formatTime(''), '')
+
+        desired = '2017-10-05 09:52:31'
+        # datetime
+        d = datetime.datetime(year=2017, month=10, day=5, hour=9, minute=52, second=31, microsecond=12)
+        self.assertEqual(formatTime(d), desired)
+
+        # DateTime
+        d1 = xmlrpc_client.DateTime(d)
+        self.assertEqual(formatTime(d1), desired)
+
+        # str
+        self.assertEqual(formatTime(desired), desired)
+
+        # str + microseconds
+        self.assertEqual(formatTime(desired + '.123'), desired)
+
+    def test_format_time_long(self):
+        self.assertEqual(formatTimeLong(None), '')
+        self.assertEqual(formatTimeLong(''), '')
+
+        desired = 'Thu, 05 Oct 2017 09:52:31 CEST'
+
+        # datetime
+        d = datetime.datetime(year=2017, month=10, day=5, hour=9, minute=52, second=31, microsecond=12)
+        self.assertEqual(formatTimeLong(d), desired)
+
+        # DateTime
+        d1 = xmlrpc_client.DateTime(d)
+        self.assertEqual(formatTimeLong(d1), desired)
+
+        # str
+        d2 = '2017-10-05 09:52:31'
+        self.assertEqual(formatTimeLong(d2), desired)
+
+        # str + microseconds
+        self.assertEqual(formatTimeLong(d2 + '.123'), desired)
+

From fbb1fca30f528022a4d8996e167d0b0d3154709f Mon Sep 17 00:00:00 2001
From: Tomas Kopecek <tkopecek@redhat.com>
Date: Oct 05 2017 08:31:26 +0000
Subject: [PATCH 2/2] ignore concrete timezone in tests


---

diff --git a/tests/test_lib/test_format_time.py b/tests/test_lib/test_format_time.py
index 7ba28a8..f989aa4 100644
--- a/tests/test_lib/test_format_time.py
+++ b/tests/test_lib/test_format_time.py
@@ -29,20 +29,27 @@ class TestFormatTime(unittest.TestCase):
         self.assertEqual(formatTimeLong(None), '')
         self.assertEqual(formatTimeLong(''), '')
 
-        desired = 'Thu, 05 Oct 2017 09:52:31 CEST'
+        desired = 'Thu, 05 Oct 2017 09:52:31'
 
         # datetime
         d = datetime.datetime(year=2017, month=10, day=5, hour=9, minute=52, second=31, microsecond=12)
-        self.assertEqual(formatTimeLong(d), desired)
+        r = formatTimeLong(d)
+        r = r[:r.rfind(' ')]
+        self.assertEqual(r, desired)
 
         # DateTime
         d1 = xmlrpc_client.DateTime(d)
-        self.assertEqual(formatTimeLong(d1), desired)
+        r = formatTimeLong(d1)
+        r = r[:r.rfind(' ')]
+        self.assertEqual(r, desired)
 
         # str
         d2 = '2017-10-05 09:52:31'
-        self.assertEqual(formatTimeLong(d2), desired)
+        r = formatTimeLong(d2)
+        r = r[:r.rfind(' ')]
+        self.assertEqual(r, desired)
 
         # str + microseconds
-        self.assertEqual(formatTimeLong(d2 + '.123'), desired)
-
+        r = formatTimeLong(d2 + '.123')
+        r = r[:r.rfind(' ')]
+        self.assertEqual(r, desired)

