parent
bea9a86916
commit
470addae97
2 changed files with 52 additions and 2 deletions
|
|
@ -78,7 +78,7 @@ import warnings
|
||||||
import xml.sax
|
import xml.sax
|
||||||
import xml.sax.handler
|
import xml.sax.handler
|
||||||
import six.moves.urllib
|
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}
|
PROFILE_MODULES = {} # {module_name: module_instance}
|
||||||
|
|
@ -2766,7 +2766,9 @@ def formatTime(value):
|
||||||
"""Format a timestamp so it looks nicer"""
|
"""Format a timestamp so it looks nicer"""
|
||||||
if not value:
|
if not value:
|
||||||
return ''
|
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')
|
return value.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
else:
|
else:
|
||||||
# trim off the microseconds, if present
|
# trim off the microseconds, if present
|
||||||
|
|
|
||||||
48
tests/test_lib/test_format_time.py
Normal file
48
tests/test_lib/test_format_time.py
Normal file
|
|
@ -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)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue