File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ var s = 1000;
66var m = s * 60 ;
77var h = m * 60 ;
88var d = h * 24 ;
9+ var w = d * 7 ;
910var y = d * 365.25 ;
1011
1112/**
@@ -49,7 +50,7 @@ function parse(str) {
4950 if ( str . length > 100 ) {
5051 return ;
5152 }
52- var match = / ^ ( (?: \d + ) ? \. ? \d + ) * ( m i l l i s e c o n d s ? | m s e c s ? | m s | s e c o n d s ? | s e c s ? | s | m i n u t e s ? | m i n s ? | m | h o u r s ? | h r s ? | h | d a y s ? | d | y e a r s ? | y r s ? | y ) ? $ / i. exec (
53+ var match = / ^ ( (?: \d + ) ? \. ? \d + ) * ( m i l l i s e c o n d s ? | m s e c s ? | m s | s e c o n d s ? | s e c s ? | s | m i n u t e s ? | m i n s ? | m | h o u r s ? | h r s ? | h | d a y s ? | d | w e e k s ? | w | y e a r s ? | y r s ? | y ) ? $ / i. exec (
5354 str
5455 ) ;
5556 if ( ! match ) {
@@ -64,6 +65,10 @@ function parse(str) {
6465 case 'yr' :
6566 case 'y' :
6667 return n * y ;
68+ case 'weeks' :
69+ case 'week' :
70+ case 'w' :
71+ return n * w ;
6772 case 'days' :
6873 case 'day' :
6974 case 'd' :
@@ -130,11 +135,13 @@ function fmtShort(ms) {
130135 */
131136
132137function fmtLong ( ms ) {
133- return plural ( ms , d , 'day' ) ||
138+ return (
139+ plural ( ms , d , 'day' ) ||
134140 plural ( ms , h , 'hour' ) ||
135141 plural ( ms , m , 'minute' ) ||
136142 plural ( ms , s , 'second' ) ||
137- ms + ' ms' ;
143+ ms + ' ms'
144+ ) ;
138145}
139146
140147/**
Original file line number Diff line number Diff line change @@ -33,6 +33,10 @@ describe('ms(string)', function() {
3333 expect ( ms ( '2d' ) ) . to . be ( 172800000 ) ;
3434 } ) ;
3535
36+ it ( 'should convert w to ms' , function ( ) {
37+ expect ( ms ( '3w' ) ) . to . be ( 1814400000 ) ;
38+ } ) ;
39+
3640 it ( 'should convert s to ms' , function ( ) {
3741 expect ( ms ( '1s' ) ) . to . be ( 1000 ) ;
3842 } ) ;
You can’t perform that action at this time.
0 commit comments