/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { if ($data = $row->getData($this->getColumn()->getIndex())) { return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($data)), $this->_getFormat()); } return $this->getColumn()->getDefault(); }
/** * Format given time [+ date] in current locale without changing timezone * * @param string $time * @param string $date * @return string */ public function formatDeliveryTime($time, $date = null) { if (!empty($date)) { $time = $date . ' ' . $time; } $format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT); return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($time)), $format); }
/** * @param string|null $index * @return string */ public function getEscapedValue($index = null) { $value = $this->getValue($index); if ($value instanceof \DateTime) { return $this->dateTimeFormatter->formatObject($value, $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)); } return $value; }
/** * Renders grid column * * @param \Magento\Framework\DataObject $row * @return string */ public function render(\Magento\Framework\DataObject $row) { if ($data = $row->getData($this->getColumn()->getIndex())) { $timezone = $this->getColumn()->getTimezone() !== false ? $this->_localeDate->getConfigTimezone() : 'UTC'; return $this->dateTimeFormatter->formatObject($this->_localeDate->date(new \DateTime($data, new \DateTimeZone($timezone))), $this->_getFormat()); } return $this->getColumn()->getDefault(); }
/** * Add refresh statistics links * * @param string $flagCode * @param string $refreshCode * @return $this */ protected function _showLastExecutionTime($flagCode, $refreshCode) { $flag = $this->_objectManager->create('Magento\\Reports\\Model\\Flag')->setReportFlagCode($flagCode)->loadSelf(); $updatedAt = 'undefined'; if ($flag->hasData()) { $updatedAt = $this->dateTimeFormatter->formatObject($this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->scopeDate(0, $flag->getLastUpdate(), true)); } $refreshStatsLink = $this->getUrl('reports/report_statistics'); $directRefreshLink = $this->getUrl('reports/report_statistics/refreshRecent', ['code' => $refreshCode]); $this->messageManager->addNotice(__('Last updated: %1. To refresh last day\'s <a href="%2">statistics</a>, ' . 'click <a href="%3">here</a>.', $updatedAt, $refreshStatsLink, $directRefreshLink)); return $this; }
public function testDateIsRenderedIndependentOfSystemDefaultLocale() { $locale = 'en_US'; $result = 'Jun 25, 2014'; \Locale::setDefault('de_DE'); $this->mockGridDateRendererBehaviorWithLocale($locale); $this->mockGridDateColumnConfig('period', 'day'); $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->setMethods(['getData'])->getMock(); $objectMock->expects($this->any())->method('getData')->willReturn('2014-06-25'); $this->dateTimeFormatter->expects($this->once())->method('formatObject')->with($this->isInstanceOf('DateTime'), $this->isType('string'), $locale)->willReturn($result); $this->assertEquals($result, $this->date->render($objectMock)); }
/** * Prepare data for save * * @return $this * @throws LocalizedException * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function beforeSave() { // prevent overriding product data if (isset($this->_data['attribute_code']) && $this->reservedAttributeList->isReservedAttribute($this)) { throw new LocalizedException(__('The attribute code \'%1\' is reserved by system. Please try another attribute code', $this->_data['attribute_code'])); } /** * Check for maximum attribute_code length */ if (isset($this->_data['attribute_code']) && !\Zend_Validate::is($this->_data['attribute_code'], 'StringLength', ['max' => self::ATTRIBUTE_CODE_MAX_LENGTH])) { throw new LocalizedException(__('An attribute code must be fewer than %1 characters.', self::ATTRIBUTE_CODE_MAX_LENGTH)); } $defaultValue = $this->getDefaultValue(); $hasDefaultValue = (string) $defaultValue != ''; if ($this->getBackendType() == 'decimal' && $hasDefaultValue) { $numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL); $defaultValue = $numberFormatter->parse($defaultValue); if ($defaultValue === false) { throw new LocalizedException(__('Invalid default decimal value')); } $this->setDefaultValue($defaultValue); } if ($this->getBackendType() == 'datetime') { if (!$this->getBackendModel()) { $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\Datetime'); } if (!$this->getFrontendModel()) { $this->setFrontendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\Datetime'); } // save default date value as timestamp if ($hasDefaultValue) { $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); try { $defaultValue = $this->dateTimeFormatter->formatObject(new \DateTime($defaultValue), $format); $this->setDefaultValue($defaultValue); } catch (\Exception $e) { throw new LocalizedException(__('Invalid default date')); } } } if ($this->getBackendType() == 'gallery') { if (!$this->getBackendModel()) { $this->setBackendModel('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\DefaultBackend'); } } return parent::beforeSave(); }
/** * @param AbstractElement $element * @return string */ protected function _getElementHtml(AbstractElement $element) { $element->setValue($this->_cache->load('admin_notifications_lastcheck')); $format = $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::MEDIUM); return $this->dateTimeFormatter->formatObject($this->_localeDate->date(intval($element->getValue())), $format); }
/** * @param AbstractElement $element * @return string * @codeCoverageIgnore */ protected function _getElementHtml(AbstractElement $element) { return $this->dateTimeFormatter->formatObject($this->_localeDate->date(intval($element->getValue())), $this->_localeDate->getDateTimeFormat(\IntlDateFormatter::MEDIUM)); }