diff --git a/lib/utils/monkey-patches.js b/lib/utils/monkey-patches.js index 69bf24b..4927cc7 100644 --- a/lib/utils/monkey-patches.js +++ b/lib/utils/monkey-patches.js @@ -24,7 +24,30 @@ module.exports.uninstall = function() { module.exports.install = function() { /** - * Multiplies a number by 1000 to get time in milliseconds + * Multiplies a number by 60000 to convert minutes + * to milliseconds + * + * @example + * (2).minutes(); //=> 120000 + * @return {Number} time in milliseconds + */ + Number.prototype.minutes = function() { + return this * 60000; + }; + + /** + * Alias for Number.prototype.minutes + * + * @see Number.prototype.minute + * @example + * (1).minute(); //=>60000 + * @return {Number} time in milliseconds + */ + Number.prototype.minute = Number.prototype.minutes; + + /** + * Multiplies a number by 1000 to convert seconds + * to milliseconds * * @example * (2).seconds(); //=> 2000 @@ -66,7 +89,9 @@ module.exports.install = function() { Number.prototype.ms = Number.prototype.milliseconds; /** - * Divides a number by 1000 to get time in microseconds + * Converts microseconds to milliseconds. + * Note that timing of events in terms of microseconds + * is not very accurate in JS. * * @example * (2000).microseconds(); //=> 2 diff --git a/spec/lib/utils/monkey-patches.spec.js b/spec/lib/utils/monkey-patches.spec.js index 57db358..46c9137 100644 --- a/spec/lib/utils/monkey-patches.spec.js +++ b/spec/lib/utils/monkey-patches.spec.js @@ -77,6 +77,18 @@ describe("monkey-patches", function() { }); }); + describe("#minutes", function() { + it("allows for expressing time in minutes", function() { + expect((5).minutes()).to.be.eql(300000); + }); + }); + + describe("#minute", function() { + it("allows for expressing time per minute", function() { + expect((1).minute()).to.be.eql(60000); + }); + }); + describe("#fromScale", function() { it("converts a value from one scale to 0-1 scale", function() { expect((5).fromScale(0, 10)).to.be.eql(0.5);