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
08bbb22a
Commit
08bbb22a
authored
Jan 23, 2014
by
Jason Bau
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2284 from edx/jbau/edx-west/lms-localize-datetime
Start datetime localization in LMS
parents
48d1dd56
6cb237e8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
6 deletions
+38
-6
common/lib/xmodule/xmodule/tests/test_date_utils.py
+18
-1
common/lib/xmodule/xmodule/util/date_utils.py
+11
-2
lms/envs/test.py
+1
-0
lms/templates/courseware/accordion.html
+2
-1
lms/templates/courseware/progress.html
+6
-2
No files found.
common/lib/xmodule/xmodule/tests/test_date_utils.py
View file @
08bbb22a
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
from
nose.tools
import
assert_equals
,
assert_false
# pylint: disable=E0611
from
nose.tools
import
assert_equals
,
assert_false
# pylint: disable=E0611
from
xmodule.util.date_utils
import
get_default_time_display
,
get_time_display
,
almost_same_datetime
from
xmodule.util.date_utils
import
get_default_time_display
,
get_time_display
,
almost_same_datetime
from
datetime
import
datetime
,
timedelta
,
tzinfo
from
datetime
import
datetime
,
timedelta
,
tzinfo
from
pytz
import
UTC
from
pytz
import
UTC
,
timezone
def
test_get_default_time_display
():
def
test_get_default_time_display
():
...
@@ -42,6 +42,23 @@ def test_get_time_pass_through():
...
@@ -42,6 +42,23 @@ def test_get_time_pass_through():
assert_equals
(
"Mar 12, 1992 at 15:03 UTC"
,
get_time_display
(
test_time
,
"
%
"
))
assert_equals
(
"Mar 12, 1992 at 15:03 UTC"
,
get_time_display
(
test_time
,
"
%
"
))
def
test_get_time_display_coerce
():
test_time_standard
=
datetime
(
1992
,
1
,
12
,
15
,
3
,
30
,
tzinfo
=
UTC
)
test_time_daylight
=
datetime
(
1992
,
7
,
12
,
15
,
3
,
30
,
tzinfo
=
UTC
)
assert_equals
(
"Jan 12, 1992 at 07:03 PST"
,
get_time_display
(
test_time_standard
,
None
,
coerce_tz
=
"US/Pacific"
))
assert_equals
(
"Jan 12, 1992 at 15:03 UTC"
,
get_time_display
(
test_time_standard
,
None
,
coerce_tz
=
"NONEXISTENTTZ"
))
assert_equals
(
"Jan 12 07:03"
,
get_time_display
(
test_time_standard
,
'
%
b
%
d
%
H:
%
M'
,
coerce_tz
=
"US/Pacific"
))
assert_equals
(
"Jul 12, 1992 at 08:03 PDT"
,
get_time_display
(
test_time_daylight
,
None
,
coerce_tz
=
"US/Pacific"
))
assert_equals
(
"Jul 12, 1992 at 15:03 UTC"
,
get_time_display
(
test_time_daylight
,
None
,
coerce_tz
=
"NONEXISTENTTZ"
))
assert_equals
(
"Jul 12 08:03"
,
get_time_display
(
test_time_daylight
,
'
%
b
%
d
%
H:
%
M'
,
coerce_tz
=
"US/Pacific"
))
# pylint: disable=W0232
# pylint: disable=W0232
class
NamelessTZ
(
tzinfo
):
class
NamelessTZ
(
tzinfo
):
"""Static timezone for testing"""
"""Static timezone for testing"""
...
...
common/lib/xmodule/xmodule/util/date_utils.py
View file @
08bbb22a
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
Convenience methods for working with datetime objects
Convenience methods for working with datetime objects
"""
"""
from
datetime
import
timedelta
from
datetime
import
timedelta
from
pytz
import
timezone
,
UTC
,
UnknownTimeZoneError
def
get_default_time_display
(
dtime
):
def
get_default_time_display
(
dtime
):
"""
"""
...
@@ -25,7 +25,7 @@ def get_default_time_display(dtime):
...
@@ -25,7 +25,7 @@ def get_default_time_display(dtime):
tz
=
timezone
)
.
strip
()
tz
=
timezone
)
.
strip
()
def
get_time_display
(
dtime
,
format_string
=
None
):
def
get_time_display
(
dtime
,
format_string
=
None
,
coerce_tz
=
None
):
"""
"""
Converts a datetime to a string representation.
Converts a datetime to a string representation.
...
@@ -34,8 +34,17 @@ def get_time_display(dtime, format_string=None):
...
@@ -34,8 +34,17 @@ def get_time_display(dtime, format_string=None):
If the format_string is None, or if format_string is improperly
If the format_string is None, or if format_string is improperly
formatted, this method will return the value from `get_default_time_display`.
formatted, this method will return the value from `get_default_time_display`.
Coerces aware datetime to tz=coerce_tz if set. coerce_tz should be a pytz timezone string
like "US/Pacific", or None
format_string should be a unicode string that is a valid argument for datetime's strftime method.
format_string should be a unicode string that is a valid argument for datetime's strftime method.
"""
"""
if
dtime
is
not
None
and
dtime
.
tzinfo
is
not
None
and
coerce_tz
:
try
:
to_tz
=
timezone
(
coerce_tz
)
except
UnknownTimeZoneError
:
to_tz
=
UTC
dtime
=
to_tz
.
normalize
(
dtime
.
astimezone
(
to_tz
))
if
dtime
is
None
or
format_string
is
None
:
if
dtime
is
None
or
format_string
is
None
:
return
get_default_time_display
(
dtime
)
return
get_default_time_display
(
dtime
)
try
:
try
:
...
...
lms/envs/test.py
View file @
08bbb22a
...
@@ -84,6 +84,7 @@ XQUEUE_INTERFACE = {
...
@@ -84,6 +84,7 @@ XQUEUE_INTERFACE = {
}
}
XQUEUE_WAITTIME_BETWEEN_REQUESTS
=
5
# seconds
XQUEUE_WAITTIME_BETWEEN_REQUESTS
=
5
# seconds
TIME_ZONE
=
'UTC'
# Don't rely on a real staff grading backend
# Don't rely on a real staff grading backend
MOCK_STAFF_GRADING
=
True
MOCK_STAFF_GRADING
=
True
...
...
lms/templates/courseware/accordion.html
View file @
08bbb22a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
django
.
core
.
urlresolvers
import
reverse
from
django
.
core
.
urlresolvers
import
reverse
from
xmodule
.
util
.
date_utils
import
get_time_display
from
xmodule
.
util
.
date_utils
import
get_time_display
from
django
.
utils
.
translation
import
ugettext
as
_
from
django
.
utils
.
translation
import
ugettext
as
_
from
django
.
conf
import
settings
%
>
%
>
<
%
def
name=
"make_chapter(chapter)"
>
<
%
def
name=
"make_chapter(chapter)"
>
...
@@ -29,7 +30,7 @@
...
@@ -29,7 +30,7 @@
if
section
.
get
('
due
')
is
None:
if
section
.
get
('
due
')
is
None:
due_date =
''
due_date =
''
else:
else:
formatted_string =
get_time_display(section['due'],
due_date_display_format
)
formatted_string =
get_time_display(section['due'],
due_date_display_format
,
coerce_tz=
settings.TIME_ZONE
)
due_date =
''
if
len
(
formatted_string
)==
0
else
_
('
due
{
date
}'.
format
(
date=
formatted_string))
due_date =
''
if
len
(
formatted_string
)==
0
else
_
('
due
{
date
}'.
format
(
date=
formatted_string))
%
>
%
>
<p
class=
"subtitle"
>
${section['format']} ${due_date}
</p>
<p
class=
"subtitle"
>
${section['format']} ${due_date}
</p>
...
...
lms/templates/courseware/progress.html
View file @
08bbb22a
...
@@ -15,7 +15,11 @@
...
@@ -15,7 +15,11 @@
from
django
.
core
.
urlresolvers
import
reverse
from
django
.
core
.
urlresolvers
import
reverse
%
>
%
>
<
%!
from
xmodule
.
util
.
date_utils
import
get_time_display
%
>
<
%!
from
xmodule
.
util
.
date_utils
import
get_time_display
from
django
.
conf
import
settings
import
pytz
%
>
<
%
block
name=
"js_extra"
>
<
%
block
name=
"js_extra"
>
<script
type=
"text/javascript"
src=
"${static.url('js/vendor/flot/jquery.flot.js')}"
></script>
<script
type=
"text/javascript"
src=
"${static.url('js/vendor/flot/jquery.flot.js')}"
></script>
...
@@ -71,7 +75,7 @@ ${progress_graph.body(grade_summary, course.grade_cutoffs, "grade-detail-graph",
...
@@ -71,7 +75,7 @@ ${progress_graph.body(grade_summary, course.grade_cutoffs, "grade-detail-graph",
%if section.get('due') is not None:
%if section.get('due') is not None:
<
%
<
%
formatted_string =
get_time_display(section['due'],
course
.
due_date_display_format
)
formatted_string =
get_time_display(section['due'],
course
.
due_date_display_format
,
coerce_tz=
settings.TIME_ZONE
)
due_date =
''
if
len
(
formatted_string
)==
0
else
_
(
u
'
due
{
date
}').
format
(
date=
formatted_string)
due_date =
''
if
len
(
formatted_string
)==
0
else
_
(
u
'
due
{
date
}').
format
(
date=
formatted_string)
%
>
%
>
<em>
<em>
...
...
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