mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-24 14:03:16 +00:00
commit
658411f8b4
2 changed files with 35 additions and 32 deletions
|
@ -1,6 +1,8 @@
|
||||||
# Release Notes
|
# Release Notes
|
||||||
|
|
||||||
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.0...dev)
|
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.0...dev)
|
||||||
|
### Updated
|
||||||
|
- Updated PrettyNumber, fix deprecated warning. ([20ec870b](https://github.com/pixelfed/pixelfed/commit/20ec870b))
|
||||||
|
|
||||||
## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0)
|
## [v0.11.0 (2021-06-01)](https://github.com/pixelfed/pixelfed/compare/v0.10.10...v0.11.0)
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -4,40 +4,41 @@ namespace App\Util\Lexer;
|
||||||
|
|
||||||
class PrettyNumber
|
class PrettyNumber
|
||||||
{
|
{
|
||||||
public static function convert($number, $showDecimals = true)
|
public static function convert($number, $showDecimals = true)
|
||||||
{
|
{
|
||||||
if(!is_integer($number)) {
|
if(!is_integer($number)) {
|
||||||
return $number;
|
return $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
$abbrevs = [12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => ''];
|
$abbrevs = [12 => 'T', 9 => 'B', 6 => 'M', 3 => 'K', 0 => ''];
|
||||||
foreach ($abbrevs as $exponent => $abbrev) {
|
foreach ($abbrevs as $exponent => $abbrev) {
|
||||||
if(abs($number) >= pow(10, $exponent)) {
|
if(abs($number) >= pow(10, $exponent)) {
|
||||||
$display = $number / pow(10, $exponent);
|
$display = $number / pow(10, $exponent);
|
||||||
$decimals = !$showDecimals ? 0 : ($exponent >= 3 && round($display) < 100) ? 1 : 0;
|
$decimals = ($exponent >= 3 && round($display) < 100) ? 1 : 0;
|
||||||
$number = number_format($display, $decimals).$abbrev;
|
$decimals = !$showDecimals ? 0 : $decimals;
|
||||||
break;
|
$number = number_format($display, $decimals).$abbrev;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $number;
|
return $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function size($expression, $kb = false)
|
public static function size($expression, $kb = false)
|
||||||
{
|
{
|
||||||
if ($kb) {
|
if ($kb) {
|
||||||
$expression = $expression * 1024;
|
$expression = $expression * 1024;
|
||||||
}
|
}
|
||||||
$size = intval($expression);
|
$size = intval($expression);
|
||||||
$precision = 0;
|
$precision = 0;
|
||||||
$short = true;
|
$short = true;
|
||||||
$units = $short ?
|
$units = $short ?
|
||||||
['B', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] :
|
['B', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'] :
|
||||||
['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||||
for ($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) {
|
for ($i = 0; ($size / 1024) > 0.9; $i++, $size /= 1024) {
|
||||||
}
|
}
|
||||||
$res = round($size, $precision).$units[$i];
|
$res = round($size, $precision).$units[$i];
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue