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
3188bb06
Commit
3188bb06
authored
Jun 24, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: Use approximate comparison when checking for changes to start dates
parent
1c5706fb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
24 deletions
+67
-24
cms/templates/edit_subsection.html
+4
-3
common/lib/xmodule/xmodule/tests/test_date_utils.py
+47
-20
common/lib/xmodule/xmodule/tests/test_export.py
+4
-1
common/lib/xmodule/xmodule/util/date_utils.py
+12
-0
No files found.
cms/templates/edit_subsection.html
View file @
3188bb06
<
%
inherit
file=
"base.html"
/>
<
%!
import
logging
from
xmodule
.
util
.
date_utils
import
get_default_time_display
from
xmodule
.
util
.
date_utils
import
get_default_time_display
,
almost_same_datetime
%
>
<
%!
from
django
.
core
.
urlresolvers
import
reverse
%
>
...
...
@@ -47,9 +47,10 @@
placeholder=
"HH:MM"
class=
"time"
size=
'10'
autocomplete=
"off"
/>
</div>
</div>
% if subsection.lms.start
!= parent_item.lms.start and subsection.lms.start
:
% if subsection.lms.start
and not almost_same_datetime(subsection.lms.start, parent_item.lms.start)
:
% if parent_item.lms.start is None:
<p
class=
"notice"
>
The date above differs from the release date of ${parent_item.display_name_with_default}, which is unset.
<p
class=
"notice"
>
The date above differs from the release date of
${parent_item.display_name_with_default}, which is unset.
% else:
<p
class=
"notice"
>
The date above differs from the release date of ${parent_item.display_name_with_default} –
${get_default_time_display(parent_item.lms.start)}.
...
...
common/lib/xmodule/xmodule/tests/test_date_utils.py
View file @
3188bb06
# Tests for xmodule.util.date_utils
from
nose.tools
import
assert_equals
from
xmodule.util
import
date_utils
import
datetime
from
nose.tools
import
assert_equals
,
assert_false
from
xmodule.util
.date_utils
import
get_default_time_display
,
almost_same_datetime
from
datetime
import
datetime
,
timedelta
,
tzinfo
from
pytz
import
UTC
def
test_get_default_time_display
():
assert_equals
(
""
,
date_utils
.
get_default_time_display
(
None
))
test_time
=
datetime
.
datetime
(
1992
,
3
,
12
,
15
,
3
,
30
,
tzinfo
=
UTC
)
assert_equals
(
""
,
get_default_time_display
(
None
))
test_time
=
datetime
(
1992
,
3
,
12
,
15
,
3
,
30
,
tzinfo
=
UTC
)
assert_equals
(
"Mar 12, 1992 at 15:03 UTC"
,
date_utils
.
get_default_time_display
(
test_time
))
get_default_time_display
(
test_time
))
assert_equals
(
"Mar 12, 1992 at 15:03 UTC"
,
date_utils
.
get_default_time_display
(
test_time
,
True
))
get_default_time_display
(
test_time
,
True
))
assert_equals
(
"Mar 12, 1992 at 15:03"
,
date_utils
.
get_default_time_display
(
test_time
,
False
))
get_default_time_display
(
test_time
,
False
))
def
test_get_default_time_display_notz
():
test_time
=
datetime
.
datetime
(
1992
,
3
,
12
,
15
,
3
,
30
)
test_time
=
datetime
(
1992
,
3
,
12
,
15
,
3
,
30
)
assert_equals
(
"Mar 12, 1992 at 15:03 UTC"
,
date_utils
.
get_default_time_display
(
test_time
))
get_default_time_display
(
test_time
))
assert_equals
(
"Mar 12, 1992 at 15:03 UTC"
,
date_utils
.
get_default_time_display
(
test_time
,
True
))
get_default_time_display
(
test_time
,
True
))
assert_equals
(
"Mar 12, 1992 at 15:03"
,
date_utils
.
get_default_time_display
(
test_time
,
False
))
get_default_time_display
(
test_time
,
False
))
# pylint: disable=W0232
class
NamelessTZ
(
datetime
.
tzinfo
):
class
NamelessTZ
(
tzinfo
):
def
utcoffset
(
self
,
_dt
):
return
datetime
.
timedelta
(
hours
=-
3
)
return
timedelta
(
hours
=-
3
)
def
dst
(
self
,
_dt
):
return
datetime
.
timedelta
(
0
)
return
timedelta
(
0
)
def
test_get_default_time_display_no_tzname
():
assert_equals
(
""
,
date_utils
.
get_default_time_display
(
None
))
test_time
=
datetime
.
datetime
(
1992
,
3
,
12
,
15
,
3
,
30
,
tzinfo
=
NamelessTZ
())
assert_equals
(
""
,
get_default_time_display
(
None
))
test_time
=
datetime
(
1992
,
3
,
12
,
15
,
3
,
30
,
tzinfo
=
NamelessTZ
())
assert_equals
(
"Mar 12, 1992 at 15:03-0300"
,
date_utils
.
get_default_time_display
(
test_time
))
get_default_time_display
(
test_time
))
assert_equals
(
"Mar 12, 1992 at 15:03-0300"
,
date_utils
.
get_default_time_display
(
test_time
,
True
))
get_default_time_display
(
test_time
,
True
))
assert_equals
(
"Mar 12, 1992 at 15:03"
,
date_utils
.
get_default_time_display
(
test_time
,
False
))
get_default_time_display
(
test_time
,
False
))
def
test_almost_same_datetime
():
assert
almost_same_datetime
(
datetime
(
2013
,
5
,
3
,
10
,
20
,
30
),
datetime
(
2013
,
5
,
3
,
10
,
21
,
29
)
)
assert
almost_same_datetime
(
datetime
(
2013
,
5
,
3
,
11
,
20
,
30
),
datetime
(
2013
,
5
,
3
,
10
,
21
,
29
),
timedelta
(
hours
=
1
)
)
assert_false
(
almost_same_datetime
(
datetime
(
2013
,
5
,
3
,
11
,
20
,
30
),
datetime
(
2013
,
5
,
3
,
10
,
21
,
29
)
)
)
assert_false
(
almost_same_datetime
(
datetime
(
2013
,
5
,
3
,
11
,
20
,
30
),
datetime
(
2013
,
5
,
3
,
10
,
21
,
29
),
timedelta
(
minutes
=
10
)
)
)
common/lib/xmodule/xmodule/tests/test_export.py
View file @
3188bb06
...
...
@@ -185,6 +185,9 @@ class TestEdxJsonEncoder(unittest.TestCase):
self
.
encoder
.
default
(
datetime
(
2013
,
5
,
3
,
10
,
20
,
30
,
0
,
self
.
null_utc_tz
))
)
def
test_
other_classes
(
self
):
def
test_
fallthrough
(
self
):
with
self
.
assertRaises
(
TypeError
):
self
.
encoder
.
default
(
None
)
with
self
.
assertRaises
(
TypeError
):
self
.
encoder
.
default
({})
common/lib/xmodule/xmodule/util/date_utils.py
View file @
3188bb06
import
datetime
def
get_default_time_display
(
dt
,
show_timezone
=
True
):
"""
Converts a datetime to a string representation. This is the default
...
...
@@ -20,3 +21,14 @@ def get_default_time_display(dt, show_timezone=True):
else
:
timezone
=
" UTC"
return
dt
.
strftime
(
"
%
b
%
d,
%
Y at
%
H:
%
M"
)
+
timezone
def
almost_same_datetime
(
dt1
,
dt2
,
allowed_delta
=
datetime
.
timedelta
(
minutes
=
1
)):
"""
Returns true if these are w/in a minute of each other. (in case secs saved to db
or timezone aren't same)
:param dt1:
:param dt2:
"""
return
abs
(
dt1
-
dt2
)
<
allowed_delta
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