|
|
@ -178,19 +178,59 @@ DataStep.prototype.previous = function() { |
|
|
|
* Get the current datetime |
|
|
|
* @return {String} current The current date |
|
|
|
*/ |
|
|
|
DataStep.prototype.getCurrent = function() { |
|
|
|
DataStep.prototype.getCurrent = function(decimals) { |
|
|
|
var toPrecision = '' + Number(this.current).toPrecision(5); |
|
|
|
if (toPrecision.indexOf(",") != -1 || toPrecision.indexOf(".") != -1) { |
|
|
|
for (var i = toPrecision.length-1; i > 0; i--) { |
|
|
|
if (toPrecision[i] == "0") { |
|
|
|
toPrecision = toPrecision.slice(0,i); |
|
|
|
// If decimals is specified, then limit or extend the string as required
|
|
|
|
if(decimals !== undefined && !isNaN(Number(decimals))) { |
|
|
|
// If string includes exponent, then we need to add it to the end
|
|
|
|
var exp = ""; |
|
|
|
var index = toPrecision.indexOf("e"); |
|
|
|
if(index != -1) { |
|
|
|
// Get the exponent
|
|
|
|
exp = toPrecision.slice(index); |
|
|
|
// Remove the exponent in case we need to zero-extend
|
|
|
|
toPrecision = toPrecision.slice(0, index); |
|
|
|
} |
|
|
|
index = Math.max(toPrecision.indexOf(","), toPrecision.indexOf(".")); |
|
|
|
if(index === -1) { |
|
|
|
// No decimal found - if we want decimals, then we need to add it
|
|
|
|
if(decimals !== 0) { |
|
|
|
toPrecision += '.'; |
|
|
|
} |
|
|
|
else if (toPrecision[i] == "." || toPrecision[i] == ",") { |
|
|
|
toPrecision = toPrecision.slice(0,i); |
|
|
|
break; |
|
|
|
// Calculate how long the string should be
|
|
|
|
index = toPrecision.length + decimals; |
|
|
|
} |
|
|
|
else if(decimals !== 0) { |
|
|
|
// Calculate how long the string should be - accounting for the decimal place
|
|
|
|
index += decimals + 1; |
|
|
|
} |
|
|
|
if(index > toPrecision.length) { |
|
|
|
// We need to add zeros!
|
|
|
|
for(var cnt = index - toPrecision.length; cnt > 0; cnt--) { |
|
|
|
toPrecision += '0'; |
|
|
|
} |
|
|
|
else{ |
|
|
|
break; |
|
|
|
} |
|
|
|
else { |
|
|
|
// we need to remove characters
|
|
|
|
toPrecision = toPrecision.slice(0, index); |
|
|
|
} |
|
|
|
// Add the exponent if there is one
|
|
|
|
toPrecision += exp; |
|
|
|
} |
|
|
|
else { |
|
|
|
if (toPrecision.indexOf(",") != -1 || toPrecision.indexOf(".") != -1) { |
|
|
|
// If no decimal is specified, and there are decimal places, remove trailing zeros
|
|
|
|
for (var i = toPrecision.length - 1; i > 0; i--) { |
|
|
|
if (toPrecision[i] == "0") { |
|
|
|
toPrecision = toPrecision.slice(0, i); |
|
|
|
} |
|
|
|
else if (toPrecision[i] == "." || toPrecision[i] == ",") { |
|
|
|
toPrecision = toPrecision.slice(0, i); |
|
|
|
break; |
|
|
|
} |
|
|
|
else { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|