Skip to content

Commit

Permalink
feat(formatter)!: time()/date()/datetime() will accept only `st…
Browse files Browse the repository at this point in the history
…ring` as `$format` name.
  • Loading branch information
LastDragon-ru committed Jan 1, 2024
1 parent 9bc90af commit 5612367
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions packages/formatter/src/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,23 +340,23 @@ public function duration(DateInterval|float|int|null $value, string $format = nu

public function time(
?DateTimeInterface $value,
string|int $format = null,
string $format = null,
IntlTimeZone|DateTimeZone|string $timezone = null,
): string {
return $this->formatDateTime(self::Time, $value, $format, $timezone);
}

public function date(
?DateTimeInterface $value,
string|int $format = null,
string $format = null,
IntlTimeZone|DateTimeZone|string $timezone = null,
): string {
return $this->formatDateTime(self::Date, $value, $format, $timezone);
}

public function datetime(
?DateTimeInterface $value,
string|int $format = null,
string $format = null,
IntlTimeZone|DateTimeZone|string $timezone = null,
): string {
return $this->formatDateTime(self::DateTime, $value, $format, $timezone);
Expand Down Expand Up @@ -501,7 +501,7 @@ protected function formatValue(
protected function formatDateTime(
string $type,
?DateTimeInterface $value,
string|int $format = null,
string $format = null,
IntlTimeZone|DateTimeZone|string $timezone = null,
): string {
if (is_null($value)) {
Expand Down Expand Up @@ -548,10 +548,7 @@ protected function formatFilesize(string|float|int|null $bytes, int $decimals, i

// <editor-fold desc="Internal">
// =========================================================================
private function getIntlDateFormatter(
string $type,
string|int $format = null,
): IntlDateFormatter {
private function getIntlDateFormatter(string $type, string $format = null): IntlDateFormatter {
$key = json_encode([$type, $format], JSON_THROW_ON_ERROR);
$formatter = $this->dateFormatters[$key] ?? $this->createIntlDateFormatter($type, $format);

Expand All @@ -564,10 +561,7 @@ private function getIntlDateFormatter(
return $formatter;
}

private function createIntlDateFormatter(
string $type,
string|int $format = null,
): ?IntlDateFormatter {
private function createIntlDateFormatter(string $type, string $format = null): ?IntlDateFormatter {
$formatter = null;
$pattern = '';
$default = IntlDateFormatter::SHORT;
Expand Down

0 comments on commit 5612367

Please sign in to comment.