Skip to content
Permalink
Browse files

remove LocalizedNumber

  • Loading branch information...
antograssiot committed Sep 4, 2014
1 parent 85c294a commit a78d7650a7cc1d5772066a241b918a9155e06007
Showing with 103 additions and 181 deletions.
  1. +0 −50 src/I18n/LocalizedNumber.php
  2. +22 −0 src/I18n/Number.php
  3. +0 −131 tests/TestCase/I18n/LocalizedNumberTest.php
  4. +81 −0 tests/TestCase/I18n/NumberTest.php

This file was deleted.

Oops, something went wrong.
@@ -53,6 +53,28 @@ public static function precision($value, $precision = 3) {
return $formatter->format($value);
}
/**
* Returns a formatted-for-humans file size.
*
* @param int $size Size in bytes
* @return string Human readable size
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/number.html#NumberHelper::toReadableSize
*/
public static function toReadableSize($size) {
switch (true) {
case $size < 1024:
return __dn('cake', '{0,number,integer} Byte', '{0,number,integer} Bytes', $size, $size);
case round($size / 1024) < 1024:
return __d('cake', '{0,number,#,###.##} KB', $size / 1024);
case round($size / 1024 / 1024, 2) < 1024:
return __d('cake', '{0,number,#,###.##} MB', $size / 1024 / 1024);
case round($size / 1024 / 1024 / 1024, 2) < 1024:
return __d('cake', '{0,number,#,###.##} GB', $size / 1024 / 1024 / 1024);
default:
return __d('cake', '{0,number,#,###.##} TB', $size / 1024 / 1024 / 1024 / 1024);
}
}
/**
* Converts filesize from human readable string to bytes
*

This file was deleted.

Oops, something went wrong.
@@ -413,6 +413,87 @@ public function testToPercentage() {
$this->assertEquals($expected, $result);
}
/**
* testToReadableSize method
*
* @return void
*/
public function testToReadableSize() {
$result = $this->Number->toReadableSize(0);
$expected = '0 Bytes';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1);
$expected = '1 Byte';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(45);
$expected = '45 Bytes';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1023);
$expected = '1,023 Bytes';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024);
$expected = '1 KB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 + 123);
$expected = '1.12 KB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 512);
$expected = '512 KB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 - 1);
$expected = '1 MB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(512.05 * 1024 * 1024);
$expected = '512.05 MB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 * 1024 - 1);
$expected = '1 GB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 512);
$expected = '512 GB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 1024 - 1);
$expected = '1 TB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 1024 * 512);
$expected = '512 TB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 1024 * 1024 - 1);
$expected = '1,024 TB';
$this->assertEquals($expected, $result);
$result = $this->Number->toReadableSize(1024 * 1024 * 1024 * 1024 * 1024 * 1024);
$expected = '1,048,576 TB';
$this->assertEquals($expected, $result);
}
/**
* test toReadableSize() with locales
*
* @return void
*/
public function testReadableSizeLocalized() {
I18n::defaultLocale('fr_FR');
$result = $this->Number->toReadableSize(1321205);
$this->assertEquals('1,26 MB', $result);
$result = $this->Number->toReadableSize(512.05 * 1024 * 1024 * 1024);
$this->assertEquals('512,05 GB', $result);
}
/**
* testFromReadableSize
*

0 comments on commit a78d765

Please sign in to comment.
You can’t perform that action at this time.