diff --git a/README.md b/README.md index d8e634a..abdb2ea 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # millisecond -[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/millisecond)[![Build Status][build]](https://travis-ci.org/unshiftio/millisecond)[![Dependencies][david]](https://david-dm.org/unshiftio/millisecond)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/millisecond?branch=master)[![IRC channel][irc]](http://webchat.freenode.net/?channels=unshift) +[![Made by unshift][made-by]](http://unshift.io)[![Version npm][version]](http://browsenpm.org/package/millisecond)[![Build Status][build]](https://travis-ci.org/unshiftio/millisecond)[![Dependencies][david]](https://david-dm.org/unshiftio/millisecond)[![Coverage Status][cover]](https://coveralls.io/r/unshiftio/millisecond?branch=master)[![IRC channel][irc]](https://webchat.freenode.net/?channels=unshift) [made-by]: https://img.shields.io/badge/made%20by-unshift-00ffcc.svg?style=flat-square -[version]: http://img.shields.io/npm/v/millisecond.svg?style=flat-square -[build]: http://img.shields.io/travis/unshiftio/millisecond/master.svg?style=flat-square +[version]: https://img.shields.io/npm/v/millisecond.svg?style=flat-square +[build]: https://img.shields.io/travis/unshiftio/millisecond/master.svg?style=flat-square [david]: https://img.shields.io/david/unshiftio/millisecond.svg?style=flat-square -[cover]: http://img.shields.io/coveralls/unshiftio/millisecond/master.svg?style=flat-square -[irc]: http://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square +[cover]: https://img.shields.io/coveralls/unshiftio/millisecond/master.svg?style=flat-square +[irc]: https://img.shields.io/badge/IRC-irc.freenode.net%23unshift-00a8ff.svg?style=flat-square Parse strings that indicate a time to their millisecond equivalents. @@ -65,6 +65,11 @@ It understands the following strings: - `x days` - `x day` - `x d` +- `x weeks` +- `x week` +- `x wks` +- `x wk` +- `x w` - `x years` - `x year` - `x yrs` diff --git a/index.js b/index.js index ff1036f..9a1743c 100644 --- a/index.js +++ b/index.js @@ -10,11 +10,12 @@ module.exports = function millisecond(ms) { if ('string' !== typeof ms || '0' === ms || +ms) return +ms; - var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(ms) + var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|wks?|w|years?|yrs?|y)?$/i.exec(ms) , second = 1000 , minute = second * 60 , hour = minute * 60 , day = hour * 24 + , week = day * 7 , year = day * 365 , amount; @@ -30,6 +31,13 @@ module.exports = function millisecond(ms) { case 'y': return amount * year; + case 'weeks': + case 'week': + case 'wks': + case 'wk': + case 'w': + return amount * week; + case 'days': case 'day': case 'd': diff --git a/test.js b/test.js index 0f4d324..f0b69ca 100644 --- a/test.js +++ b/test.js @@ -49,6 +49,14 @@ describe('millisecond', function () { assume(ms('2days')).to.equal(172800000); }); + it('should convert w to ms', function () { + assume(ms('1w')).to.equal(604800000); + assume(ms('1wk')).to.equal(604800000); + assume(ms('1wks')).to.equal(604800000); + assume(ms('1week')).to.equal(604800000); + assume(ms('1weeks')).to.equal(604800000); + }); + it('should convert y to ms', function () { assume(ms('1y')).to.equal(31536000000); assume(ms('1yr')).to.equal(31536000000);