Files
oficial/app/src/Service/Format.php

37 lines
1.1 KiB
PHP
Raw Normal View History

<?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, ',', '.');
}
2024-01-18 16:41:16 -03:00
public function percent(float|string $number, int $decimal_places = 2): string
{
return "{$this->number($number, $decimal_places)}%";
}
2024-02-13 01:16:17 -03:00
public function pesos(string $valor, int $decimal_places = 0): string
{
2024-02-13 01:16:17 -03:00
return "$ {$this->number($valor, $decimal_places)}";
}
2024-02-13 01:16:17 -03:00
public function ufs(string $valor, int $decimal_places = 2): string
{
2024-02-13 01:16:17 -03:00
return "{$this->number($valor, $decimal_places)} UF";
}
}