Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
040b4da1
Commit
040b4da1
authored
Oct 22, 2013
by
Alexander Kryklia
Committed by
polesye
Oct 23, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change str of RelativeTime.
parent
14dc814e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
common/lib/xmodule/xmodule/fields.py
+12
-0
common/lib/xmodule/xmodule/tests/test_fields.py
+10
-0
No files found.
common/lib/xmodule/xmodule/fields.py
View file @
040b4da1
...
...
@@ -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
common/lib/xmodule/xmodule/tests/test_fields.py
View file @
040b4da1
...
...
@@ -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
))
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment