/** * {@inheritdoc} */ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null) { if (!$scope instanceof \Magento\Framework\App\ScopeInterface) { $scope = $this->_scopeResolver->getScope($scope); } $scopeTimeStamp = $this->scopeTimeStamp($scope); $fromTimeStamp = strtotime($dateFrom); $toTimeStamp = strtotime($dateTo); if ($dateTo) { // fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59 $toTimeStamp += 86400; } $result = false; if (!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp) { } elseif (!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp) { } else { $result = true; } return $result; }
/** * Retrieve Date value for store * * @param int $storeId * @param string $date * @return string|null */ protected function getStoreDate($storeId, $date = null) { if (!isset($this->dates[$storeId])) { $timezone = $this->scopeConfig->getValue($this->localeDate->getDefaultTimezonePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $this->localeResolver->emulate($storeId); $dateObj = new \DateTime(); $dateObj->setTimezone(new \DateTimeZone($timezone)); $this->dates[$storeId] = $dateObj; $this->localeResolver->revert(); } if (!$this->dateTime->isEmptyDate($date)) { /** @var \DateTime $dateObj */ $dateObj = $this->dates[$storeId]; return $this->localeDate->formatDateTime($dateObj, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE); } return null; }
/** * Retrieve Date value for store * * @param int $storeId * @param string $date * @return string|null */ protected function getStoreDate($storeId, $date = null) { if (!isset($this->dates[$storeId])) { $timezone = $this->scopeConfig->getValue($this->localeDate->getDefaultTimezonePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $locale = $this->scopeConfig->getValue($this->localeResolver->getDefaultLocalePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); $locale = new \Zend_Locale($locale); $dateObj = new \Magento\Framework\Stdlib\DateTime\Date(null, null, $locale); $dateObj->setTimezone($timezone); $this->dates[$storeId] = [$dateObj, $locale->getTranslation(null, 'date', $locale)]; } if (!$this->dateTime->isEmptyDate($date)) { list($dateObj, $format) = $this->dates[$storeId]; $dateObj->setDate($date, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); return $dateObj->toString($format); } return null; }
/** * @param string $date * @param bool $expected * * @dataProvider isEmptyDateDataProvider */ public function testIsEmptyDate($date, $expected) { $actual = $this->_dateTime->isEmptyDate($date); $this->assertEquals($actual, $expected); }