33 lines
848 B
PHP
33 lines
848 B
PHP
<?php
|
|
namespace Incoviba\Service;
|
|
|
|
use DateTimeImmutable;
|
|
use IntlDateFormatter;
|
|
|
|
class Format
|
|
{
|
|
public function localDate(string $valor, string $format, bool $print = false): string
|
|
{
|
|
$date = new DateTimeImmutable($valor);
|
|
$formatter = new IntlDateFormatter('es_ES');
|
|
if ($format == null) {
|
|
$format = 'DD [de] MMMM [de] YYYY';
|
|
}
|
|
$formatter->setPattern($format);
|
|
return $formatter->format($date);
|
|
|
|
}
|
|
public function number(float|string $number, int $decimal_places = 0): string
|
|
{
|
|
return number_format($number, $decimal_places, ',', '.');
|
|
}
|
|
public function pesos(string $valor): string
|
|
{
|
|
return '$ ' . $this->number($valor);
|
|
}
|
|
public function ufs(string $valor): string
|
|
{
|
|
return $this->number($valor, 2) . ' UF';
|
|
}
|
|
}
|