diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 38099f035d..f27c08a853 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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. diff --git a/common/lib/xmodule/xmodule/js/spec/time_spec.js b/common/lib/xmodule/xmodule/js/spec/time_spec.js index 55a98ebb72..1941d09959 100644 --- a/common/lib/xmodule/xmodule/js/spec/time_spec.js +++ b/common/lib/xmodule/xmodule/js/spec/time_spec.js @@ -1,50 +1,57 @@ -(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); diff --git a/common/lib/xmodule/xmodule/js/src/time.js b/common/lib/xmodule/xmodule/js/src/time.js index 464d06ed5f..b4ccb6652c 100644 --- a/common/lib/xmodule/xmodule/js/src/time.js +++ b/common/lib/xmodule/xmodule/js/src/time.js @@ -1,47 +1,51 @@ -(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);