config
This commit is contained in:
11
app_old/aldarien/format/.gitignore
vendored
Normal file
11
app_old/aldarien/format/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
composer.phar
|
||||
/vendor/
|
||||
|
||||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
|
||||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
|
||||
# composer.lock
|
||||
|
||||
# Eclipse IDE
|
||||
.settings
|
||||
.buildpath
|
||||
.project
|
21
app_old/aldarien/format/LICENSE
Normal file
21
app_old/aldarien/format/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Aldarien
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
2
app_old/aldarien/format/README.md
Normal file
2
app_old/aldarien/format/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
# format
|
||||
Module for formatting data, mostly numbers
|
43
app_old/aldarien/format/app/Helper/Format.php
Normal file
43
app_old/aldarien/format/app/Helper/Format.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace App\Helper;
|
||||
|
||||
class Format
|
||||
{
|
||||
public static function number(float $number, $decimals)
|
||||
{
|
||||
return number_format($number, $decimals, ',', '.');
|
||||
}
|
||||
public static function pesos(float $number, bool $print = false)
|
||||
{
|
||||
return (($print) ? '$ ' : '') . self::number($number, 0);
|
||||
}
|
||||
public static function ufs(float $number, bool $print = false)
|
||||
{
|
||||
return self::number($number, 2) . (($print) ? ' UF' : '');
|
||||
}
|
||||
public static function date(string $date)
|
||||
{
|
||||
$d = \Carbon\Carbon::parse($date, config('app.timezone'));
|
||||
return $d->format("d \d\\e F Y");
|
||||
}
|
||||
public static function shortDate(string $date)
|
||||
{
|
||||
$d = \Carbon\Carbon::parse($date, config('app.timezone'));
|
||||
return $d->format('d-m-Y');
|
||||
}
|
||||
public static function localDate(string $date)
|
||||
{
|
||||
$d = \Carbon\Carbon::parse($date, config('app.timezone'));
|
||||
setlocale(LC_TIME, 'es');
|
||||
return $d->formatLocalized('%d de %B de %Y');
|
||||
}
|
||||
public static function m2(float $number, bool $print = false)
|
||||
{
|
||||
return self::number($number, 2) . (($print) ? ' m²' : '');
|
||||
}
|
||||
public static function percent(float $number, bool $print = false)
|
||||
{
|
||||
return self::number($number, 2) . (($print) ? '%' : '');
|
||||
}
|
||||
}
|
||||
?>
|
23
app_old/aldarien/format/composer.json
Normal file
23
app_old/aldarien/format/composer.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name" : "aldarien/format",
|
||||
"description" : "Module for formatting data, mostly numbers",
|
||||
"type" : "library",
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit" : "*",
|
||||
"aldarien/config": "*"
|
||||
},
|
||||
"license" : "MIT",
|
||||
"authors" : [{
|
||||
"name" : "Aldarien",
|
||||
"email" : "aldarien85@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload" : {
|
||||
"psr-4" : {
|
||||
"App\\" : "app"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"nesbot/carbon": "^2"
|
||||
}
|
||||
}
|
5
app_old/aldarien/format/config/app.php
Normal file
5
app_old/aldarien/format/config/app.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'timezone' => 'America/Santiago'
|
||||
];
|
||||
?>
|
17
app_old/aldarien/format/phpunit.xml
Normal file
17
app_old/aldarien/format/phpunit.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
colors="true"
|
||||
verbose="true"
|
||||
bootstrap="./vendor/autoload.php"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Application Test Suite">
|
||||
<directory>./tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory>./app</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
59
app_old/aldarien/format/tests/FormatTest.php
Normal file
59
app_old/aldarien/format/tests/FormatTest.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Helper\Format;
|
||||
|
||||
class FormatTest extends TestCase
|
||||
{
|
||||
protected $number = 5049872.31567;
|
||||
protected $date = '2016-03-25';
|
||||
|
||||
public function testFormat()
|
||||
{
|
||||
$output = '5.049.872,316';
|
||||
$result = Format::number($this->number, 3);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testPesosPrint()
|
||||
{
|
||||
$output = '$ 5.049.872';
|
||||
$result = Format::pesos($this->number, true);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testUFPrint()
|
||||
{
|
||||
$output = '5.049.872,32 UF';
|
||||
$result = Format::ufs($this->number, true);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testDate()
|
||||
{
|
||||
$output = '25 de March 2016';
|
||||
$result = Format::date($this->date);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testShortDate()
|
||||
{
|
||||
$output = '25-03-2016';
|
||||
$result = Format::shortDate($this->date);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testLocalDate()
|
||||
{
|
||||
$output = '25 de marzo de 2016';
|
||||
$result = Format::localDate($this->date);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testM2Print()
|
||||
{
|
||||
$output = '5.049.872,32 m²';
|
||||
$result = Format::m2($this->number, true);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
public function testPercentPrint()
|
||||
{
|
||||
$output = '5.049.872,32%';
|
||||
$result = Format::percent($this->number, true);
|
||||
$this->assertEquals($output, $result);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user