Actualizaciones en Format

This commit is contained in:
Juan Pablo Vial
2025-04-03 13:37:41 -03:00
parent 4d6a1827a3
commit 74a2cf7303

View File

@ -6,12 +6,12 @@ use IntlDateFormatter;
class Format class Format
{ {
public function localDate(string $valor, string $format, bool $print = false): string public function localDate(string $valor, ?string $format = null, bool $print = false): string
{ {
$date = new DateTimeImmutable($valor); $date = new DateTimeImmutable($valor);
$formatter = new IntlDateFormatter('es_ES'); $formatter = new IntlDateFormatter('es_ES');
if ($format == null) { if ($format == null) {
$format = 'DD [de] MMMM [de] YYYY'; $format = "dd 'de' MMMM 'de' YYYY";
} }
$formatter->setPattern($format); $formatter->setPattern($format);
return $formatter->format($date); return $formatter->format($date);
@ -21,9 +21,9 @@ class Format
{ {
return number_format($number, $decimal_places, ',', '.'); return number_format($number, $decimal_places, ',', '.');
} }
public function percent(float|string $number, int $decimal_places = 2): string public function percent(float|string $number, int $decimal_places = 2, bool $multiply = false): string
{ {
return "{$this->number($number, $decimal_places)}%"; return "{$this->number(($multiply) ? $number * 100 : $number, $decimal_places)}%";
} }
public function pesos(string $valor, int $decimal_places = 0): string public function pesos(string $valor, int $decimal_places = 0): string
{ {