@@ -2,8 +2,8 @@ const _ = require('underscore');
22const moment = require ( 'moment' ) ;
33
44const defaultTimeFormat = '[%sign][%days>d ][%hours>h ][%minutes>m ][%seconds>s]' ;
5- const mappings = [ 'complete' , 'sign' , 'weeks' , 'days' , 'hours' , 'minutes' , 'seconds' ] ;
6- const regex = / ^ (?: ( [ - ] ) \s * ) ? (?: ( \d + ) w \s * ) ? (?: ( \d + ) d \s * ) ? (?: ( \d + ) h \s * ) ? (?: ( \d + ) m \s * ) ? (?: ( \d + ) s \s * ) ? $ / ;
5+ const mappings = [ 'complete' , 'sign' , 'months' , ' weeks', 'days' , 'hours' , 'minutes' , 'seconds' ] ;
6+ const regex = / ^ (?: ( [ - ] ) \s * ) ? (?: ( \d + ) m o \s * ) ? (?: ( \d + ) w \s * ) ? (?: ( \d + ) d \s * ) ? (?: ( \d + ) h \s * ) ? (?: ( \d + ) m \s * ) ? (?: ( \d + ) s \s * ) ? $ / ;
77const conditionalRegex = / ( \[ \% ( [ ^ \> \] ] * ) \> ( [ ^ \] ] * ) \] ) / ig;
88const roundedRegex = / ( \[ \% ( [ ^ \> \] ] * ) \: ( [ ^ \] ] * ) \] ) / ig;
99const conditionalSimpleRegex = / ( [ 0 - 9 ] * ) \> ( .* ) / ig;
@@ -29,7 +29,7 @@ class time {
2929 this . _date = date ;
3030 this . parent = parent ;
3131 this . config = config ;
32- this . seconds = time . parse ( timeString , this . _hoursPerDay ) ;
32+ this . seconds = time . parse ( timeString , this . _hoursPerDay , this . _daysPerWeek , this . _weeksPerMonth ) ;
3333 }
3434
3535 /*
@@ -71,13 +71,23 @@ class time {
7171 return this . config && this . config . get ( 'hoursPerDay' ) ? parseInt ( this . config . get ( 'hoursPerDay' ) ) : 8 ;
7272 }
7373
74+ get _daysPerWeek ( ) {
75+ return this . config && this . config . get ( 'daysPerWeek' ) ? parseInt ( this . config . get ( 'daysPerWeek' ) ) : 5 ;
76+ }
77+
78+ get _weeksPerMonth ( ) {
79+ return this . config && this . config . get ( 'weeksPerMonth' ) ? parseInt ( this . config . get ( 'weeksPerMonth' ) ) : 4 ;
80+ }
81+
7482 /**
7583 * parse human readable to seconds
7684 * @param string
7785 * @param hoursPerDay
86+ * @param daysPerWeek
87+ * @param weeksPerMonth
7888 * @returns {* }
7989 */
80- static parse ( string , hoursPerDay = 8 ) {
90+ static parse ( string , hoursPerDay = 8 , daysPerWeek = 5 , weeksPerMonth = 4 ) {
8191 let match , parsed ;
8292
8393 if ( ( match = regex . exec ( string ) ) === null ) return false ;
@@ -87,7 +97,8 @@ class time {
8797 + ( parseInt ( parsed . minutes ) * 60 )
8898 + ( parseInt ( parsed . hours ) * 60 * 60 )
8999 + ( parseInt ( parsed . days ) * hoursPerDay * 60 * 60 )
90- + ( parseInt ( parsed . weeks ) * 5 * hoursPerDay * 60 * 60 ) ) ;
100+ + ( parseInt ( parsed . weeks ) * daysPerWeek * hoursPerDay * 60 * 60 )
101+ + ( parseInt ( parsed . months ) * weeksPerMonth * daysPerWeek * hoursPerDay * 60 * 60 ) ) ;
91102 }
92103
93104 /**
0 commit comments