Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2014-11-17 08:44:49 +0300
committerdiosmosis <benaka@piwik.pro>2014-11-17 08:44:49 +0300
commitc39566965b4b9371e619e11cb8346a9a11f8b246 (patch)
tree73775e7bcc6c49f08be2533d8eb8375636802af2 /core/Metrics
parentb95f7dfe78a704d760767f950f65cfadb2b3d0bf (diff)
Add unit tests for new Metrics Formatter classes and remove existing ones. Small change to Overlay included and bug fixes to metrics formatting code included.
Diffstat (limited to 'core/Metrics')
-rw-r--r--core/Metrics/Formatter.php34
1 files changed, 17 insertions, 17 deletions
diff --git a/core/Metrics/Formatter.php b/core/Metrics/Formatter.php
index ac3c6f0278..44103d7e27 100644
--- a/core/Metrics/Formatter.php
+++ b/core/Metrics/Formatter.php
@@ -23,6 +23,9 @@ use Piwik\Tracker\GoalManager;
*/
class Formatter
{
+ private $decimalPoint = null;
+ private $thousandsSeparator = null;
+
/**
* Returns a prettified string representation of a number. The result will have
* thousands separators and a decimal point specific to the current locale, eg,
@@ -31,19 +34,16 @@ class Formatter
* @param number $value
* @return string
*/
- public function getPrettyNumber($value)
+ public function getPrettyNumber($value, $precision = 0)
{
- static $decimalPoint = null;
- static $thousandsSeparator = null;
-
- if ($decimalPoint === null) {
+ if ($this->decimalPoint === null) {
$locale = localeconv();
- $decimalPoint = $locale['decimal_point'];
- $thousandsSeparator = $locale['thousands_sep'];
+ $this->decimalPoint = $locale['decimal_point'];
+ $this->thousandsSeparator = $locale['thousands_sep'];
}
- return number_format($value, 0, $decimalPoint, $thousandsSeparator);
+ return number_format($value, $precision, $this->decimalPoint, $this->thousandsSeparator);
}
/**
@@ -51,7 +51,6 @@ class Formatter
*
* @param int $numberOfSeconds The number of seconds.
* @param bool $displayTimeAsSentence If set to true, will output `"5min 17s"`, if false `"00:05:17"`.
- * @param bool $isHtml If true, replaces all spaces with `'&nbsp;'`.
* @param bool $round Whether to round to the nearest second or not.
* @return string
*/
@@ -132,8 +131,8 @@ class Formatter
$units = array('B', 'K', 'M', 'G', 'T');
$currentUnit = null;
- foreach ($units as $currentUnit) {
- if ($size >= 1024 && $unit != $currentUnit) {
+ foreach ($units as $idx => $currentUnit) {
+ if ($size >= 1024 && $unit != $currentUnit && $idx != count($units) - 1) {
$size = $size / 1024;
} else {
break;
@@ -148,22 +147,23 @@ class Formatter
*
* @param int|string $value The monetary value to format.
* @param int $idSite The ID of the site whose currency will be used.
- * @param bool $isHtml If true, replaces all spaces with `'&nbsp;'`.
* @return string
*/
public function getPrettyMoney($value, $idSite)
{
- $currencyBefore = self::getCurrencySymbol($idSite);
-
$space = ' ';
+ $currencySymbol = self::getCurrencySymbol($idSite);
+
+ $currencyBefore = $currencySymbol . $space;
$currencyAfter = '';
+
// (maybe more currencies prefer this notation?)
$currencySymbolToAppend = array('€', 'kr', 'zł');
// manually put the currency symbol after the amount
- if (in_array($currencyBefore, $currencySymbolToAppend)) {
- $currencyAfter = $space . $currencyBefore;
+ if (in_array($currencySymbol, $currencySymbolToAppend)) {
+ $currencyAfter = $space . $currencySymbol;
$currencyBefore = '';
}
@@ -179,7 +179,7 @@ class Formatter
}
}
- $prettyMoney = $currencyBefore . $space . $value . $currencyAfter;
+ $prettyMoney = $currencyBefore . $value . $currencyAfter;
return $prettyMoney;
}