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
056b7d34
Commit
056b7d34
authored
Mar 22, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More unit tests which found another timezone assumption :-)
parent
862a7d13
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
9 deletions
+28
-9
cms/djangoapps/contentstore/tests/test_course_settings.py
+21
-1
common/djangoapps/util/converters.py
+2
-5
common/lib/xmodule/xmodule/fields.py
+5
-3
No files found.
cms/djangoapps/contentstore/tests/test_course_settings.py
View file @
056b7d34
...
...
@@ -22,6 +22,7 @@ from xmodule.modulestore.tests.factories import CourseFactory
from
models.settings.course_metadata
import
CourseMetadata
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.django
import
modulestore
import
time
# YYYY-MM-DDThh:mm:ss.s+/-HH:MM
...
...
@@ -39,6 +40,7 @@ class ConvertersTestCase(TestCase):
+
str
(
date2
)
+
"!="
+
str
(
expected_delta
))
def
test_iso_to_struct
(
self
):
'''Test conversion from iso compatible date strings to struct_time'''
self
.
compare_dates
(
converters
.
jsdate_to_time
(
"2013-01-01"
),
converters
.
jsdate_to_time
(
"2012-12-31"
),
datetime
.
timedelta
(
days
=
1
))
...
...
@@ -54,10 +56,28 @@ class ConvertersTestCase(TestCase):
self
.
compare_dates
(
converters
.
jsdate_to_time
(
"2013-01-01T00:00:00Z"
),
converters
.
jsdate_to_time
(
"2012-12-31T23:59:59Z"
),
datetime
.
timedelta
(
seconds
=
1
))
self
.
compare_dates
(
converters
.
jsdate_to_time
(
"2012-12-31T23:00:01-01:00"
),
self
.
compare_dates
(
converters
.
jsdate_to_time
(
"2012-12-31T23:00:01-01:00"
),
converters
.
jsdate_to_time
(
"2013-01-01T00:00:00+01:00"
),
datetime
.
timedelta
(
hours
=
1
,
seconds
=
1
))
def
test_struct_to_iso
(
self
):
'''
Test converting time reprs to iso dates
'''
self
.
assertEqual
(
converters
.
time_to_isodate
(
time
.
strptime
(
"2012-12-31T23:59:59Z"
,
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ"
)),
"2012-12-31T23:59:59Z"
)
self
.
assertEqual
(
converters
.
time_to_isodate
(
jsdate_to_time
(
"2012-12-31T23:59:59Z"
)),
"2012-12-31T23:59:59Z"
)
self
.
assertEqual
(
converters
.
time_to_isodate
(
jsdate_to_time
(
"2012-12-31T23:00:01-01:00"
)),
"2013-01-01T00:00:01Z"
)
class
CourseTestCase
(
ModuleStoreTestCase
):
def
setUp
(
self
):
...
...
common/djangoapps/util/converters.py
View file @
056b7d34
...
...
@@ -4,9 +4,6 @@ import calendar
import
dateutil.parser
tz
=
"{:+03d}:{:02d}"
.
format
(
time
.
timezone
/
3600
,
time
.
timezone
%
3600
)
def
time_to_date
(
time_obj
):
"""
Convert a time.time_struct to a true universal time (can pass to js Date
...
...
@@ -18,9 +15,9 @@ def time_to_date(time_obj):
def
time_to_isodate
(
source
):
'''Convert to an iso date'''
if
isinstance
(
source
,
time
.
struct_time
):
return
time
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S
'
+
tz
,
source
)
return
time
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S
Z'
,
source
)
elif
isinstance
(
source
,
datetime
):
return
source
.
isoformat
()
+
tz
return
source
.
isoformat
()
+
'Z'
def
jsdate_to_time
(
field
):
...
...
common/lib/xmodule/xmodule/fields.py
View file @
056b7d34
...
...
@@ -11,8 +11,10 @@ log = logging.getLogger(__name__)
class
Date
(
ModelType
):
tz
=
"{:+03d}:{:02d}"
.
format
(
time
.
timezone
/
3600
,
time
.
timezone
%
3600
)
'''
Date fields know how to parse and produce json (iso) compatible formats.
'''
# NB: these are copies of util.converters.*
def
from_json
(
self
,
field
):
"""
Parse an optional metadata key containing a time: if present, complain
...
...
@@ -44,7 +46,7 @@ class Date(ModelType):
# struct_times are always utc
return
time
.
strftime
(
'
%
Y-
%
m-
%
dT
%
H:
%
M:
%
SZ'
,
value
)
elif
isinstance
(
value
,
datetime
.
datetime
):
return
value
.
isoformat
()
+
Date
.
tz
return
value
.
isoformat
()
+
'Z'
TIMEDELTA_REGEX
=
re
.
compile
(
r'^((?P<days>\d+?) day(?:s?))?(\s)?((?P<hours>\d+?) hour(?:s?))?(\s)?((?P<minutes>\d+?) minute(?:s)?)?(\s)?((?P<seconds>\d+?) second(?:s)?)?$'
)
...
...
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