123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
- */
- namespace Temando\Shipping\ViewModel\DataProvider;
- use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
- use Magento\Framework\View\Element\Text;
- use Magento\Store\Model\ScopeInterface;
- /**
- * Order Info Date Formatter
- *
- * @package Temando\Shipping\ViewModel
- * @author Christoph Aßmann <christoph.assmann@netresearch.de>
- * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * @link https://www.temando.com/
- */
- class OrderDate implements OrderDateInterface
- {
- /**
- * @var TimezoneInterface
- */
- private $date;
- /**
- * @var Text
- */
- private $block;
- /**
- * OrderDate constructor.
- * @param TimezoneInterface $date
- * @param Text $block
- */
- public function __construct(TimezoneInterface $date, Text $block)
- {
- $this->date = $date;
- $this->block = $block;
- }
- /**
- * Create DateTime object with given date in the current locale.
- *
- * @param string $date
- * @return \DateTime
- */
- public function getDate(string $date): \DateTime
- {
- $localizedDate = $this->date->date(new \DateTime($date));
- return $localizedDate;
- }
- /**
- * Format given date in the locale configured for given store.
- *
- * @param string $date
- * @param int $storeId
- * @return string
- */
- public function getStoreDate(string $date, int $storeId): string
- {
- if (empty($date)) {
- return '';
- }
- $timezone = $this->date->getConfigTimezone(ScopeInterface::SCOPE_STORE, $storeId);
- $storeDate = $this->block->formatDate(
- $date,
- \IntlDateFormatter::MEDIUM,
- true,
- $timezone
- );
- return $storeDate;
- }
- /**
- * Format given date in the current locale.
- *
- * @param string $date
- * @return string
- */
- public function getAdminDate(string $date): string
- {
- if (empty($date)) {
- return '';
- }
- $localizedDate = $this->getDate($date);
- $adminDate = $this->block->formatDate(
- $localizedDate,
- \IntlDateFormatter::MEDIUM,
- true
- );
- return $adminDate;
- }
- /**
- * @param int $storeId
- * @return string
- */
- public function getStoreTimezone(int $storeId): string
- {
- return $this->date->getConfigTimezone(ScopeInterface::SCOPE_STORE, $storeId);
- }
- }
|