@@ -6,7 +6,7 @@ const mappings = ['complete', 'sign', 'weeks', 'days', 'hours', 'minutes', 'seco
66const regex = / ^ (?: ( [ - ] ) \s * ) ? (?: ( \d + ) w \s * ) ? (?: ( \d + ) d \s * ) ? (?: ( \d + ) h \s * ) ? (?: ( \d + ) m \s * ) ? (?: ( \d + ) s \s * ) ? $ / ;
77const conditionalRegex = / ( \[ \% ( [ ^ \> \] ] * ) \> ( [ ^ \] ] * ) \] ) / ig;
88const roundedRegex = / ( \[ \% ( [ ^ \> \] ] * ) \: ( [ ^ \] ] * ) \] ) / ig;
9- const conditionalSimpleRegex = / ( . * ) \> ( .* ) / ig;
9+ const conditionalSimpleRegex = / ( [ 0 - 9 ] * ) \> ( .* ) / ig;
1010const defaultRegex = / ( \[ \% ( [ ^ \] ] * ) \] ) / ig;
1111
1212Number . prototype . padLeft = function ( n , str ) {
@@ -97,7 +97,7 @@ class time {
9797 * @returns {string }
9898 */
9999 static toHumanReadable ( input , hoursPerDay = 8 , format = time . defaultTimeFormat ) {
100- let sign = parseInt ( input ) < 0 ? '-' : '' , output = format , match , conditionalMatch ;
100+ let sign = parseInt ( input ) < 0 ? '-' : '' , output = format , match ;
101101 input = Math . abs ( input ) ;
102102
103103 let secondsInADay = 60 * 60 * hoursPerDay ;
@@ -126,14 +126,15 @@ class time {
126126 // rounded
127127 while ( ( match = roundedRegex . exec ( format ) ) !== null ) {
128128 if ( match . index === roundedRegex . lastIndex ) roundedRegex . lastIndex ++ ;
129- let time ;
129+ let time , conditionalMatch , decimals = match [ 3 ] ;
130130
131- if ( ( conditionalMatch = conditionalSimpleRegex . exec ( match [ 3 ] ) ) !== null ) {
132- match [ 3 ] = conditionalMatch [ 1 ]
131+ if ( ( conditionalMatch = conditionalSimpleRegex . exec ( decimals ) ) !== null ) {
132+ decimals = conditionalMatch [ 1 ]
133133 }
134134
135- time = Math . ceil ( inserts [ match [ 2 ] ] * Math . pow ( 10 , match [ 3 ] ) ) / Math . pow ( 10 , match [ 3 ] ) ;
136- output = output . replace ( match [ 0 ] , time !== 0 && conditionalMatch ? time + conditionalMatch [ 2 ] : '' ) ;
135+ decimals = parseInt ( decimals ) ;
136+ time = Math . ceil ( inserts [ match [ 2 ] ] * Math . pow ( 10 , decimals ) ) / Math . pow ( 10 , decimals ) ;
137+ output = output . replace ( match [ 0 ] , time !== 0 && conditionalMatch ? time + conditionalMatch [ 2 ] : time ) ;
137138 }
138139
139140 // conditionals
0 commit comments