diff --git a/index.js b/index.js index 6a522b1..c0f2412 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var s = 1000; var m = s * 60; var h = m * 60; var d = h * 24; +var w = d * 7; var y = d * 365.25; /** @@ -49,7 +50,7 @@ function parse(str) { if (str.length > 100) { return; } - var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec( + var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( str ); if (!match) { @@ -64,6 +65,10 @@ function parse(str) { case 'yr': case 'y': return n * y; + case 'weeks': + case 'week': + case 'w': + return n * w; case 'days': case 'day': case 'd': @@ -130,11 +135,13 @@ function fmtShort(ms) { */ function fmtLong(ms) { - return plural(ms, d, 'day') || + return ( + plural(ms, d, 'day') || plural(ms, h, 'hour') || plural(ms, m, 'minute') || plural(ms, s, 'second') || - ms + ' ms'; + ms + ' ms' + ); } /** diff --git a/tests.js b/tests.js index 9b437f4..ff0cdec 100644 --- a/tests.js +++ b/tests.js @@ -33,6 +33,10 @@ describe('ms(string)', function() { expect(ms('2d')).to.be(172800000); }); + it('should convert w to ms', function() { + expect(ms('3w')).to.be(1814400000); + }); + it('should convert s to ms', function() { expect(ms('1s')).to.be(1000); });