Datetime.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Model\Entity\Attribute\Frontend;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Datetime extends \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
  12. {
  13. /**
  14. * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
  15. */
  16. protected $_localeDate;
  17. /**
  18. * @param \Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory
  19. * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  20. * @codeCoverageIgnore
  21. */
  22. public function __construct(
  23. \Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory,
  24. \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  25. ) {
  26. parent::__construct($attrBooleanFactory);
  27. $this->_localeDate = $localeDate;
  28. }
  29. /**
  30. * Retrieve attribute value
  31. *
  32. * @param \Magento\Framework\DataObject $object
  33. * @return mixed
  34. */
  35. public function getValue(\Magento\Framework\DataObject $object)
  36. {
  37. $data = '';
  38. $value = parent::getValue($object);
  39. if ($value) {
  40. $data = $this->_localeDate->formatDateTime(
  41. new \DateTime($value),
  42. \IntlDateFormatter::MEDIUM,
  43. \IntlDateFormatter::NONE
  44. );
  45. }
  46. return $data;
  47. }
  48. }