Commit 040b4da1 by Alexander Kryklia Committed by polesye

Change str of RelativeTime.

parent 14dc814e
......@@ -207,3 +207,15 @@ class RelativeTime(Field):
return str(value)
raise TypeError("RelativeTime: cannot convert {!r} to json".format(value))
def __str__(self):
"""
Makes first H in str representation non-optional.
str(timedelta) has [H]H:MM:SS format, which is not suitable
for front-end (and IsoTime standart), so we forse HH:MM:SS
"""
_str = super(RelativeTime, slef).__str__(self)
if len(_str) == 7:
_str = '0' + _str
return _str
......@@ -167,3 +167,13 @@ class RelativeTimeTest(unittest.TestCase):
with self.assertRaises(TypeError):
RelativeTimeTest.delta.to_json("123")
def test_str(self):
self.assertEqual(
"1:02:03",
RelativeTimeTest.delta.to_json(datetime.timedelta(seconds=3723))
)
self.assertEqual(
"11:02:03",
RelativeTimeTest.delta.to_json(datetime.timedelta(seconds=39723))
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment