Commit 865b6936 by polesye

BLD-1060: Fix RelativeTime.

parent ee368da6
...@@ -5,6 +5,8 @@ These are notable changes in edx-platform. This is a rolling list of changes, ...@@ -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 in roughly chronological order, most recent first. Add your entries at or near
the top. Include a label indicating the component affected. 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 LMS: Update bulk email implementation to lessen load on the database
by consolidating chunked queries for recipients into a single query. by consolidating chunked queries for recipients into a single query.
......
(function (undefined) { (function (undefined) {
'use strict'; 'use strict';
describe('Time', function () { describe('Time', function () {
describe('format', function () { describe('format', function () {
describe('with duration more than or equal to 1 hour', function () { describe('with NAN', function () {
it('return a correct time format', function () { it('return a correct time format', function () {
expect(Time.format(3600)).toEqual('1:00:00'); expect(Time.format('string')).toEqual('0:00');
expect(Time.format(7272)).toEqual('2:01:12'); expect(Time.format(void(0))).toEqual('0:00');
}); });
}); });
describe('with duration less than 1 hour', function () { describe('with duration more than or equal to 1 hour', function () {
it('return a correct time format', function () { it('return a correct time format', function () {
expect(Time.format(1)).toEqual('0:01'); expect(Time.format(3600)).toEqual('1:00:00');
expect(Time.format(61)).toEqual('1:01'); expect(Time.format(7272)).toEqual('2:01:12');
expect(Time.format(3599)).toEqual('59:59'); });
}); });
});
}); describe('with duration less than 1 hour', function () {
it('return a correct time format', function () {
describe('formatFull', function () { expect(Time.format(1)).toEqual('0:01');
it('gives correct string for times', function () { expect(Time.format(61)).toEqual('1:01');
var testTimes = [ expect(Time.format(3599)).toEqual('59:59');
[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'] describe('formatFull', function () {
]; it('gives correct string for times', function () {
var testTimes = [
$.each(testTimes, function (index, times) { [0, '00:00:00'], [60, '00:01:00'],
var timeInt = times[0], [488, '00:08:08'], [2452, '00:40:52'],
timeStr = times[1]; [3600, '01:00:00'], [28800, '08:00:00'],
[144532, '40:08:52'], [190360, '52:52:40'],
expect(Time.formatFull(timeInt)).toBe(timeStr); [294008, '81:40:08']
}); ];
});
}); $.each(testTimes, function (index, times) {
var timeInt = times[0],
describe('convert', function () { timeStr = times[1];
it('return a correct time based on speed modifier', function () {
expect(Time.convert(0, 1, 1.5)).toEqual('0.000'); expect(Time.formatFull(timeInt)).toBe(timeStr);
expect(Time.convert(100, 1, 1.5)).toEqual('66.667'); });
expect(Time.convert(100, 1.5, 1)).toEqual('150.000'); });
}); });
});
}); describe('convert', function () {
it('return a correct time based on speed modifier', function () {
}).call(this); 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) { (function (undefined) {
'use strict'; 'use strict';
this.Time = { this.Time = {
format: format, format: format,
formatFull: formatFull, formatFull: formatFull,
convert: convert convert: convert
}; };
return; return;
function format(time, formatFull) { function format(time, formatFull) {
var hours, minutes, seconds; var hours, minutes, seconds;
seconds = Math.floor(time); if (!_.isFinite(time)) {
minutes = Math.floor(seconds / 60); time = 0;
hours = Math.floor(minutes / 60); }
seconds = seconds % 60;
minutes = minutes % 60; seconds = Math.floor(time);
minutes = Math.floor(seconds / 60);
if (formatFull) { hours = Math.floor(minutes / 60);
return '' + _pad(hours) + ':' + _pad(minutes) + ':' + _pad(seconds % 60); seconds = seconds % 60;
} else if (hours) { minutes = minutes % 60;
return '' + hours + ':' + _pad(minutes) + ':' + _pad(seconds % 60);
} else { if (formatFull) {
return '' + minutes + ':' + _pad(seconds % 60); return '' + _pad(hours) + ':' + _pad(minutes) + ':' + _pad(seconds % 60);
} } else if (hours) {
} return '' + hours + ':' + _pad(minutes) + ':' + _pad(seconds % 60);
} else {
function formatFull(time) { return '' + minutes + ':' + _pad(seconds % 60);
// The returned value will not be user-facing. So no need for }
// internationalization. }
return format(time, true);
} function formatFull(time) {
// The returned value will not be user-facing. So no need for
function convert(time, oldSpeed, newSpeed) { // internationalization.
return (time * oldSpeed / newSpeed).toFixed(3); return format(time, true);
} }
function _pad(number) { function convert(time, oldSpeed, newSpeed) {
if (number < 10) { return (time * oldSpeed / newSpeed).toFixed(3);
return '0' + number; }
} else {
return '' + number; function _pad(number) {
} if (number < 10) {
} return '0' + number;
}).call(this); } else {
return '' + number;
}
}
}).call(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment