|
10 | 10 | use Magento\Framework\App\ObjectManager; |
11 | 11 | use Magento\Framework\Json\EncoderInterface; |
12 | 12 | use Magento\Framework\Locale\Bundle\DataBundle; |
| 13 | +use Magento\Framework\Locale\Resolver; |
13 | 14 | use Magento\Framework\Locale\ResolverInterface; |
14 | 15 |
|
15 | 16 | /** |
@@ -468,32 +469,27 @@ private function setTwoMonthPlaces(string $format): string |
468 | 469 | /** |
469 | 470 | * Normalize the dob for a proper output on the frontend |
470 | 471 | * |
| 472 | + * Converts localized date format (with potentially localized numerals like Arabic) to standard numerals |
| 473 | + * |
471 | 474 | * @param bool|string|null $value |
472 | 475 | * @return bool|string |
473 | 476 | */ |
474 | 477 | private function normalizedDobOutput(bool|string|null $value): bool|string |
475 | 478 | { |
476 | | - if ($value === false || $value === null) { |
477 | | - return false; |
| 479 | + if (empty($value)) { |
| 480 | + return $value; |
478 | 481 | } |
479 | 482 | $locale = $this->localeResolver->getLocale(); |
480 | 483 | $dateFormat = $this->getDateFormat(); |
481 | | - $formatter = new \IntlDateFormatter( |
482 | | - $locale, |
483 | | - \IntlDateFormatter::SHORT, |
484 | | - \IntlDateFormatter::NONE |
| 484 | + $dateTime = $this->_localeDate->date($value, $locale, false, false); |
| 485 | + |
| 486 | + return $this->_localeDate->formatDateTime( |
| 487 | + $dateTime, |
| 488 | + \IntlDateFormatter::NONE, |
| 489 | + \IntlDateFormatter::NONE, |
| 490 | + Resolver::DEFAULT_LOCALE, |
| 491 | + null, |
| 492 | + $dateFormat |
485 | 493 | ); |
486 | | - $formatter->setPattern($dateFormat); |
487 | | - $timestamp = $formatter->parse($value); |
488 | | - if ($timestamp !== false) { |
489 | | - $formatterEn = new \IntlDateFormatter( |
490 | | - 'en', |
491 | | - \IntlDateFormatter::SHORT, |
492 | | - \IntlDateFormatter::NONE |
493 | | - ); |
494 | | - $formatterEn->setPattern($dateFormat); |
495 | | - $value = $formatterEn->format($timestamp); |
496 | | - } |
497 | | - return $value; |
498 | 494 | } |
499 | 495 | } |
0 commit comments