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
865b6936
Commit
865b6936
authored
Jun 02, 2014
by
polesye
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BLD-1060: Fix RelativeTime.
parent
ee368da6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
97 deletions
+110
-97
CHANGELOG.rst
+2
-0
common/lib/xmodule/xmodule/js/spec/time_spec.js
+57
-50
common/lib/xmodule/xmodule/js/src/time.js
+51
-47
No files found.
CHANGELOG.rst
View file @
865b6936
...
...
@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes,
in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected.
Blades: Fix bug with incorrect RelativeTime value after XML serialization. BLD-1060
LMS: Update bulk email implementation to lessen load on the database
by consolidating chunked queries for recipients into a single query.
...
...
common/lib/xmodule/xmodule/js/spec/time_spec.js
View file @
865b6936
(
function
(
undefined
)
{
'use strict'
;
describe
(
'Time'
,
function
()
{
describe
(
'format'
,
function
()
{
describe
(
'with duration more than or equal to 1 hour'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
3600
)).
toEqual
(
'1:00:00'
);
expect
(
Time
.
format
(
7272
)).
toEqual
(
'2:01:12'
);
});
});
describe
(
'with duration less than 1 hour'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
1
)).
toEqual
(
'0:01'
);
expect
(
Time
.
format
(
61
)).
toEqual
(
'1:01'
);
expect
(
Time
.
format
(
3599
)).
toEqual
(
'59:59'
);
});
});
});
describe
(
'formatFull'
,
function
()
{
it
(
'gives correct string for times'
,
function
()
{
var
testTimes
=
[
[
0
,
'00:00:00'
],
[
60
,
'00:01:00'
],
[
488
,
'00:08:08'
],
[
2452
,
'00:40:52'
],
[
3600
,
'01:00:00'
],
[
28800
,
'08:00:00'
],
[
144532
,
'40:08:52'
],
[
190360
,
'52:52:40'
],
[
294008
,
'81:40:08'
]
];
$
.
each
(
testTimes
,
function
(
index
,
times
)
{
var
timeInt
=
times
[
0
],
timeStr
=
times
[
1
];
expect
(
Time
.
formatFull
(
timeInt
)).
toBe
(
timeStr
);
});
});
});
describe
(
'convert'
,
function
()
{
it
(
'return a correct time based on speed modifier'
,
function
()
{
expect
(
Time
.
convert
(
0
,
1
,
1.5
)).
toEqual
(
'0.000'
);
expect
(
Time
.
convert
(
100
,
1
,
1.5
)).
toEqual
(
'66.667'
);
expect
(
Time
.
convert
(
100
,
1.5
,
1
)).
toEqual
(
'150.000'
);
});
});
});
}).
call
(
this
);
(
function
(
undefined
)
{
'use strict'
;
describe
(
'Time'
,
function
()
{
describe
(
'format'
,
function
()
{
describe
(
'with NAN'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
'string'
)).
toEqual
(
'0:00'
);
expect
(
Time
.
format
(
void
(
0
))).
toEqual
(
'0:00'
);
});
});
describe
(
'with duration more than or equal to 1 hour'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
3600
)).
toEqual
(
'1:00:00'
);
expect
(
Time
.
format
(
7272
)).
toEqual
(
'2:01:12'
);
});
});
describe
(
'with duration less than 1 hour'
,
function
()
{
it
(
'return a correct time format'
,
function
()
{
expect
(
Time
.
format
(
1
)).
toEqual
(
'0:01'
);
expect
(
Time
.
format
(
61
)).
toEqual
(
'1:01'
);
expect
(
Time
.
format
(
3599
)).
toEqual
(
'59:59'
);
});
});
});
describe
(
'formatFull'
,
function
()
{
it
(
'gives correct string for times'
,
function
()
{
var
testTimes
=
[
[
0
,
'00:00:00'
],
[
60
,
'00:01:00'
],
[
488
,
'00:08:08'
],
[
2452
,
'00:40:52'
],
[
3600
,
'01:00:00'
],
[
28800
,
'08:00:00'
],
[
144532
,
'40:08:52'
],
[
190360
,
'52:52:40'
],
[
294008
,
'81:40:08'
]
];
$
.
each
(
testTimes
,
function
(
index
,
times
)
{
var
timeInt
=
times
[
0
],
timeStr
=
times
[
1
];
expect
(
Time
.
formatFull
(
timeInt
)).
toBe
(
timeStr
);
});
});
});
describe
(
'convert'
,
function
()
{
it
(
'return a correct time based on speed modifier'
,
function
()
{
expect
(
Time
.
convert
(
0
,
1
,
1.5
)).
toEqual
(
'0.000'
);
expect
(
Time
.
convert
(
100
,
1
,
1.5
)).
toEqual
(
'66.667'
);
expect
(
Time
.
convert
(
100
,
1.5
,
1
)).
toEqual
(
'150.000'
);
});
});
});
}).
call
(
this
);
common/lib/xmodule/xmodule/js/src/time.js
View file @
865b6936
(
function
(
undefined
)
{
'use strict'
;
this
.
Time
=
{
format
:
format
,
formatFull
:
formatFull
,
convert
:
convert
};
return
;
function
format
(
time
,
formatFull
)
{
var
hours
,
minutes
,
seconds
;
seconds
=
Math
.
floor
(
time
);
minutes
=
Math
.
floor
(
seconds
/
60
);
hours
=
Math
.
floor
(
minutes
/
60
);
seconds
=
seconds
%
60
;
minutes
=
minutes
%
60
;
if
(
formatFull
)
{
return
''
+
_pad
(
hours
)
+
':'
+
_pad
(
minutes
)
+
':'
+
_pad
(
seconds
%
60
);
}
else
if
(
hours
)
{
return
''
+
hours
+
':'
+
_pad
(
minutes
)
+
':'
+
_pad
(
seconds
%
60
);
}
else
{
return
''
+
minutes
+
':'
+
_pad
(
seconds
%
60
);
}
}
function
formatFull
(
time
)
{
// The returned value will not be user-facing. So no need for
// internationalization.
return
format
(
time
,
true
);
}
function
convert
(
time
,
oldSpeed
,
newSpeed
)
{
return
(
time
*
oldSpeed
/
newSpeed
).
toFixed
(
3
);
}
function
_pad
(
number
)
{
if
(
number
<
10
)
{
return
'0'
+
number
;
}
else
{
return
''
+
number
;
}
}
}).
call
(
this
);
(
function
(
undefined
)
{
'use strict'
;
this
.
Time
=
{
format
:
format
,
formatFull
:
formatFull
,
convert
:
convert
};
return
;
function
format
(
time
,
formatFull
)
{
var
hours
,
minutes
,
seconds
;
if
(
!
_
.
isFinite
(
time
))
{
time
=
0
;
}
seconds
=
Math
.
floor
(
time
);
minutes
=
Math
.
floor
(
seconds
/
60
);
hours
=
Math
.
floor
(
minutes
/
60
);
seconds
=
seconds
%
60
;
minutes
=
minutes
%
60
;
if
(
formatFull
)
{
return
''
+
_pad
(
hours
)
+
':'
+
_pad
(
minutes
)
+
':'
+
_pad
(
seconds
%
60
);
}
else
if
(
hours
)
{
return
''
+
hours
+
':'
+
_pad
(
minutes
)
+
':'
+
_pad
(
seconds
%
60
);
}
else
{
return
''
+
minutes
+
':'
+
_pad
(
seconds
%
60
);
}
}
function
formatFull
(
time
)
{
// The returned value will not be user-facing. So no need for
// internationalization.
return
format
(
time
,
true
);
}
function
convert
(
time
,
oldSpeed
,
newSpeed
)
{
return
(
time
*
oldSpeed
/
newSpeed
).
toFixed
(
3
);
}
function
_pad
(
number
)
{
if
(
number
<
10
)
{
return
'0'
+
number
;
}
else
{
return
''
+
number
;
}
}
}).
call
(
this
);
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