Permalink
Browse files

Rewrote the part that handled decimal part slicing and fitting into f…

…ormat, now working in every test case
  • Loading branch information...
therazor committed Jun 7, 2012
1 parent e5f7d06 commit e9a400014706ca796511587d1707278fe7f15bc7
Showing with 5 additions and 6 deletions.
  1. +5 −6 lib/globalize.js
View
@@ -969,21 +969,20 @@ formatDate = function( value, format, culture ) {
}
var curFragment,
- curDecimalPlaces = decimalsLengthRange[1],
- minDecimalPlaces = decimalPlaces,
+ decimalPlacesGap = decimalsLengthRange[1] - decimalPlaces,
curIntLength = 0;
for ( i = subpatterns.length - 1; i > 0; i-- ) {
if ( i > decimalsSeparatorIndex && formattedIntDec.length > 1 ) { // decimal part
var sliceLength = subpatterns[i].length - ( subpatterns[i].lastIndexOf( '.' ) + 1 );
- curFragment = formattedIntDec[1].substring( formattedIntDec[1].length +
- curDecimalPlaces - minDecimalPlaces - 1 );
+ curFragment = formattedIntDec[1].substring( formattedIntDec[1].length -
+ Math.max( sliceLength - decimalPlacesGap, 0 ) );
formattedIntDec[1] = formattedIntDec[1].slice( 0,
formattedIntDec[1].length - curFragment.length );
- curDecimalPlaces -= sliceLength;
- minDecimalPlaces -= curFragment.length;
+ if( decimalPlacesGap )
+ decimalPlacesGap -= sliceLength - curFragment.length;
}
if ( i <= decimalsSeparatorIndex || !~decimalsSeparatorIndex ) { // int part
var sliceLength = subpatterns[i].indexOf( '.' );

0 comments on commit e9a4000

Please sign in to comment.