diff --git a/app/bootstrap.php b/app/bootstrap.php index b62375c317bf2ef5921bb6599fdc5906e6be2c18..f51265aee618ef7240fe5f2da9653b992cd1b964 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -35,5 +35,5 @@ if (!empty($_SERVER['MAGE_PROFILER'])) { \Magento\Framework\Profiler::applyConfig($_SERVER['MAGE_PROFILER'], BP, !empty($_REQUEST['isAjax'])); } if (ini_get('date.timezone') == '') { - date_default_timezone_set(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE); + date_default_timezone_set('UTC'); } diff --git a/app/code/Magento/AdminNotification/Block/ToolbarEntry.php b/app/code/Magento/AdminNotification/Block/ToolbarEntry.php index 0f301a162280b8de18da5568a042b349a3e12749..c4eb46a318c8bddc16ed625dc2698bcaf630a963 100644 --- a/app/code/Magento/AdminNotification/Block/ToolbarEntry.php +++ b/app/code/Magento/AdminNotification/Block/ToolbarEntry.php @@ -69,13 +69,18 @@ class ToolbarEntry extends \Magento\Backend\Block\Template */ public function formatNotificationDate($dateString) { - if (date('Ymd') == date('Ymd', strtotime($dateString))) { - return $this->formatTime( - $dateString, - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, - false + $date = new \DateTime($dateString); + if ($date == new \DateTime('today')) { + return $this->_localeDate->formatDateTime( + $date, + \IntlDateFormatter::NONE, + \IntlDateFormatter::SHORT ); } - return $this->formatDate($dateString, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, true); + return $this->_localeDate->formatDateTime( + $date, + \IntlDateFormatter::MEDIUM, + \IntlDateFormatter::MEDIUM + ); } } diff --git a/app/code/Magento/Backend/App/AbstractAction.php b/app/code/Magento/Backend/App/AbstractAction.php index cb99c2be306a866dc2faf1183538c0a342467f88..eba77d1795371b747c0f53b4980c72cbc5459a24 100644 --- a/app/code/Magento/Backend/App/AbstractAction.php +++ b/app/code/Magento/Backend/App/AbstractAction.php @@ -290,7 +290,7 @@ abstract class AbstractAction extends \Magento\Framework\App\Action\Action } if (is_null($this->_getSession()->getLocale())) { - $this->_getSession()->setLocale($this->_localeResolver->getLocaleCode()); + $this->_getSession()->setLocale($this->_localeResolver->getLocale()); } return $this; diff --git a/app/code/Magento/Backend/Block/Dashboard/Graph.php b/app/code/Magento/Backend/Block/Dashboard/Graph.php index 91c4d619072bac7d99c3e452ff28da690468faf0..5911a361b02997c4903d7251fc20571a3b4788ad 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Graph.php +++ b/app/code/Magento/Backend/Block/Dashboard/Graph.php @@ -99,27 +99,19 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard */ protected $_dashboardData = null; - /** - * @var \Magento\Framework\Locale\ListsInterface - */ - protected $_localeLists = null; - /** * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory * @param \Magento\Backend\Helper\Dashboard\Data $dashboardData - * @param \Magento\Framework\Locale\ListsInterface $localeLists * @param array $data */ public function __construct( \Magento\Backend\Block\Template\Context $context, \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory, \Magento\Backend\Helper\Dashboard\Data $dashboardData, - \Magento\Framework\Locale\ListsInterface $localeLists, array $data = [] ) { $this->_dashboardData = $dashboardData; - $this->_localeLists = $localeLists; parent::__construct($context, $collectionFactory, $data); } @@ -213,6 +205,8 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + /** @var \DateTime $dateStart */ + /** @var \DateTime $dateEnd */ list($dateStart, $dateEnd) = $this->_collectionFactory->create()->getDateRange( $this->getDataHelper()->getParam('period'), '', @@ -220,27 +214,27 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard true ); - $dateStart->setTimezone($timezoneLocal); - $dateEnd->setTimezone($timezoneLocal); + $dateStart->setTimezone(new \DateTimeZone($timezoneLocal)); + $dateEnd->setTimezone(new \DateTimeZone($timezoneLocal)); $dates = []; $datas = []; - while ($dateStart->compare($dateEnd) < 0) { + while ($dateStart < $dateEnd) { switch ($this->getDataHelper()->getParam('period')) { case '7d': case '1m': - $d = $dateStart->toString('yyyy-MM-dd'); - $dateStart->addDay(1); + $d = $dateStart->format('Y-m-d'); + $dateStart->modify('+1 day'); break; case '1y': case '2y': - $d = $dateStart->toString('yyyy-MM'); - $dateStart->addMonth(1); + $d = $dateStart->format('Y-m'); + $dateStart->modify('+1 month'); break; default: - $d = $dateStart->toString('yyyy-MM-dd HH:00'); - $dateStart->addHour(1); + $d = $dateStart->format('Y-m-d H:00'); + $dateStart->modify('+1 hour'); } foreach ($this->getAllSeries() as $index => $serie) { if (in_array($d, $this->_axisLabels['x'])) { @@ -393,26 +387,22 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard */ foreach ($this->_axisLabels[$idx] as $_index => $_label) { if ($_label != '') { + $period = new \DateTime($_label); switch ($this->getDataHelper()->getParam('period')) { case '24h': - $this->_axisLabels[$idx][$_index] = $this->formatTime( - new \Magento\Framework\Stdlib\DateTime\Date($_label, 'yyyy-MM-dd HH:00'), - 'short', - false + $this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime( + $period->setTime($period->format('H'), 0, 0), + \IntlDateFormatter::NONE, + \IntlDateFormatter::SHORT ); break; case '7d': case '1m': - $this->_axisLabels[$idx][$_index] = $this->formatDate( - new \Magento\Framework\Stdlib\DateTime\Date($_label, 'yyyy-MM-dd') - ); + $this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime($period); break; case '1y': case '2y': - $formats = $this->_localeLists->getTranslationList('datetime'); - $format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy'; - $format = str_replace(["yyyy", "yy", "MM"], ["Y", "y", "m"], $format); - $this->_axisLabels[$idx][$_index] = date($format, strtotime($_label)); + $this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label)); break; } } else { diff --git a/app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php b/app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php index bbc3e39f72644c95166a2b5dd38a7d59994a7c35..239c99ceacb32acd4be489c0d50a709b0b6ccbce 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php +++ b/app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php @@ -17,7 +17,6 @@ class Amounts extends \Magento\Backend\Block\Dashboard\Graph * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory * @param \Magento\Backend\Helper\Dashboard\Data $dashboardData - * @param \Magento\Framework\Locale\ListsInterface $localeLists * @param \Magento\Backend\Helper\Dashboard\Order $dataHelper * @param array $data */ @@ -25,12 +24,11 @@ class Amounts extends \Magento\Backend\Block\Dashboard\Graph \Magento\Backend\Block\Template\Context $context, \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory, \Magento\Backend\Helper\Dashboard\Data $dashboardData, - \Magento\Framework\Locale\ListsInterface $localeLists, \Magento\Backend\Helper\Dashboard\Order $dataHelper, array $data = [] ) { $this->_dataHelper = $dataHelper; - parent::__construct($context, $collectionFactory, $dashboardData, $localeLists, $data); + parent::__construct($context, $collectionFactory, $dashboardData, $data); } /** diff --git a/app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php b/app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php index da407c01c3ffa5dcbf0a1359b4b72669a5edadca..1e849cae23d65450657263659c003964f225817a 100644 --- a/app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php +++ b/app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php @@ -17,7 +17,6 @@ class Orders extends \Magento\Backend\Block\Dashboard\Graph * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory * @param \Magento\Backend\Helper\Dashboard\Data $dashboardData - * @param \Magento\Framework\Locale\ListsInterface $localeLists * @param \Magento\Backend\Helper\Dashboard\Order $dataHelper * @param array $data */ @@ -25,12 +24,11 @@ class Orders extends \Magento\Backend\Block\Dashboard\Graph \Magento\Backend\Block\Template\Context $context, \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory, \Magento\Backend\Helper\Dashboard\Data $dashboardData, - \Magento\Framework\Locale\ListsInterface $localeLists, \Magento\Backend\Helper\Dashboard\Order $dataHelper, array $data = [] ) { $this->_dataHelper = $dataHelper; - parent::__construct($context, $collectionFactory, $dashboardData, $localeLists, $data); + parent::__construct($context, $collectionFactory, $dashboardData, $data); } /** diff --git a/app/code/Magento/Backend/Block/Menu.php b/app/code/Magento/Backend/Block/Menu.php index 83f63bf04e03ecbc4b15a152c36ade4e6d7783bb..785dfd02b7b7d524032a9f5505d5621701440d14 100644 --- a/app/code/Magento/Backend/Block/Menu.php +++ b/app/code/Magento/Backend/Block/Menu.php @@ -286,7 +286,7 @@ class Menu extends \Magento\Backend\Block\Template 'admin_top_nav', $this->getActive(), $this->_authSession->getUser()->getId(), - $this->_localeResolver->getLocaleCode(), + $this->_localeResolver->getLocale(), ]; // Add additional key parameters if needed $newCacheKeyInfo = $this->getAdditionalCacheKeyInfo(); diff --git a/app/code/Magento/Backend/Block/Page.php b/app/code/Magento/Backend/Block/Page.php index d8617ee82e1f63e29d1e8f4d94ab267b9124c2c0..146b05237ec8326cf69b76b36330a9d4f08d0c3e 100644 --- a/app/code/Magento/Backend/Block/Page.php +++ b/app/code/Magento/Backend/Block/Page.php @@ -52,7 +52,7 @@ class Page extends \Magento\Backend\Block\Template public function getLang() { if (!$this->hasData('lang')) { - $this->setData('lang', substr($this->_localeResolver->getLocaleCode(), 0, 2)); + $this->setData('lang', substr($this->_localeResolver->getLocale(), 0, 2)); } return $this->getData('lang'); } diff --git a/app/code/Magento/Backend/Block/Page/Locale.php b/app/code/Magento/Backend/Block/Page/Locale.php index 93c2e74acb4849007c81881b43d276eb4508e1ef..be0d1ae098a42aa687898efd26404f2df5791371 100644 --- a/app/code/Magento/Backend/Block/Page/Locale.php +++ b/app/code/Magento/Backend/Block/Page/Locale.php @@ -83,7 +83,7 @@ class Locale extends \Magento\Backend\Block\Template ->setId('footer_interface_locale') ->setTitle(__('Interface Language')) ->setClass('select locale-switcher-select') - ->setValue($this->_localeResolver->getLocale()->__toString()) + ->setValue($this->_localeResolver->getLocale()) ->setOptions($this->_localeLists->getTranslatedOptionLocales()) ->getHtml(); diff --git a/app/code/Magento/Backend/Block/System/Design/Edit/Tab/General.php b/app/code/Magento/Backend/Block/System/Design/Edit/Tab/General.php index ccb8788dbb35b49c1a0da746af36ed3948b7f8ed..ccd84b6474c572c64e21c0d04a2a840fef989b57 100644 --- a/app/code/Magento/Backend/Block/System/Design/Edit/Tab/General.php +++ b/app/code/Magento/Backend/Block/System/Design/Edit/Tab/General.php @@ -92,7 +92,7 @@ class General extends \Magento\Backend\Block\Widget\Form\Generic ] ); - $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $fieldset->addField( 'date_from', 'date', diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php index fa7185cca11b7e31e85d93ca6d245090f794ffab..5675f0fcbdadf1f2dc208843a8d0fc3a82dbb1e7 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php @@ -4,8 +4,6 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\Backend\Block\Widget\Grid\Column\Filter; /** @@ -21,7 +19,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt /** * @var \Magento\Framework\Locale\ResolverInterface */ - protected $_localeResolver; + protected $localeResolver; /** * @param \Magento\Backend\Block\Context $context @@ -38,7 +36,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt array $data = [] ) { $this->mathRandom = $mathRandom; - $this->_localeResolver = $localeResolver; + $this->localeResolver = $localeResolver; parent::__construct($context, $resourceHelper, $data); } @@ -48,7 +46,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt public function getHtml() { $htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId()); - $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $html = '<div class="range" id="' . $htmlId . '_range"><div class="range-line date">' . @@ -87,7 +85,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt $this->_getHtmlName() . '[locale]"' . ' value="' . - $this->_localeResolver->getLocaleCode() . + $this->localeResolver->getLocale() . '"/>'; $html .= '<script> require(["jquery", "mage/calendar"], function($){ @@ -126,9 +124,10 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt public function getEscapedValue($index = null) { $value = $this->getValue($index); - if ($value instanceof \Zend_Date) { - return $value->toString( - $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT) + if ($value instanceof \DateTime) { + return \IntlDateFormatter::formatObject( + $value, + $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT) ); } return $value; @@ -142,7 +141,6 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt { if ($index) { if ($data = $this->getData('value', 'orig_' . $index)) { - //date('Y-m-d', strtotime($data)); return $data; } return null; @@ -173,11 +171,11 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt if (isset($value['locale'])) { if (!empty($value['from'])) { $value['orig_from'] = $value['from']; - $value['from'] = $this->_convertDate($value['from'], $value['locale']); + $value['from'] = $this->_convertDate($value['from']); } if (!empty($value['to'])) { $value['orig_to'] = $value['to']; - $value['to'] = $this->_convertDate($value['to'], $value['locale']); + $value['to'] = $this->_convertDate($value['to']); } } if (empty($value['from']) && empty($value['to'])) { @@ -191,36 +189,25 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt * Convert given date to default (UTC) timezone * * @param string $date - * @param string $locale - * @return \Magento\Framework\Stdlib\DateTime\Date|null + * @return \DateTime|null */ - protected function _convertDate($date, $locale) + protected function _convertDate($date) { - try { - $dateObj = $this->_localeDate->date(null, null, $locale, false); - - //set default timezone for store (admin) - $dateObj->setTimezone( - $this->_scopeConfig->getValue( - $this->_localeDate->getDefaultTimezonePath(), - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) - ); - - //set beginning of day - $dateObj->setHour(00); - $dateObj->setMinute(00); - $dateObj->setSecond(00); - - //set date with applying timezone of store - $dateObj->set($date, \Zend_Date::DATE_SHORT, $locale); - - //convert store date to default date in UTC timezone without DST - $dateObj->setTimezone(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE); - - return $dateObj; - } catch (\Exception $e) { - return null; - } + $adminTimeZone = new \DateTimeZone( + $this->_scopeConfig->getValue( + $this->_localeDate->getDefaultTimezonePath(), + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) + ); + $formatter = new \IntlDateFormatter( + $this->localeResolver->getLocale(), + \IntlDateFormatter::SHORT, + \IntlDateFormatter::NONE, + $adminTimeZone + ); + $simpleRes = new \DateTime('@' . $formatter->parse($date), $adminTimeZone); + $simpleRes->setTime(0, 0, 0); + $simpleRes->setTimezone(new \DateTimeZone('UTC')); + return $simpleRes; } } diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php index 3ea98889419dc032726282b4ca3d392b4298a2a8..3d2f0110dfc279e2cf8b6c04774db94d4f194cff 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php @@ -41,14 +41,19 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date $datetimeTo = $value['to']; //calculate end date considering timezone specification + /** @var $datetimeTo \DateTime */ $datetimeTo->setTimezone( - $this->_scopeConfig->getValue( - $this->_localeDate->getDefaultTimezonePath(), - \Magento\Store\Model\ScopeInterface::SCOPE_STORE + new \DateTimeZone( + $this->_scopeConfig->getValue( + $this->_localeDate->getDefaultTimezonePath(), + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ) ) ); - $datetimeTo->addDay(1)->subSecond(1); - $datetimeTo->setTimezone(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE); + $datetimeTo->modify('+1 day')->modify('-1 second'); + $datetimeTo->setTimezone( + new \DateTimeZone('UTC') + ); } return $value; } @@ -57,41 +62,26 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date * Convert given date to default (UTC) timezone * * @param string $date - * @param string $locale - * @return \Magento\Framework\Stdlib\DateTime\Date|null + * @return \DateTime|null */ - protected function _convertDate($date, $locale) + protected function _convertDate($date) { if ($this->getColumn()->getFilterTime()) { try { - $dateObj = $this->_localeDate->date(null, null, $locale, false); - - //set default timezone for store (admin) - $dateObj->setTimezone( + $adminTimeZone = new \DateTimeZone( $this->_scopeConfig->getValue( $this->_localeDate->getDefaultTimezonePath(), \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) ); - - //set date with applying timezone of store - $dateObj->set( - $date, - $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT - ), - $locale - ); - - //convert store date to default date in UTC timezone without DST - $dateObj->setTimezone(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE); - - return $dateObj; + $simpleRes = new \DateTime($date, $adminTimeZone); + $simpleRes->setTimezone(new \DateTimeZone('UTC')); + return $simpleRes; } catch (\Exception $e) { return null; } } - return parent::_convertDate($date, $locale); + return parent::_convertDate($date); } /** @@ -102,12 +92,12 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date public function getHtml() { $htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId()); - $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $timeFormat = ''; if ($this->getColumn()->getFilterTime()) { $timeFormat = $this->_localeDate->getTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ); } @@ -132,7 +122,7 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date 'to' ) . '/>' . '</div></div>'; $html .= '<input type="hidden" name="' . $this->_getHtmlName() . '[locale]"' . ' value="' - . $this->_localeResolver->getLocaleCode() . '"/>'; + . $this->localeResolver->getLocale() . '"/>'; $html .= '<script> require(["jquery", "mage/calendar"],function($){ $("#' . $htmlId . '_range").dateRange({ @@ -163,12 +153,8 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Filter\Date { if ($this->getColumn()->getFilterTime()) { $value = $this->getValue($index); - if ($value instanceof \Zend_Date) { - return $value->toString( - $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT - ) - ); + if ($value instanceof \DateTime) { + return $this->_localeDate->formatDateTime($value); } return $value; } diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php b/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php index 59eff5872dd090ca304d880c4f43393efc21b849..320c05567a6f72fed1e30d6401f8377b12b4f238 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php @@ -43,7 +43,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRe if (is_null(self::$_format)) { try { self::$_format = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); } catch (\Exception $e) { $this->_logger->critical($e); @@ -64,30 +64,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRe { if ($data = $row->getData($this->getColumn()->getIndex())) { $format = $this->_getFormat(); - try { - if ($this->getColumn()->getGmtoffset()) { - $data = $this->_localeDate->date( - $data, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - )->toString( - $format - ); - } else { - $data = $this->_localeDate->date($data, \Zend_Date::ISO_8601, null, false)->toString($format); - } - } catch (\Exception $e) { - if ($this->getColumn()->getTimezone()) { - $data = $this->_localeDate->date( - $data, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - )->toString( - $format - ); - } else { - $data = $this->_localeDate->date($data, null, null, false)->toString($format); - } - } - return $data; + return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format); } return $this->getColumn()->getDefault(); } diff --git a/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Datetime.php b/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Datetime.php index 0a5e6f96d39eb3bc769fcf0e058c4753b8dcf85b..674041d975e251aef00409198df1dae514d6dd96 100644 --- a/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Datetime.php +++ b/app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Datetime.php @@ -11,36 +11,6 @@ namespace Magento\Backend\Block\Widget\Grid\Column\Renderer; class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer { - /** - * Date format string - * - * @var string - */ - protected static $_format = null; - - /** - * Retrieve datetime format - * - * @return string|null - */ - protected function _getFormat() - { - $format = $this->getColumn()->getFormat(); - if (!$format) { - if (is_null(self::$_format)) { - try { - self::$_format = $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM - ); - } catch (\Exception $e) { - $this->_logger->critical($e); - } - } - $format = self::$_format; - } - return $format; - } - /** * Renders grid column * @@ -49,24 +19,13 @@ class Datetime extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abstra */ public function render(\Magento\Framework\Object $row) { + $format = $this->getColumn()->getFormat(); if ($data = $this->_getValue($row)) { - $format = $this->_getFormat(); - try { - $data = $this->_localeDate->date( - $data, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - )->toString( - $format - ); - } catch (\Exception $e) { - $data = $this->_localeDate->date( - $data, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - )->toString( - $format - ); - } - return $data; + return $this->_localeDate->formatDateTime( + $data instanceof \DateTimeInterface ? $data : new \DateTime($data), + $format ?: \IntlDateFormatter::MEDIUM, + $format ?: \IntlDateFormatter::MEDIUM + ); } return $this->getColumn()->getDefault(); } diff --git a/app/code/Magento/Backend/Helper/Data.php b/app/code/Magento/Backend/Helper/Data.php index bfc14df5c049534970f5e33e0bbb75d0c7c39167..e54179a3a50d74b9d43fdf5d312c111ecb90d076 100644 --- a/app/code/Magento/Backend/Helper/Data.php +++ b/app/code/Magento/Backend/Helper/Data.php @@ -105,7 +105,7 @@ class Data extends AbstractHelper } } $url = 'http://www.magentocommerce.com/gethelp/'; - $url .= $this->_locale->getLocaleCode() . '/'; + $url .= $this->_locale->getLocale() . '/'; $url .= $frontModule . '/'; $url .= $request->getControllerName() . '/'; $url .= $request->getActionName() . '/'; diff --git a/app/code/Magento/Backend/Model/Locale/Resolver.php b/app/code/Magento/Backend/Model/Locale/Resolver.php index 767f3d71041b7c2a823a126777f2825010949223..b27fcf1468311129e3e307ef0ffa57909ea2e08d 100644 --- a/app/code/Magento/Backend/Model/Locale/Resolver.php +++ b/app/code/Magento/Backend/Model/Locale/Resolver.php @@ -32,8 +32,6 @@ class Resolver extends \Magento\Framework\Locale\Resolver /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Magento\Framework\LocaleFactory $localeFactory * @param string $defaultLocalePath * @param string $scopeType * @param \Magento\Backend\Model\Session $session @@ -45,8 +43,6 @@ class Resolver extends \Magento\Framework\Locale\Resolver */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\App\CacheInterface $cache, - \Magento\Framework\LocaleFactory $localeFactory, $defaultLocalePath, $scopeType, \Magento\Backend\Model\Session $session, @@ -59,7 +55,7 @@ class Resolver extends \Magento\Framework\Locale\Resolver $this->_localeManager = $localeManager; $this->_request = $request; $this->_localeValidator = $localeValidator; - parent::__construct($scopeConfig, $cache, $localeFactory, $defaultLocalePath, $scopeType, $locale); + parent::__construct($scopeConfig, $defaultLocalePath, $scopeType, $locale); } /** @@ -70,8 +66,6 @@ class Resolver extends \Magento\Framework\Locale\Resolver */ public function setLocale($locale = null) { - parent::setLocale($locale); - $forceLocale = $this->_request->getParam('locale', null); if (!$this->_localeValidator->isValid($forceLocale)) { $forceLocale = false; @@ -83,9 +77,9 @@ class Resolver extends \Magento\Framework\Locale\Resolver $localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]); if (count($localeCodes)) { - $this->setLocaleCode(reset($localeCodes)); + $locale = reset($localeCodes); } - return $this; + return parent::setLocale($locale); } } diff --git a/app/code/Magento/Backend/Model/Observer.php b/app/code/Magento/Backend/Model/Observer.php index 285ffdd4d0b18cbe69d91427261af1a2f8c218d8..79f92228efc4917f764d6ac38417c763fce7317e 100644 --- a/app/code/Magento/Backend/Model/Observer.php +++ b/app/code/Magento/Backend/Model/Observer.php @@ -10,48 +10,20 @@ namespace Magento\Backend\Model; */ class Observer { - /** - * @var \Magento\Backend\Model\Session - */ - protected $backendSession; - /** * @var \Magento\Framework\App\Cache\Frontend\Pool */ private $cacheFrontendPool; /** - * Initialize dependencies - * - * @param Session $backendSession * @param \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool */ public function __construct( - \Magento\Backend\Model\Session $backendSession, \Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool ) { - $this->backendSession = $backendSession; $this->cacheFrontendPool = $cacheFrontendPool; } - /** - * Bind locale - * - * @param \Magento\Framework\Event\Observer $observer - * @return $this - */ - public function bindLocale($observer) - { - $locale = $observer->getEvent()->getLocale(); - if ($locale) { - $selectedLocale = $this->backendSession->getLocale(); - if ($selectedLocale) { - $locale->setLocaleCode($selectedLocale); - } - } - return $this; - } - /** * Clear result of configuration files access level verification in system cache * diff --git a/app/code/Magento/Backup/Model/Backup.php b/app/code/Magento/Backup/Model/Backup.php index 73ed11ca6bcc3d524f37fe69f889061f46541f65..73f9ec7cac8b6a6e3295ab3187cb65abf3048c45 100755 --- a/app/code/Magento/Backup/Model/Backup.php +++ b/app/code/Magento/Backup/Model/Backup.php @@ -152,10 +152,7 @@ class Backup extends \Magento\Framework\Object implements \Magento\Framework\Bac 'extension' => $this->_helper->getExtensionByType($backupData->getType()), 'display_name' => $this->_helper->nameToDisplayName($backupData->getName()), 'name' => $backupData->getName(), - 'date_object' => new \Magento\Framework\Stdlib\DateTime\Date( - (int)$backupData->getTime(), - $this->_localeResolver->getLocaleCode() - ), + 'date_object' => new \DateTime('@' . $backupData->getTime()), ] ); diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.php index 78fa7f98fa105fffe0114b138ff4e0f921c62f7f..0e982417ed1bb3e40addfe6a6c73f8f42fbb1d68 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.php @@ -115,7 +115,7 @@ class Advanced extends Generic ] ); - $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $fieldset->addField( 'default_value_date', 'date', diff --git a/app/code/Magento/Catalog/Block/Product/NewProduct.php b/app/code/Magento/Catalog/Block/Product/NewProduct.php index 1f4121d3231a159ee396d56cf7465efa8a6c4405..21225c834b7125acd6c9f80e4044a6543aa2a545 100644 --- a/app/code/Magento/Catalog/Block/Product/NewProduct.php +++ b/app/code/Magento/Catalog/Block/Product/NewProduct.php @@ -113,17 +113,8 @@ class NewProduct extends \Magento\Catalog\Block\Product\AbstractProduct implemen */ protected function _getProductCollection() { - $todayStartOfDayDate = $this->_localeDate->date()->setTime( - '00:00:00' - )->toString( - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); - - $todayEndOfDayDate = $this->_localeDate->date()->setTime( - '23:59:59' - )->toString( - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); + $todayStartOfDayDate = $this->_localeDate->date()->setTime(0, 0, 0)->format('Y-m-d H:i:s'); + $todayEndOfDayDate = $this->_localeDate->date()->setTime(23, 59, 59)->format('Y-m-d H:i:s'); /** @var $collection \Magento\Catalog\Model\Resource\Product\Collection */ $collection = $this->_productCollectionFactory->create(); diff --git a/app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php b/app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php index bac018a247f34233ff035570788784003ccaf595..bba1502ffb3ad5ecf5827c43cd62bf557ea9e25e 100644 --- a/app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php +++ b/app/code/Magento/Catalog/Block/Product/View/Options/Type/Date.php @@ -93,7 +93,7 @@ class Date extends \Magento\Catalog\Block\Product\View\Options\AbstractOptions )->setImage( $this->getViewFileUrl('Magento_Theme::calendar.png') )->setDateFormat( - $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT) + $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT) )->setValue( $value )->setYearsRange( diff --git a/app/code/Magento/Catalog/Block/Rss/Product/Special.php b/app/code/Magento/Catalog/Block/Rss/Product/Special.php index 60be17cb4881e970b91962cc255f3b8e2105a98b..41a683ff4358403d4ce2db44009dc4ff0ac980f9 100644 --- a/app/code/Magento/Catalog/Block/Rss/Product/Special.php +++ b/app/code/Magento/Catalog/Block/Rss/Product/Special.php @@ -55,11 +55,6 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D */ protected $msrpHelper; - /** - * @var \Magento\Framework\Stdlib\DateTime\DateFactory - */ - private $dateFactory; - /** * @var \Magento\Framework\Locale\ResolverInterface */ @@ -74,7 +69,6 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency * @param \Magento\Catalog\Model\Rss\Product\Special $rssModel * @param \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder - * @param \Magento\Framework\Stdlib\DateTime\DateFactory $dateFactory * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -88,7 +82,6 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Magento\Catalog\Model\Rss\Product\Special $rssModel, \Magento\Framework\App\Rss\UrlBuilderInterface $rssUrlBuilder, - \Magento\Framework\Stdlib\DateTime\DateFactory $dateFactory, \Magento\Framework\Locale\ResolverInterface $localeResolver, array $data = [] ) { @@ -101,7 +94,6 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D $this->httpContext = $httpContext; $this->storeManager = $context->getStoreManager(); parent::__construct($context, $data); - $this->dateFactory = $dateFactory; $this->localeResolver = $localeResolver; } @@ -134,7 +126,7 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D 'language' => $lang, ]; - $currentDate = new \Magento\Framework\Stdlib\DateTime\Date(); + $currentDate = (new \DateTime())->setTime(0, 0, 0); foreach ($this->rssModel->getProductsCollection($this->getStoreId(), $this->getCustomerGroupId()) as $item) { /** @var $item \Magento\Catalog\Model\Product */ $item->setAllowedInRss(true); @@ -153,11 +145,7 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D if ($item->getSpecialToDate() && $item->getFinalPrice() <= $item->getSpecialPrice() && $item->getAllowedPriceInRss() ) { - $compareDate = $currentDate->compareDate( - $item->getSpecialToDate(), - \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT - ); - if (-1 === $compareDate || 0 === $compareDate) { + if ($currentDate->format('Y-m-d') <= $item->getSpecialToDate()) { $item->setUseSpecial(true); } } @@ -188,14 +176,8 @@ class Special extends \Magento\Framework\View\Element\AbstractBlock implements D $special = ''; if ($item->getUseSpecial()) { $special = '<br />' . __('Special Expires On: %1', $this->formatDate( - $this->dateFactory->create( - [ - 'date' => $item->getSpecialToDate(), - 'part' => \Magento\Framework\Stdlib\DateTime\Date::ISO_8601, - 'locale' => $this->localeResolver->getLocaleCode() - ] - ), - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + $item->getSpecialToDate(), + \IntlDateFormatter::MEDIUM )); } $specialPrice = sprintf( diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php index fd5647e6c3a1793d4aa43c852d747e2c9a2452cc..ef791cd838cdac322244ddead979da27b69c4f27 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Action/Attribute/Save.php @@ -118,7 +118,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Product\Action\Attribut $storeId = $this->attributeHelper->getSelectedStoreId(); if ($attributesData) { $dateFormat = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\TimezoneInterface') - ->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + ->getDateFormat(\IntlDateFormatter::SHORT); foreach ($attributesData as $attributeCode => $value) { $attribute = $this->_objectManager->get('Magento\Eav\Model\Config') diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Observer.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Observer.php index 0d8b328c8873a21a4a8f306b4824614a108c87e9..bf0c2104daa93598be70f4df020cf8092eed20a3 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Observer.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Observer.php @@ -94,7 +94,7 @@ class Observer $currDateExpr = $connection->quote($currDate); // timestamp is locale based - if (date(\Zend_Date::HOUR_SHORT, $timestamp) == '00') { + if (date('H', $timestamp) == '00') { $format = '%Y-%m-%d %H:%i:%s'; $this->_refreshSpecialPriceByStore( $store->getId(), diff --git a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php index 9e2df08ea458b0f0cb835698afa790174953b9bb..9d4c877d8da833080b3db357c016361487dd5181 100644 --- a/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php +++ b/app/code/Magento/Catalog/Model/Product/Option/Type/Date.php @@ -143,10 +143,7 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType if ($this->_dateExists()) { if ($this->useCalendar()) { - $format = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT - ); - $timestamp += $this->_localeDate->date($value['date'], $format, null, false)->getTimestamp(); + $timestamp += (new \DateTime($value['date']))->getTimestamp(); } else { $timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']); } @@ -168,8 +165,8 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType $timestamp += 60 * 60 * $value['hour'] + 60 * $value['minute']; } - $date = new \Magento\Framework\Stdlib\DateTime\Date($timestamp); - $result = $date->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + $date = new \DateTime('@' . $timestamp); + $result = $date->format('Y-m-d H:i:s'); // Save date in internal format to avoid locale date bugs $this->_setInternalInRequest($result); @@ -190,27 +187,21 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType public function getFormattedOptionValue($optionValue) { if ($this->_formattedOptionValue === null) { - $option = $this->getOption(); if ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE) { $format = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); - $result = $this->_localeDate->date($optionValue, \Zend_Date::ISO_8601, null, false)->toString($format); + $result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format); } elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) { $format = $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT - ); - $result = $this->_localeDate->date( - $optionValue, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT, - null, - false - )->toString( - $format + \IntlDateFormatter::SHORT ); + $result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format); } elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) { - $date = new \Magento\Framework\Stdlib\DateTime\Date($optionValue); - $result = date($this->is24hTimeFormat() ? 'H:i' : 'h:i a', $date->getTimestamp()); + $result = \IntlDateFormatter::formatObject( + new \DateTime($optionValue), + $this->is24hTimeFormat() ? 'H:i' : 'h:i a' + ); } else { $result = $optionValue; } @@ -247,16 +238,16 @@ class Date extends \Magento\Catalog\Model\Product\Option\Type\DefaultType * @param string $optionValue * @param array $productOptionValues Values for product option * @return string|null + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function parseOptionValue($optionValue, $productOptionValues) { - $timestamp = strtotime($optionValue); - if ($timestamp === false || $timestamp == -1) { + try { + $date = new \DateTime($optionValue); + } catch (\Exception $e) { return null; } - - $date = new \Magento\Framework\Stdlib\DateTime\Date($timestamp); - return $date->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + return $date->format('Y-m-d H:i:s'); } /** diff --git a/app/code/Magento/Catalog/Model/Product/Type/Price.php b/app/code/Magento/Catalog/Model/Product/Type/Price.php index da34894119078e6845de7f87da16a45b40bd7741..b86dc74b3c74c2343bee44290c47dd4fc98bb1d6 100644 --- a/app/code/Magento/Catalog/Model/Product/Type/Price.php +++ b/app/code/Magento/Catalog/Model/Product/Type/Price.php @@ -477,8 +477,8 @@ class Price ); if ($rulePrice === false) { - $storeTimestamp = $this->_localeDate->scopeTimeStamp($sId); - $rulePrice = $this->_ruleFactory->create()->getRulePrice($storeTimestamp, $wId, $gId, $productId); + $date = $this->_localeDate->scopeDate($sId); + $rulePrice = $this->_ruleFactory->create()->getRulePrice($date, $wId, $gId, $productId); } if ($rulePrice !== null && $rulePrice !== false) { diff --git a/app/code/Magento/Catalog/Model/Rss/Product/NewProducts.php b/app/code/Magento/Catalog/Model/Rss/Product/NewProducts.php index 5156f5023c995c26adb43995fea9fcbca95a06a0..1f0a919125213974578dcddc604aab2c5b8bad52 100644 --- a/app/code/Magento/Catalog/Model/Rss/Product/NewProducts.php +++ b/app/code/Magento/Catalog/Model/Rss/Product/NewProducts.php @@ -49,11 +49,13 @@ class NewProducts { /** @var $product \Magento\Catalog\Model\Product */ $product = $this->productFactory->create(); - $todayStartOfDayDate = $this->localeDate->date()->setTime('00:00:00') - ->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + $todayStartOfDayDate = $this->localeDate->date() + ->setTime(0, 0) + ->format('Y-m-d H:i:s'); - $todayEndOfDayDate = $this->localeDate->date()->setTime('23:59:59') - ->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + $todayEndOfDayDate = $this->localeDate->date() + ->setTime(23, 59, 59) + ->format('Y-m-d H:i:s'); /** @var $products \Magento\Catalog\Model\Resource\Product\Collection */ $products = $product->getResourceCollection(); $products->setStoreId($storeId); diff --git a/app/code/Magento/Catalog/Test/Unit/Block/Rss/Product/SpecialTest.php b/app/code/Magento/Catalog/Test/Unit/Block/Rss/Product/SpecialTest.php index 86445975f7619628dc03cc7424e94dbd65e2adf6..05d98f2b8c5770bdf4f3962d95d05abacee9c955 100644 --- a/app/code/Magento/Catalog/Test/Unit/Block/Rss/Product/SpecialTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Block/Rss/Product/SpecialTest.php @@ -73,11 +73,6 @@ class SpecialTest extends \PHPUnit_Framework_TestCase */ protected $request; - /** - * @var \Magento\Framework\Stdlib\DateTime\DateFactory|\PHPUnit_Framework_MockObject_MockObject - */ - protected $dateFactory; - protected function setUp() { $this->request = $this->getMock('Magento\Framework\App\RequestInterface'); @@ -106,7 +101,6 @@ class SpecialTest extends \PHPUnit_Framework_TestCase $this->scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue('en_US')); $this->localeDate = $this->getMock('\Magento\Framework\Stdlib\DateTime\TimezoneInterface'); - $this->dateFactory = $this->getMock('Magento\Framework\Stdlib\DateTime\DateFactory', ['create'], [], '', false); $objectManagerHelper = new ObjectManagerHelper($this); $this->block = $objectManagerHelper->getObject( @@ -123,7 +117,6 @@ class SpecialTest extends \PHPUnit_Framework_TestCase 'storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'localeDate' => $this->localeDate, - 'dateFactory' => $this->dateFactory ] ); } @@ -137,8 +130,7 @@ class SpecialTest extends \PHPUnit_Framework_TestCase $this->rssModel->expects($this->once())->method('getProductsCollection') ->will($this->returnValue([$item])); $this->msrpHelper->expects($this->once())->method('canApplyMsrp')->will($this->returnValue(false)); - $this->dateFactory->expects($this->once())->method('create'); - $this->localeDate->expects($this->once())->method('formatDate')->will($this->returnValue(date('Y-m-d'))); + $this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue(date('Y-m-d'))); $this->priceCurrency->expects($this->any())->method('convertAndFormat')->will($this->returnArgument(0)); @@ -193,7 +185,7 @@ class SpecialTest extends \PHPUnit_Framework_TestCase 'getUseSpecial', ])->disableOriginalConstructor()->getMock(); $item->expects($this->once())->method('getAllowedInRss')->will($this->returnValue(true)); - $item->expects($this->exactly(3))->method('getSpecialToDate')->will($this->returnValue(date('Y-m-d'))); + $item->expects($this->any())->method('getSpecialToDate')->will($this->returnValue(date('Y-m-d'))); $item->expects($this->exactly(2))->method('getFinalPrice')->will($this->returnValue(10)); $item->expects($this->once())->method('getSpecialPrice')->will($this->returnValue(15)); $item->expects($this->exactly(2))->method('getAllowedPriceInRss')->will($this->returnValue(true)); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Rss/Product/NewProductsTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Rss/Product/NewProductsTest.php index dda2b6f11383129ad996c02d185cb87327f4f7da..e883c2ab9c237ff721d1af5c1631f8bb872f180c 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Rss/Product/NewProductsTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Rss/Product/NewProductsTest.php @@ -64,13 +64,18 @@ class NewProductsTest extends \PHPUnit_Framework_TestCase public function testGetProductsCollection() { - /** @var \Magento\Framework\Stdlib\DateTime\Date|\PHPUnit_Framework_MockObject_MockObject $dateObject */ - $dateObject = $this->getMock('Magento\Framework\Stdlib\DateTime\Date'); - $dateObject->expects($this->any())->method('setTime')->will($this->returnSelf()); - $dateObject->expects($this->any())->method('toString')->will( - $this->returnValue(date(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT)) - ); - $this->timezone->expects($this->exactly(2))->method('date')->will($this->returnValue($dateObject)); + /** @var \DateTime|\PHPUnit_Framework_MockObject_MockObject $dateObject */ + $dateObject = $this->getMock('DateTime'); + $dateObject->expects($this->any()) + ->method('setTime') + ->will($this->returnSelf()); + $dateObject->expects($this->any()) + ->method('format') + ->will($this->returnValue(date(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT))); + + $this->timezone->expects($this->exactly(2)) + ->method('date') + ->will($this->returnValue($dateObject)); /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */ $productCollection = $this->getMock('Magento\Catalog\Model\Resource\Product\Collection', [], [], '', false); diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 231331edb16ed4a5153a75e7de839e541a51015b..0bcac43699d1cc037b309bbedc1f384f7bec0e51 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -12,6 +12,7 @@ use Magento\Framework\App\Filesystem\DirectoryList; use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface; use Magento\Framework\Model\Resource\Db\TransactionManagerInterface; use Magento\Framework\Model\Resource\Db\ObjectRelationProcessor; +use Magento\Framework\Stdlib\DateTime; /** * Import entity product model @@ -336,7 +337,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity protected $_localeDate; /** - * @var \Magento\Framework\Stdlib\DateTime + * @var DateTime */ protected $dateTime; @@ -409,7 +410,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\CatalogInventory\Model\Resource\Stock\ItemFactory $stockResItemFac * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate - * @param \Magento\Framework\Stdlib\DateTime $dateTime + * @param DateTime $dateTime * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Indexer\Model\IndexerRegistry $indexerRegistry * @param Product\StoreResolver $storeResolver @@ -444,7 +445,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity \Magento\Framework\Filesystem $filesystem, \Magento\CatalogInventory\Model\Resource\Stock\ItemFactory $stockResItemFac, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, - \Magento\Framework\Stdlib\DateTime $dateTime, + DateTime $dateTime, \Psr\Log\LoggerInterface $logger, \Magento\Indexer\Model\IndexerRegistry $indexerRegistry, Product\StoreResolver $storeResolver, @@ -943,7 +944,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity if (isset($this->_oldSku[$rowSku])) { // existing row $entityRowsUp[] = [ - 'updated_at' => $this->dateTime->now(), + 'updated_at' => (new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT), 'entity_id' => $this->_oldSku[$rowSku]['entity_id'], ]; } else { @@ -954,8 +955,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity 'type_id' => $this->skuProcessor->getNewSku($rowSku)['type_id'], 'sku' => $rowSku, 'has_options' => isset($rowData['has_options']) ? $rowData['has_options'] : 0, - 'created_at' => $this->dateTime->now(), - 'updated_at' => $this->dateTime->now(), + 'created_at' => (new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT), + 'updated_at' => (new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT), ]; $productsQty++; } else { @@ -1086,7 +1087,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) { $attrValue = new \DateTime('@' . strtotime($attrValue)); - $attrValue = $attrValue->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); + $attrValue = $attrValue->format(DateTime::DATETIME_PHP_FORMAT); } elseif ($backModel) { $attribute->getBackend()->beforeSave($product); $attrValue = $product->getData($attribute->getAttributeCode()); @@ -1440,8 +1441,8 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity $stockItemDo->setData($row); $row['is_in_stock'] = $this->stockStateProvider->verifyStock($stockItemDo); if ($this->stockStateProvider->verifyNotification($stockItemDo)) { - $row['low_stock_date'] = $this->_localeDate->date(null, null, null, false) - ->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + $row['low_stock_date'] = $this->_localeDate->date(null, null, false) + ->format('Y-m-d H:i:s'); } $row['stock_status_changed_auto'] = (int) !$this->stockStateProvider->verifyStock($stockItemDo); diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php b/app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php index acece5eed42edc554529146beb0fc44ce5d822d9..b1b556466c5e587b90357824435bad027b6ac123 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product/Option.php @@ -1348,7 +1348,7 @@ class Option extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity 'entity_id' => $productId, 'has_options' => 1, 'required_options' => 0, - 'updated_at' => $this->dateTime->now(), + 'updated_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), ]; if (!empty($rowData[self::COLUMN_IS_REQUIRED])) { diff --git a/app/code/Magento/CatalogInventory/Model/Stock/StockItemRepository.php b/app/code/Magento/CatalogInventory/Model/Stock/StockItemRepository.php index 10c1debd7335d941e1ad30af64fc0f047d8a1d3e..d41f2951dadeab5d2c610f0609c94e5e8e1d0670 100644 --- a/app/code/Magento/CatalogInventory/Model/Stock/StockItemRepository.php +++ b/app/code/Magento/CatalogInventory/Model/Stock/StockItemRepository.php @@ -138,8 +138,7 @@ class StockItemRepository implements StockItemRepositoryInterface $stockItem->setLowStockDate(null); if ($this->stockStateProvider->verifyNotification($stockItem)) { $stockItem->setLowStockDate( - $this->localeDate->date(null, null, null, false) - ->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + (new \DateTime())->format('Y-m-d H:i:s') ); } $stockItem->setStockStatusChangedAuto(0); diff --git a/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Main.php b/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Main.php index 4e9f25b954c15d489240337fbd00730d0c5094f9..60ddd32007c278a4cf5f0d497d5b65c7ad3002d9 100644 --- a/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Main.php +++ b/app/code/Magento/CatalogRule/Block/Adminhtml/Promo/Catalog/Edit/Tab/Main.php @@ -187,7 +187,7 @@ class Main extends Generic implements TabInterface ); $dateFormat = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ); $fieldset->addField( 'from_date', diff --git a/app/code/Magento/CatalogRule/Model/Observer.php b/app/code/Magento/CatalogRule/Model/Observer.php index 887b60b9c8a2e5426eee596422197fb29c027dff..b5cf25c153b3a173bccf087aa2e704afdb04dc9e 100644 --- a/app/code/Magento/CatalogRule/Model/Observer.php +++ b/app/code/Magento/CatalogRule/Model/Observer.php @@ -133,9 +133,9 @@ class Observer $storeId = $product->getStoreId(); if ($observer->hasDate()) { - $date = $observer->getEvent()->getDate(); + $date = new \DateTime($observer->getEvent()->getDate()); } else { - $date = $this->_localeDate->scopeTimeStamp($storeId); + $date = $this->_localeDate->scopeDate($storeId); } if ($observer->hasWebsiteId()) { @@ -152,7 +152,7 @@ class Observer $gId = $this->_customerSession->getCustomerGroupId(); } - $key = "{$date}|{$wId}|{$gId}|{$pId}"; + $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}"; if (!isset($this->_rulePrices[$key])) { $rulePrice = $this->_resourceRuleFactory->create()->getRulePrice($date, $wId, $gId, $pId); $this->_rulePrices[$key] = $rulePrice; @@ -183,12 +183,12 @@ class Observer $gId = $ruleData->getCustomerGroupId(); $pId = $product->getId(); - $key = "{$date}|{$wId}|{$gId}|{$pId}"; + $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}"; } elseif (!is_null($product->getWebsiteId()) && !is_null($product->getCustomerGroupId())) { $wId = $product->getWebsiteId(); $gId = $product->getCustomerGroupId(); $pId = $product->getId(); - $key = "{$date}|{$wId}|{$gId}|{$pId}"; + $key = "{$date->format('Y-m-d H:i:s')}|{$wId}|{$gId}|{$pId}"; } if ($key) { @@ -265,15 +265,15 @@ class Observer } } if ($observer->getEvent()->hasDate()) { - $date = $observer->getEvent()->getDate(); + $date = new \DateTime($observer->getEvent()->getDate()); } else { - $date = $this->_localeDate->scopeTimeStamp($store); + $date = new \DateTime('@' . $this->_localeDate->scopeTimeStamp($store)); } $productIds = []; /* @var $product Product */ foreach ($collection as $product) { - $key = implode('|', [$date, $websiteId, $groupId, $product->getId()]); + $key = implode('|', [$date->format('Y-m-d H:i:s'), $websiteId, $groupId, $product->getId()]); if (!isset($this->_rulePrices[$key])) { $productIds[] = $product->getId(); } @@ -287,7 +287,7 @@ class Observer $productIds ); foreach ($productIds as $productId) { - $key = implode('|', [$date, $websiteId, $groupId, $productId]); + $key = implode('|', [$date->format('Y-m-d H:i:s'), $websiteId, $groupId, $productId]); $this->_rulePrices[$key] = isset($rulePrices[$productId]) ? $rulePrices[$productId] : false; } } diff --git a/app/code/Magento/CatalogRule/Model/Resource/Rule.php b/app/code/Magento/CatalogRule/Model/Resource/Rule.php index 3fe9ce0f5f8778fffd99d5384aae81727e680383..b20a93b2b6f15ee8904c2d8823b58fbd4ca1ef52 100644 --- a/app/code/Magento/CatalogRule/Model/Resource/Rule.php +++ b/app/code/Magento/CatalogRule/Model/Resource/Rule.php @@ -210,7 +210,7 @@ class Rule extends \Magento\Rule\Model\Resource\AbstractResource * Get catalog rules product price for specific date, website and * customer group * - * @param int|string $date + * @param \DateTime $date * @param int $wId * @param int $gId * @param int $pId @@ -230,13 +230,13 @@ class Rule extends \Magento\Rule\Model\Resource\AbstractResource * Retrieve product prices by catalog rule for specific date, website and customer group * Collect data with product Id => price pairs * - * @param int|string $date + * @param \DateTime $date * @param int $websiteId * @param int $customerGroupId * @param array $productIds * @return array */ - public function getRulePrices($date, $websiteId, $customerGroupId, $productIds) + public function getRulePrices(\DateTime $date, $websiteId, $customerGroupId, $productIds) { $adapter = $this->_getReadAdapter(); $select = $adapter->select()->from( @@ -244,7 +244,7 @@ class Rule extends \Magento\Rule\Model\Resource\AbstractResource ['product_id', 'rule_price'] )->where( 'rule_date = ?', - $this->dateTime->formatDate($date, false) + $date->format('Y-m-d') )->where( 'website_id = ?', $websiteId diff --git a/app/code/Magento/CatalogRule/Model/Rule.php b/app/code/Magento/CatalogRule/Model/Rule.php index 1228ac74d24cb34975ecd832a25d2f714b1af202..61eac7c2b59f204a98ee782994d04eed6e97bfbf 100644 --- a/app/code/Magento/CatalogRule/Model/Rule.php +++ b/app/code/Magento/CatalogRule/Model/Rule.php @@ -252,7 +252,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel public function getNow() { if (!$this->_now) { - return $this->dateTime->now(); + return (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); } return $this->_now; } diff --git a/app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php b/app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php index ecd31765bcb0bd419b1acc25656ac28cc40376d4..5140f4a55eee011fca72375dc48118fac012f658 100644 --- a/app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php +++ b/app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php @@ -82,7 +82,7 @@ class CatalogRulePrice extends AbstractPrice implements BasePriceProviderInterfa if (null === $this->value) { $this->value = $this->resourceRuleFactory->create() ->getRulePrice( - $this->dateTime->scopeTimeStamp($this->storeManager->getStore()->getId()), + $this->dateTime->scopeDate($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId() diff --git a/app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php b/app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php index 10f5e51286c200feb09542765874060c9f6e439b..44a3efcdd797a126098241b25e74e2796dac3c2d 100644 --- a/app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php +++ b/app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php @@ -177,7 +177,7 @@ class CatalogRulePriceTest extends \PHPUnit_Framework_TestCase ->method('getWebsiteId') ->will($this->returnValue($coreWebsiteId)); $this->dataTimeMock->expects($this->once()) - ->method('scopeTimeStamp') + ->method('scopeDate') ->with($this->equalTo($coreStoreId)) ->will($this->returnValue($dateTime)); $this->customerSessionMock->expects($this->once()) diff --git a/app/code/Magento/CatalogSearch/Block/Advanced/Form.php b/app/code/Magento/CatalogSearch/Block/Advanced/Form.php index 948f2db6e5e1366bdae12e03b7a49a8c5f8bccd0..730f52568e8058cc31366f4e126d5fae08df989c 100644 --- a/app/code/Magento/CatalogSearch/Block/Advanced/Form.php +++ b/app/code/Magento/CatalogSearch/Block/Advanced/Form.php @@ -348,7 +348,7 @@ class Form extends Template )->setImage( $this->getViewFileUrl('Magento_Theme::calendar.png') )->setDateFormat( - $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT) + $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT) )->setClass( 'input-text' )->getHtml(); diff --git a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php index 104843591917cd0000399b15a7e8bae60ac7737d..09bced67eb0c3ebffe81527df0d0db8b7d08ab5d 100644 --- a/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php +++ b/app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php @@ -28,9 +28,9 @@ class Full protected $separator = ' | '; /** - * Array of \Magento\Framework\Stdlib\DateTime\DateInterface objects per store + * Array of \DateTime objects per store * - * @var array + * @var \DateTime[] */ protected $dates = []; @@ -140,7 +140,7 @@ class Full /** * @var \Magento\Framework\Search\Request\Config */ - private $searchRequestConfig; + protected $searchRequestConfig; /** * @param \Magento\Framework\App\Resource $resource @@ -763,23 +763,20 @@ class Full \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); + + $this->localeResolver->emulate($storeId); + + $dateObj = new \DateTime(); + $dateObj->setTimezone(new \DateTimeZone($timezone)); + $this->dates[$storeId] = $dateObj; - $dateObj = new \Magento\Framework\Stdlib\DateTime\Date(null, null, $locale); - $dateObj->setTimezone($timezone); - $this->dates[$storeId] = [$dateObj, $locale->getTranslation(null, 'date', $locale)]; + $this->localeResolver->revert(); } 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); + /** @var \DateTime $dateObj */ + $dateObj = $this->dates[$storeId]; + return $this->localeDate->formatDateTime($dateObj, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE); } return null; diff --git a/app/code/Magento/Checkout/Controller/Cart/Add.php b/app/code/Magento/Checkout/Controller/Cart/Add.php index bc7d70be280d3b705b6ab208213f7dfeba99012a..d9cf864bd356fc02a1d18210cb4c451a523158da 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Add.php +++ b/app/code/Magento/Checkout/Controller/Cart/Add.php @@ -86,7 +86,7 @@ class Add extends \Magento\Checkout\Controller\Cart try { if (isset($params['qty'])) { $filter = new \Zend_Filter_LocalizedToNormalized( - ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocaleCode()] + ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()] ); $params['qty'] = $filter->filter($params['qty']); } diff --git a/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php b/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php index a7ae076c012dc9431a7cdb419885f29f269e8c3e..61be91b6a1e925178502254081decb8d0cc3112d 100644 --- a/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php +++ b/app/code/Magento/Checkout/Controller/Cart/UpdateItemOptions.php @@ -29,7 +29,7 @@ class UpdateItemOptions extends \Magento\Checkout\Controller\Cart try { if (isset($params['qty'])) { $filter = new \Zend_Filter_LocalizedToNormalized( - ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocaleCode()] + ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()] ); $params['qty'] = $filter->filter($params['qty']); } diff --git a/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php b/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php index bd7abd59c5b5341e3f080e7e0dcbbba8dbdb189b..dc71ca01354e36206279c5a580c9a5f4be0b71c8 100644 --- a/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php +++ b/app/code/Magento/Checkout/Controller/Cart/UpdatePost.php @@ -39,7 +39,7 @@ class UpdatePost extends \Magento\Checkout\Controller\Cart $cartData = $this->getRequest()->getParam('cart'); if (is_array($cartData)) { $filter = new \Zend_Filter_LocalizedToNormalized( - ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocaleCode()] + ['locale' => $this->_objectManager->get('Magento\Framework\Locale\ResolverInterface')->getLocale()] ); foreach ($cartData as $index => $data) { if (isset($data['qty'])) { diff --git a/app/code/Magento/Cms/Block/Adminhtml/Page/Edit/Tab/Design.php b/app/code/Magento/Cms/Block/Adminhtml/Page/Edit/Tab/Design.php index 0d639ce8483757c082e10fb37a79d1a2f63eda36..0e12b799444cd796892dfcf5f1892e780e368532 100644 --- a/app/code/Magento/Cms/Block/Adminhtml/Page/Edit/Tab/Design.php +++ b/app/code/Magento/Cms/Block/Adminhtml/Page/Edit/Tab/Design.php @@ -116,7 +116,7 @@ class Design extends \Magento\Backend\Block\Widget\Form\Generic implements ); $dateFormat = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ); $designFieldset->addField( diff --git a/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php b/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php index 8b37f3483531ead4075051e334aa860325af54d4..f6339dd68cd3149f38822875e82c25bcc15988e8 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Field/Datetime.php @@ -19,8 +19,8 @@ class Datetime extends \Magento\Config\Block\System\Config\Form\Field protected function _getElementHtml(AbstractElement $element) { $format = $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); - return $this->_localeDate->date(intval($element->getValue()))->toString($format); + return \IntlDateFormatter::formatObject($this->_localeDate->date(intval($element->getValue())), $format); } } diff --git a/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php b/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php index ad9dd87ccad09824b3783314589ac69731d6636f..73f77141771112a28c23e1cafb8a22dd7a97f508 100644 --- a/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php +++ b/app/code/Magento/Config/Block/System/Config/Form/Field/Notification.php @@ -20,8 +20,8 @@ class Notification extends \Magento\Config\Block\System\Config\Form\Field { $element->setValue($this->_cache->load('admin_notifications_lastcheck')); $format = $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); - return $this->_localeDate->date(intval($element->getValue()))->toString($format); + return \IntlDateFormatter::formatObject($this->_localeDate->date(intval($element->getValue())), $format); } } diff --git a/app/code/Magento/Cron/Model/Schedule.php b/app/code/Magento/Cron/Model/Schedule.php index 7b200e04b809e6ad47708362c79814064fad3a41..eeb13bde4cde959b646efe452c10db48b158da0b 100644 --- a/app/code/Magento/Cron/Model/Schedule.php +++ b/app/code/Magento/Cron/Model/Schedule.php @@ -114,11 +114,11 @@ class Schedule extends \Magento\Framework\Model\AbstractModel $dateWithTimezone = $this->timezone->date($time); - $match = $this->matchCronExpression($e[0], $dateWithTimezone->get(\Zend_Date::MINUTE)) - && $this->matchCronExpression($e[1], $dateWithTimezone->get(\Zend_Date::HOUR)) - && $this->matchCronExpression($e[2], $dateWithTimezone->get(\Zend_Date::DAY)) - && $this->matchCronExpression($e[3], $dateWithTimezone->get(\Zend_Date::MONTH)) - && $this->matchCronExpression($e[4], $dateWithTimezone->get(\Zend_Date::WEEKDAY)); + $match = $this->matchCronExpression($e[0], $dateWithTimezone->format('i')) + && $this->matchCronExpression($e[1], $dateWithTimezone->format('H')) + && $this->matchCronExpression($e[2], $dateWithTimezone->format('d')) + && $this->matchCronExpression($e[3], $dateWithTimezone->format('m')) + && $this->matchCronExpression($e[4], $dateWithTimezone->format('N')); return $match; } diff --git a/app/code/Magento/Cron/Test/Unit/Model/ScheduleTest.php b/app/code/Magento/Cron/Test/Unit/Model/ScheduleTest.php index d1dbcf1fdc201cd4ca0b4655dc6e911c92ec018e..a5678197291887d8de73ee75f918da7c80310d72 100644 --- a/app/code/Magento/Cron/Test/Unit/Model/ScheduleTest.php +++ b/app/code/Magento/Cron/Test/Unit/Model/ScheduleTest.php @@ -162,10 +162,6 @@ class ScheduleTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->setMethods(['date']) ->getMockForAbstractClass(); - $dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateInterface') - ->disableOriginalConstructor() - ->setMethods(['get']) - ->getMockForAbstractClass(); /** @var \Magento\Cron\Model\Schedule $model */ $model = $this->helper->getObject( @@ -179,13 +175,11 @@ class ScheduleTest extends \PHPUnit_Framework_TestCase $model->setScheduledAt($scheduledAt); $model->setCronExprArr($cronExprArr); if ($scheduledAt && $cronExprArr) { - $timezoneMock->expects($this->once())->method('date')->willReturn($dateMock); - $date = getdate(is_numeric($scheduledAt) ? $scheduledAt : strtotime($scheduledAt)); - $dateMock->expects($this->at(0))->method('get')->with(\Zend_Date::MINUTE)->willReturn($date['minutes']); - $dateMock->expects($this->at(1))->method('get')->with(\Zend_Date::HOUR)->willReturn($date['hours']); - $dateMock->expects($this->at(2))->method('get')->with(\Zend_Date::DAY)->willReturn($date['mday']); - $dateMock->expects($this->at(3))->method('get')->with(\Zend_Date::MONTH)->willReturn($date['mon']); - $dateMock->expects($this->at(4))->method('get')->with(\Zend_Date::WEEKDAY)->willReturn($date['wday']); + $date = is_numeric($scheduledAt) ? $scheduledAt : strtotime($scheduledAt); + $timezoneMock->expects($this->once()) + ->method('date') + ->with($date) + ->willReturn((new \DateTime())->setTimestamp($date)); } // 3. Run tested method diff --git a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php index c89fbd8b94ddcf14cd82224a78902e800fb53cc8..66510bd9522d6f05a8fe9e0e9e6849f624305a7b 100644 --- a/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php +++ b/app/code/Magento/CurrencySymbol/Model/System/Currencysymbol.php @@ -3,9 +3,10 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ - namespace Magento\CurrencySymbol\Model\System; +use Magento\Framework\Locale\Bundle\CurrencyBundle; + /** * Custom currency symbol model */ @@ -89,9 +90,9 @@ class Currencysymbol protected $_storeManager; /** - * @var \Magento\Framework\LocaleInterface + * @var \Magento\Framework\Locale\ResolverInterface */ - protected $_locale; + protected $localeResolver; /** * @var \Magento\Framework\App\Config\ReinitableConfigInterface @@ -129,7 +130,7 @@ class Currencysymbol $this->_configFactory = $configFactory; $this->_cacheTypeList = $cacheTypeList; $this->_storeManager = $storeManager; - $this->_locale = $localeResolver->getLocale(); + $this->localeResolver = $localeResolver; $this->_systemStore = $systemStore; $this->_eventManager = $eventManager; $this->_scopeConfig = $scopeConfig; @@ -196,13 +197,9 @@ class Currencysymbol $currentSymbols = $this->_unserializeStoreConfig(self::XML_PATH_CUSTOM_CURRENCY_SYMBOL); foreach ($allowedCurrencies as $code) { - if (!($symbol = $this->_locale->getTranslation($code, 'currencysymbol'))) { - $symbol = $code; - } - $name = $this->_locale->getTranslation($code, 'nametocurrency'); - if (!$name) { - $name = $code; - } + $currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies']; + $symbol = $currencies[$code][0] ?: $code; + $name = $currencies[$code][1] ?: $code; $this->_symbolsData[$code] = ['parentSymbol' => $symbol, 'displayName' => $name]; if (isset($currentSymbols[$code]) && !empty($currentSymbols[$code])) { diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php index 6467fe865e6db15c13c46a9bf3281ada2daff897..7e84b670e96cc42a1d0230f19dc8a52d8c487491 100644 --- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php +++ b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Newsletter.php @@ -192,7 +192,7 @@ class Newsletter extends \Magento\Backend\Block\Widget\Form\Generic implements T if ($subscriber->getChangeStatusAt()) { return $this->formatDate( $subscriber->getChangeStatusAt(), - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, + \IntlDateFormatter::MEDIUM, true ); } diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfo.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfo.php index 2ea02b24ab271ec0f4dd0648ae99eefc779051bb..891ba0e5fcad0cfd8153c0600ed705583a5b92a6 100644 --- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfo.php +++ b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfo.php @@ -133,12 +133,8 @@ class PersonalInfo extends \Magento\Backend\Block\Template { $createdAt = $this->getCustomer()->getCreatedAt(); try { - $date = $this->_localeDate->scopeDate( - $this->getCustomer()->getStoreId(), - $this->dateTime->toTimestamp($createdAt), - true - ); - return $this->formatDate($date, TimezoneInterface::FORMAT_TYPE_MEDIUM, true); + $date = $this->_localeDate->scopeDate($this->getCustomer()->getStoreId(), $createdAt, true); + return $this->formatDate($date, \IntlDateFormatter::MEDIUM, true); } catch (\Exception $e) { $this->_logger->critical($e); return ''; @@ -166,7 +162,7 @@ class PersonalInfo extends \Magento\Backend\Block\Template { return $this->formatDate( $this->getCustomer()->getCreatedAt(), - TimezoneInterface::FORMAT_TYPE_MEDIUM, + \IntlDateFormatter::MEDIUM, true ); } diff --git a/app/code/Magento/Customer/Block/Widget/Dob.php b/app/code/Magento/Customer/Block/Widget/Dob.php index 61d24dcc78e493c4adad33fecac516cca3a0bce9..5d272f753f732a8db5af008da3a293effa850786 100644 --- a/app/code/Magento/Customer/Block/Widget/Dob.php +++ b/app/code/Magento/Customer/Block/Widget/Dob.php @@ -160,7 +160,7 @@ class Dob extends AbstractWidget */ public function getDateFormat() { - return $this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_SHORT); + return $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); } /** diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 62790ea7352258c30889500f912bc8ebcccda42f..7fb85ee1caf5ab41cce6309d8843ccacd43f070b 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -981,8 +981,8 @@ class AccountManagement implements AccountManagementInterface $expirationPeriod = $this->customerModel->getResetPasswordLinkExpirationPeriod(); - $currentTimestamp = $this->dateTime->toTimestamp($this->dateTime->now()); - $tokenTimestamp = $this->dateTime->toTimestamp($rpTokenCreatedAt); + $currentTimestamp = (new \DateTime())->getTimestamp(); + $tokenTimestamp = (new \DateTime($rpTokenCreatedAt))->getTimestamp(); if ($tokenTimestamp > $currentTimestamp) { return true; } @@ -1016,7 +1016,9 @@ class AccountManagement implements AccountManagementInterface if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) { $customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId()); $customerSecure->setRpToken($passwordLinkToken); - $customerSecure->setRpTokenCreatedAt($this->dateTime->now()); + $customerSecure->setRpTokenCreatedAt( + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); $this->customerRepository->save($customer); } return true; diff --git a/app/code/Magento/Customer/Model/Customer.php b/app/code/Magento/Customer/Model/Customer.php index 67327f1012ebd9499b7d35c90962fa6551d88954..cb0e6f90dc16b29fbf8b0eac2641dcdc346ce61f 100644 --- a/app/code/Magento/Customer/Model/Customer.php +++ b/app/code/Magento/Customer/Model/Customer.php @@ -1113,7 +1113,7 @@ class Customer extends \Magento\Framework\Model\AbstractExtensibleModel { $date = $this->getCreatedAt(); if ($date) { - return $this->dateTime->toTimestamp($date); + return (new \DateTime($date))->getTimestamp(); } return null; } @@ -1278,8 +1278,8 @@ class Customer extends \Magento\Framework\Model\AbstractExtensibleModel $expirationPeriod = $this->getResetPasswordLinkExpirationPeriod(); - $currentTimestamp = $this->dateTime->toTimestamp($this->dateTime->now()); - $tokenTimestamp = $this->dateTime->toTimestamp($linkTokenCreatedAt); + $currentTimestamp = (new \DateTime())->getTimestamp(); + $tokenTimestamp = (new \DateTime($linkTokenCreatedAt))->getTimestamp(); if ($tokenTimestamp > $currentTimestamp) { return true; } diff --git a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php index 04d96b70c24802c4f263410bc5c0273be57bc2f1..d762fb121b6ab9a08f519fe82bfe86fcc9e5f3d4 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php +++ b/app/code/Magento/Customer/Model/Metadata/Form/AbstractData.php @@ -209,7 +209,7 @@ abstract class AbstractData if ($filterCode) { $filterClass = 'Magento\Framework\Data\Form\Filter\\' . ucfirst($filterCode); if ($filterCode == 'date') { - $filter = new $filterClass($this->_dateFilterFormat(), $this->_localeResolver->getLocale()); + $filter = new $filterClass($this->_dateFilterFormat(), $this->_localeResolver); } else { $filter = new $filterClass(); } @@ -229,7 +229,7 @@ abstract class AbstractData if (is_null($format)) { // get format if (is_null($this->_dateFilterFormat)) { - $this->_dateFilterFormat = \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT; + $this->_dateFilterFormat = \IntlDateFormatter::SHORT; } return $this->_localeDate->getDateFormat($this->_dateFilterFormat); } elseif ($format === false) { diff --git a/app/code/Magento/Customer/Model/Metadata/Form/Date.php b/app/code/Magento/Customer/Model/Metadata/Form/Date.php index 6e55f61a5d225b968120b3013a093e4c2103c5aa..1bcbb500b4ae2970943fcf30ebb264e0e3ac6ce2 100644 --- a/app/code/Magento/Customer/Model/Metadata/Form/Date.php +++ b/app/code/Magento/Customer/Model/Metadata/Form/Date.php @@ -127,13 +127,13 @@ class Date extends AbstractData case \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_TEXT: case \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_HTML: case \Magento\Customer\Model\Metadata\ElementFactory::OUTPUT_FORMAT_PDF: - $this->_dateFilterFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); + $this->_dateFilterFormat(\IntlDateFormatter::MEDIUM); break; } $value = $this->_applyOutputFilter($value); } - $this->_dateFilterFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $this->_dateFilterFormat(\IntlDateFormatter::SHORT); return $value; } diff --git a/app/code/Magento/Customer/Model/Resource/Customer.php b/app/code/Magento/Customer/Model/Resource/Customer.php index 9f87049ea88ebe00907e8b8efc17d14bdef6bc5f..9e14f1091ccb5954da6fd2663967ea7e466b2619 100644 --- a/app/code/Magento/Customer/Model/Resource/Customer.php +++ b/app/code/Magento/Customer/Model/Resource/Customer.php @@ -381,7 +381,9 @@ class Customer extends \Magento\Eav\Model\Entity\AbstractEntity { if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) { $customer->setRpToken($passwordLinkToken); - $customer->setRpTokenCreatedAt($this->dateTime->now()); + $customer->setRpTokenCreatedAt( + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); $this->saveAttribute($customer, 'rp_token'); $this->saveAttribute($customer, 'rp_token_created_at'); } diff --git a/app/code/Magento/Customer/Model/Visitor.php b/app/code/Magento/Customer/Model/Visitor.php index 158a5b3c238546ad4661472368b5e32356cbb3d3..4fc1c3a8026535a7f3bad674f5c1abea19b7fb16 100644 --- a/app/code/Magento/Customer/Model/Visitor.php +++ b/app/code/Magento/Customer/Model/Visitor.php @@ -138,7 +138,9 @@ class Visitor extends \Magento\Framework\Model\AbstractModel } if (!$this->getId()) { $this->setSessionId($this->session->getSessionId()); - $this->setLastVisitAt($this->dateTime->now()); + $this->setLastVisitAt( + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); $this->save(); $this->_eventManager->dispatch('visitor_init', ['visitor' => $this]); $this->session->setVisitorData($this->getData()); diff --git a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php index 59cab7a204ef9d1da849202b2101b6ec1319cf24..347ad1ee35a4f2e2816c1a42204aa6968d02740e 100644 --- a/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php +++ b/app/code/Magento/Customer/Test/Unit/Block/Widget/DobTest.php @@ -66,12 +66,10 @@ class DobTest extends \PHPUnit_Framework_TestCase $cache->expects($this->any())->method('getFrontend')->will($this->returnValue($frontendCache)); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $locale = $objectManager->getObject( - 'Magento\Framework\Locale', - ['locale' => \Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE] - ); $localeResolver = $this->getMock('\Magento\Framework\Locale\ResolverInterface'); - $localeResolver->expects($this->any())->method('getLocale')->will($this->returnValue($locale)); + $localeResolver->expects($this->any()) + ->method('getLocale') + ->willReturn(\Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE); $timezone = $objectManager->getObject( 'Magento\Framework\Stdlib\DateTime\Timezone', ['localeResolver' => $localeResolver] diff --git a/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php b/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php index 64783020a608c1f9213709a00b97532b64671117..bb7405773f84d1ce0d3c630c52fe49274717f7e3 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/AbstractDataTest.php @@ -148,7 +148,7 @@ class AbstractDataTest extends \PHPUnit_Framework_TestCase )->method( 'getDateFormat' )->with( - $this->equalTo(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT) + $this->equalTo(\IntlDateFormatter::SHORT) )->will( $this->returnValue($output) ); diff --git a/app/code/Magento/CustomerImportExport/Model/Import/Address.php b/app/code/Magento/CustomerImportExport/Model/Import/Address.php index 39fc75107758b08636300f3db1580be3173df63c..eb7a35225b27b91fad3f25ba8d7f5601c371703b 100644 --- a/app/code/Magento/CustomerImportExport/Model/Import/Address.php +++ b/app/code/Magento/CustomerImportExport/Model/Import/Address.php @@ -499,8 +499,8 @@ class Address extends AbstractCustomer $entityRow = [ 'entity_id' => $addressId, 'parent_id' => $customerId, - 'created_at' => $this->dateTime->now(), - 'updated_at' => $this->dateTime->now(), + 'created_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), + 'updated_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), ]; // attribute values diff --git a/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Toolbar/Buttons/Edit.php b/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Toolbar/Buttons/Edit.php index f2771c3694de21a58ce6167b680f574e655b742b..3e5fabf8992beca183eaf413856c1c53088d5dba 100644 --- a/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Toolbar/Buttons/Edit.php +++ b/app/code/Magento/DesignEditor/Block/Adminhtml/Editor/Toolbar/Buttons/Edit.php @@ -151,10 +151,9 @@ class Edit extends \Magento\Backend\Block\Widget\Button\SplitButton { $sourceChange = $this->_changeFactory->create(); $sourceChange->loadByThemeId($this->_themeContext->getEditableTheme()->getId()); - $dateMessage = $this->_localeDate->date( - $sourceChange->getChangeTime(), - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - )->toString(); + $dateMessage = \IntlDateFormatter::formatObject( + $this->_localeDate->date($sourceChange->getChangeTime()) + ); $message = __('Do you want to restore the version saved at %1?', $dateMessage); $data = [ diff --git a/app/code/Magento/Dhl/Model/Carrier.php b/app/code/Magento/Dhl/Model/Carrier.php index a4abc7b4909f3d30ac603168bb1c2ca0e8a51649..64f37e2b674b8fbde5e63cff1b70f16343a92cf9 100644 --- a/app/code/Magento/Dhl/Model/Carrier.php +++ b/app/code/Magento/Dhl/Model/Carrier.php @@ -973,7 +973,10 @@ class Carrier extends \Magento\Dhl\Model\AbstractDhl implements \Magento\Shippin $nodeBkgDetails = $nodeGetQuote->addChild('BkgDetails'); $nodeBkgDetails->addChild('PaymentCountryCode', $rawRequest->getOrigCountryId()); - $nodeBkgDetails->addChild('Date', $this->_dateTime->now(true)); + $nodeBkgDetails->addChild( + 'Date', + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); $nodeBkgDetails->addChild('ReadyTime', 'PT' . (int)(string)$this->getConfigData('ready_time') . 'H00M'); $nodeBkgDetails->addChild('DimensionUnit', $this->_getDimensionUnit()); diff --git a/app/code/Magento/Dhl/Setup/InstallData.php b/app/code/Magento/Dhl/Setup/InstallData.php index 0ff473fdec0392597aff1543012807c630b0ed38..ac0912d7105a51dac9439bf87b366f4a668c8aa4 100644 --- a/app/code/Magento/Dhl/Setup/InstallData.php +++ b/app/code/Magento/Dhl/Setup/InstallData.php @@ -6,7 +6,8 @@ namespace Magento\Dhl\Setup; -use Magento\Framework\Locale\ListsInterface; +use Magento\Framework\Locale\Bundle\DataBundle; +use Magento\Framework\Locale\ResolverInterface; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; @@ -19,18 +20,18 @@ class InstallData implements InstallDataInterface /** * Locale list * - * @var ListsInterface + * @var ResolverInterface */ - private $localeLists; + private $localeResolver; /** * Init * - * @param ListsInterface $localeLists + * @param ResolverInterface $localeResolver */ - public function __construct(ListsInterface $localeLists) + public function __construct(ResolverInterface $localeResolver) { - $this->localeLists = $localeLists; + $this->localeResolver = $localeResolver; } /** @@ -38,12 +39,9 @@ class InstallData implements InstallDataInterface */ public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { - $days = $this->localeLists->getTranslationList('days'); - - $days = array_keys($days['format']['wide']); - foreach ($days as $key => $value) { - $days[$key] = ucfirst($value); - } + $days = (new DataBundle())->get( + $this->localeResolver->getLocale() + )['calendar']['gregorian']['dayNames']['format']['abbreviated']; $select = $setup->getConnection()->select()->from( $setup->getTable('core_config_data'), @@ -54,7 +52,12 @@ class InstallData implements InstallDataInterface ); foreach ($setup->getConnection()->fetchAll($select) as $configRow) { - $row = ['value' => implode(',', array_intersect_key($days, array_flip(explode(',', $configRow['value']))))]; + $row = [ + 'value' => implode( + ',', + array_intersect_key(iterator_to_array($days), array_flip(explode(',', $configRow['value']))) + ) + ]; $setup->getConnection()->update( $setup->getTable('core_config_data'), $row, diff --git a/app/code/Magento/Directory/Block/Currency.php b/app/code/Magento/Directory/Block/Currency.php index b032eed0a1b7b111394098f4416ec5742b3e6270..b6d8217657a054f7c3e6bc003616852427cc3582 100644 --- a/app/code/Magento/Directory/Block/Currency.php +++ b/app/code/Magento/Directory/Block/Currency.php @@ -9,6 +9,8 @@ */ namespace Magento\Directory\Block; +use Magento\Framework\Locale\Bundle\CurrencyBundle as CurrencyBundle; + class Currency extends \Magento\Framework\View\Element\Template { /** @@ -22,9 +24,9 @@ class Currency extends \Magento\Framework\View\Element\Template protected $_postDataHelper; /** - * @var \Magento\Framework\LocaleInterface + * @var \Magento\Framework\Locale\ResolverInterface */ - protected $_locale; + protected $localeResolver; /** * @param \Magento\Framework\View\Element\Template\Context $context @@ -43,7 +45,7 @@ class Currency extends \Magento\Framework\View\Element\Template $this->_currencyFactory = $currencyFactory; $this->_postDataHelper = $postDataHelper; parent::__construct($context, $data); - $this->_locale = $localeResolver->getLocale(); + $this->localeResolver = $localeResolver; } /** @@ -78,7 +80,10 @@ class Currency extends \Magento\Framework\View\Element\Template foreach ($codes as $code) { if (isset($rates[$code])) { - $currencies[$code] = $this->_locale->getTranslation($code, 'nametocurrency'); + $allCurrencies = (new CurrencyBundle())->get( + $this->localeResolver->getLocale() + )['Currencies']; + $currencies[$code] = $allCurrencies[$code][1] ?: $code; } } } diff --git a/app/code/Magento/Directory/Model/Resource/Country/Collection.php b/app/code/Magento/Directory/Model/Resource/Country/Collection.php index 99e1306287d0aca4ac01e55693168ba93ec140cd..43baa2bf22a8c4df546c335b4ce943fd177be691 100644 --- a/app/code/Magento/Directory/Model/Resource/Country/Collection.php +++ b/app/code/Magento/Directory/Model/Resource/Country/Collection.php @@ -200,7 +200,7 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac $sort[$name] = $data['value']; } } - $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocaleCode()); + $this->_arrayUtils->ksortMultibyte($sort, $this->_localeResolver->getLocale()); foreach (array_reverse($this->_foregroundCountries) as $foregroundCountry) { $name = array_search($foregroundCountry, $sort); unset($sort[$name]); diff --git a/app/code/Magento/Directory/Model/Resource/Region.php b/app/code/Magento/Directory/Model/Resource/Region.php index 12a28ad0477551a5fe4cbd89098d7445c027a82d..d36b9bb519814852cefa2674abd66a044e09cc2b 100644 --- a/app/code/Magento/Directory/Model/Resource/Region.php +++ b/app/code/Magento/Directory/Model/Resource/Region.php @@ -63,7 +63,7 @@ class Region extends \Magento\Framework\Model\Resource\Db\AbstractDb $select = parent::_getLoadSelect($field, $value, $object); $adapter = $this->_getReadAdapter(); - $locale = $this->_localeResolver->getLocaleCode(); + $locale = $this->_localeResolver->getLocale(); $systemLocale = \Magento\Framework\AppInterface::DISTRO_LOCALE_CODE; $regionField = $adapter->quoteIdentifier($this->getMainTable() . '.' . $this->getIdFieldName()); @@ -102,7 +102,7 @@ class Region extends \Magento\Framework\Model\Resource\Db\AbstractDb protected function _loadByCountry($object, $countryId, $value, $field) { $adapter = $this->_getReadAdapter(); - $locale = $this->_localeResolver->getLocaleCode(); + $locale = $this->_localeResolver->getLocale(); $joinCondition = $adapter->quoteInto('rname.region_id = region.region_id AND rname.locale = ?', $locale); $select = $adapter->select()->from( ['region' => $this->getMainTable()] diff --git a/app/code/Magento/Directory/Model/Resource/Region/Collection.php b/app/code/Magento/Directory/Model/Resource/Region/Collection.php index 7fdb61efb5c16023b5bacb0cfd34a263ef271626..6474d480eaaaddbe613636c66989f2b06064141b 100644 --- a/app/code/Magento/Directory/Model/Resource/Region/Collection.php +++ b/app/code/Magento/Directory/Model/Resource/Region/Collection.php @@ -76,7 +76,7 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac protected function _initSelect() { parent::_initSelect(); - $locale = $this->_localeResolver->getLocaleCode(); + $locale = $this->_localeResolver->getLocale(); $this->addBindParam(':region_locale', $locale); $this->getSelect()->joinLeft( diff --git a/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php b/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php index 47e31d0b0ef8f59219b8b8f1fff2a8395ae362c3..bc7196634e0e80410fd37a4a665d5ec838f0e94b 100644 --- a/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php +++ b/app/code/Magento/Eav/Block/Adminhtml/Attribute/Edit/Main/AbstractMain.php @@ -202,7 +202,7 @@ abstract class AbstractMain extends \Magento\Backend\Block\Widget\Form\Generic ] ); - $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $fieldset->addField( 'default_value_date', 'date', diff --git a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php index 02bd473d196d37e76afdc28c345f334bc7168e22..124830186527cbb2dc6da670aee811abf1556156 100644 --- a/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php +++ b/app/code/Magento/Eav/Model/Attribute/Data/AbstractData.php @@ -255,7 +255,7 @@ abstract class AbstractData if (is_null($format)) { // get format if (is_null($this->_dateFilterFormat)) { - $this->_dateFilterFormat = \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT; + $this->_dateFilterFormat = \IntlDateFormatter::SHORT; } return $this->_localeDate->getDateFormat($this->_dateFilterFormat); } elseif ($format === false) { diff --git a/app/code/Magento/Eav/Model/Attribute/Data/Date.php b/app/code/Magento/Eav/Model/Attribute/Data/Date.php index b1ef1c3c84b35eb61667b8c14c18ff326ce0a5c6..8d59db8adf4606a0ea55bb1731320e72ee09fa27 100644 --- a/app/code/Magento/Eav/Model/Attribute/Data/Date.php +++ b/app/code/Magento/Eav/Model/Attribute/Data/Date.php @@ -138,13 +138,13 @@ class Date extends \Magento\Eav\Model\Attribute\Data\AbstractData case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_TEXT: case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_HTML: case \Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_PDF: - $this->_dateFilterFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); + $this->_dateFilterFormat(\IntlDateFormatter::MEDIUM); break; } $value = $this->_applyOutputFilter($value); } - $this->_dateFilterFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $this->_dateFilterFormat(\IntlDateFormatter::SHORT); return $value; } diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index 671b7a1d7bbe1a5a2a914aba5edd9e5cd3d3514d..5a2b8365a25204491b4c079f86ef3aca4768b3b6 100644 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -955,8 +955,7 @@ abstract class AbstractEntity extends \Magento\Framework\Model\Resource\Abstract } else { $value = $object->getData($attribute->getAttributeCode()); if ($attribute->getBackend()->getType() == 'datetime') { - $date = new \Magento\Framework\Stdlib\DateTime\Date($value, \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT); - $value = $date->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + $value = (new \DateTime($value))->format('Y-m-d H:i:s'); } $bind = [ 'attribute_id' => $attribute->getId(), diff --git a/app/code/Magento/Eav/Model/Entity/Attribute.php b/app/code/Magento/Eav/Model/Entity/Attribute.php index a7aa71ece91c365a1deed6d335178cc9f3e9dca3..ef74bb1e59e968598de052ba3c08707c67f402cd 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute.php @@ -248,22 +248,12 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im $hasDefaultValue = (string)$defaultValue != ''; if ($this->getBackendType() == 'decimal' && $hasDefaultValue) { - if (!\Zend_Locale_Format::isNumber( - $defaultValue, - ['locale' => $this->_localeResolver->getLocaleCode()] - ) - ) { - throw new EavException(__('Invalid default decimal value')); - } - - try { - $filter = new \Zend_Filter_LocalizedToNormalized( - ['locale' => $this->_localeResolver->getLocaleCode()] - ); - $this->setDefaultValue($filter->filter($defaultValue)); - } catch (\Exception $e) { + $numberFormatter = new \NumberFormatter($this->_localeResolver->getLocale(), \NumberFormatter::DECIMAL); + $defaultValue = $numberFormatter->parse($defaultValue); + if ($defaultValue === false) { throw new EavException(__('Invalid default decimal value')); } + $this->setDefaultValue($defaultValue); } if ($this->getBackendType() == 'datetime') { @@ -278,10 +268,10 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute\AbstractAttribute im // save default date value as timestamp if ($hasDefaultValue) { $format = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ); try { - $defaultValue = $this->_localeDate->date($defaultValue, $format, null, false)->toValue(); + $defaultValue = \IntlDateFormatter::formatObject(new \DateTime($defaultValue), $format); $this->setDefaultValue($defaultValue); } catch (\Exception $e) { throw new EavException(__('Invalid default date')); diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php index 11e927f5488d6f85a39cbff079ccae2d998a51e4..464d03acab2f9187d7e59e0acd0de17c4827dacc 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php @@ -61,7 +61,7 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke * string format used from input fields (all date input fields need apply locale settings) * int value can be declared in code (this meen whot we use valid date) * - * @param string|int $date + * @param string|int|\DateTime $date * @return string */ public function formatDate($date) @@ -70,21 +70,13 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke return null; } // unix timestamp given - simply instantiate date object - if (preg_match('/^[0-9]+$/', $date)) { - $date = new \Magento\Framework\Stdlib\DateTime\Date((int)$date); + if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) { + $date = new \DateTime('@' . $date); // international format - } elseif (preg_match('#^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$#', $date)) { - $zendDate = new \Magento\Framework\Stdlib\DateTime\Date(); - $date = $zendDate->setIso($date); + } elseif (!($date instanceof \DateTime)) { + $date = new \DateTime($date); // parse this date in current locale, do not apply GMT offset - } else { - $date = $this->_localeDate->date( - $date, - $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT), - null, - false - ); } - return $date->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + return $date->format('Y-m-d H:i:s'); } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php index b3c59efbb7887bcc4a13697a75ee661930164476..5e14ddca8729ee2299fc60b3c4dd28488d75eb10 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Created.php @@ -33,7 +33,10 @@ class Created extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacken { $attributeCode = $this->getAttribute()->getAttributeCode(); if ($object->isObjectNew() && is_null($object->getData($attributeCode))) { - $object->setData($attributeCode, $this->dateTime->now()); + $object->setData( + $attributeCode, + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); } return $this; diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php index af8e2613c91566962f081177bb27e634e0068f76..d889eb031c5cc33e6b43bd34522cf4e43c3302bd 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Backend/Time/Updated.php @@ -31,7 +31,10 @@ class Updated extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacken */ public function beforeSave($object) { - $object->setData($this->getAttribute()->getAttributeCode(), $this->dateTime->now()); + $object->setData( + $this->getAttribute()->getAttributeCode(), + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); return $this; } } diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/Datetime.php b/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/Datetime.php index 57f0b73b6c7589bc64f66324209ea3e63ffd4a54..715d8677614c86e3a1ec5b69d3900ec301467789 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/Datetime.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/Frontend/Datetime.php @@ -37,14 +37,13 @@ class Datetime extends \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFron { $data = ''; $value = parent::getValue($object); - $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); if ($value) { - try { - $data = $this->_localeDate->date($value, \Zend_Date::ISO_8601, null, false)->toString($format); - } catch (\Exception $e) { - $data = $this->_localeDate->date($value, null, null, false)->toString($format); - } + $data = $this->_localeDate->formatDateTime( + new \DateTime($value), + \IntlDateFormatter::MEDIUM, + \IntlDateFormatter::NONE + ); } return $data; diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DatetimeTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DatetimeTest.php index d9cfb312804b8fadd6a00ce876a810f89340b7f4..d7a86c6ad49db762af3009c042f1b378f31ff65f 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DatetimeTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/Frontend/DatetimeTest.php @@ -57,43 +57,14 @@ class DatetimeTest extends \PHPUnit_Framework_TestCase public function testGetValue() { $attributeValue = '11-11-2011'; - $dateFormat = 'dd-mm-yyyy'; + $date = new \DateTime($attributeValue); $object = new \Magento\Framework\Object(['datetime' => $attributeValue]); $this->attributeMock->expects($this->any())->method('getData')->with('frontend_input') ->will($this->returnValue('text')); - $this->localeDateMock->expects($this->once())->method('getDateFormat') - ->with(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM) - ->will($this->returnValue($dateFormat)); - $dateMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\DateInterface'); - $dateMock->expects($this->once())->method('toString')->with($dateFormat) - ->will($this->returnValue($attributeValue)); - $this->localeDateMock->expects($this->once())->method('date') - ->with($attributeValue, \Zend_Date::ISO_8601, null, false) - ->will($this->returnValue($dateMock)); - - $this->assertEquals($attributeValue, $this->model->getValue($object)); - } - - public function testGetValueWhenDateCannotBeRepresentedUsingIso8601() - { - $attributeValue = '11-11-2011'; - $dateFormat = 'dd-mm-yyyy'; - $object = new \Magento\Framework\Object(['datetime' => $attributeValue]); - $this->localeDateMock->expects($this->once())->method('getDateFormat') - ->with(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM) - ->will($this->returnValue($dateFormat)); - $this->attributeMock->expects($this->any())->method('getData')->with('frontend_input') - ->will($this->returnValue('text')); - - $dateMock = $this->getMock('\Magento\Framework\Stdlib\DateTime\DateInterface'); - $dateMock->expects($this->once())->method('toString')->with($dateFormat) - ->will($this->returnValue($attributeValue)); - $this->localeDateMock->expects($this->at(1))->method('date') - ->will($this->throwException(new \Exception('Wrong Date'))); - $this->localeDateMock->expects($this->at(2))->method('date') - ->with($attributeValue, null, null, false) - ->will($this->returnValue($dateMock)); + $this->localeDateMock->expects($this->once())->method('formatDateTime') + ->with($date, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE, null, null, null) + ->willReturn($attributeValue); $this->assertEquals($attributeValue, $this->model->getValue($object)); } diff --git a/app/code/Magento/GoogleAdwords/Model/Config/Source/Language.php b/app/code/Magento/GoogleAdwords/Model/Config/Source/Language.php index b3051af419642516ab85bd11c79cf8354beb0232..dbd69ac3d7611c1839b9d961e9668b1067ad938c 100644 --- a/app/code/Magento/GoogleAdwords/Model/Config/Source/Language.php +++ b/app/code/Magento/GoogleAdwords/Model/Config/Source/Language.php @@ -12,11 +12,6 @@ namespace Magento\GoogleAdwords\Model\Config\Source; */ class Language implements \Magento\Framework\Option\ArrayInterface { - /** - * @var \Magento\Framework\LocaleInterface - */ - protected $_locale; - /** * @var \Magento\GoogleAdwords\Helper\Data */ @@ -28,19 +23,14 @@ class Language implements \Magento\Framework\Option\ArrayInterface protected $_uppercaseFilter; /** - * Constructor - * - * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\GoogleAdwords\Helper\Data $helper * @param \Magento\GoogleAdwords\Model\Filter\UppercaseTitle $uppercaseFilter */ public function __construct( - \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\GoogleAdwords\Helper\Data $helper, \Magento\GoogleAdwords\Model\Filter\UppercaseTitle $uppercaseFilter ) { $this->_helper = $helper; - $this->_locale = $localeResolver->getLocale(); $this->_uppercaseFilter = $uppercaseFilter; } @@ -54,8 +44,8 @@ class Language implements \Magento\Framework\Option\ArrayInterface $languages = []; foreach ($this->_helper->getLanguageCodes() as $languageCode) { $localeCode = $this->_helper->convertLanguageCodeToLocaleCode($languageCode); - $translationForSpecifiedLanguage = $this->_locale->getTranslation($localeCode, 'language', $localeCode); - $translationForDefaultLanguage = $this->_locale->getTranslation($localeCode, 'language'); + $translationForSpecifiedLanguage = \Locale::getDisplayLanguage($localeCode, $localeCode); + $translationForDefaultLanguage = \Locale::getDisplayLanguage($localeCode); $label = sprintf( '%s / %s (%s)', diff --git a/app/code/Magento/GoogleShopping/Model/Attribute/DefaultAttribute.php b/app/code/Magento/GoogleShopping/Model/Attribute/DefaultAttribute.php index c9c68afd0fdca97caaa67ba2cce0c171f324ca24..0e54ab0a0300a58fb46275cab0d274affbcba0a0 100644 --- a/app/code/Magento/GoogleShopping/Model/Attribute/DefaultAttribute.php +++ b/app/code/Magento/GoogleShopping/Model/Attribute/DefaultAttribute.php @@ -72,11 +72,11 @@ class DefaultAttribute extends \Magento\GoogleShopping\Model\Attribute if ($productAttribute->getFrontendInput() == 'date' || $productAttribute->getBackendType() == 'date') { $value = $product->getData($productAttribute->getAttributeCode()); - if (empty($value) || !\Zend_Date::isDate($value, \Zend_Date::ISO_8601)) { + if (empty($value)) { return null; } - $date = new \Magento\Framework\Stdlib\DateTime\Date($value, \Zend_Date::ISO_8601); - $value = $date->toString(\Zend_Date::ATOM); + $date = new \DateTime($value); + $value = $date->format('c'); } else { $value = $productAttribute->getFrontend()->getValue($product); } diff --git a/app/code/Magento/GoogleShopping/Model/Attribute/SalePriceEffectiveDate.php b/app/code/Magento/GoogleShopping/Model/Attribute/SalePriceEffectiveDate.php index 494e7185eb277037d3213af27e6613495c08ca1f..56deb7a9945512a36f0f1903cd8e0a6eaa4e3df6 100644 --- a/app/code/Magento/GoogleShopping/Model/Attribute/SalePriceEffectiveDate.php +++ b/app/code/Magento/GoogleShopping/Model/Attribute/SalePriceEffectiveDate.php @@ -31,30 +31,30 @@ class SalePriceEffectiveDate extends \Magento\GoogleShopping\Model\Attribute\Def $toValue = $effectiveDateTo->getProductAttributeValue($product); $from = $to = null; - if (!empty($fromValue) && \Zend_Date::isDate($fromValue, \Zend_Date::ATOM)) { - $from = new \Magento\Framework\Stdlib\DateTime\Date($fromValue, \Zend_Date::ATOM); + if (!empty($fromValue)) { + $from = new \DateTime($fromValue); } - if (!empty($toValue) && \Zend_Date::isDate($toValue, \Zend_Date::ATOM)) { - $to = new \Magento\Framework\Stdlib\DateTime\Date($toValue, \Zend_Date::ATOM); + if (!empty($toValue)) { + $to = new \DateTime($toValue); } $dateString = null; // if we have from an to dates, and if these dates are correct - if (!is_null($from) && !is_null($to) && $from->isEarlier($to)) { - $dateString = $from->toString(\Zend_Date::ATOM) . '/' . $to->toString(\Zend_Date::ATOM); + if (!is_null($from) && !is_null($to) && $from < $to) { + $dateString = $from->format('Y-m-d H:i:s') . '/' . $to->format('Y-m-d H:i:s'); } // if we have only "from" date, send "from" day if (!is_null($from) && is_null($to)) { - $dateString = $from->toString('YYYY-MM-dd'); + $dateString = $from->format('Y-m-d'); } // if we have only "to" date, use "now" date for "from" if (is_null($from) && !is_null($to)) { - $from = new \Magento\Framework\Stdlib\DateTime\Date(); + $from = new \DateTime(); // if "now" date is earlier than "to" date - if ($from->isEarlier($to)) { - $dateString = $from->toString(\Zend_Date::ATOM) . '/' . $to->toString(\Zend_Date::ATOM); + if ($from < $to) { + $dateString = $from->format('Y-m-d H:i:s') . '/' . $to->format('Y-m-d H:i:s'); } } diff --git a/app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php b/app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php index 8aa42f3a82a756ac0b1d5958705e53351c121b59..4f0408598040781afb0783254bf0ff4fc15c447a 100644 --- a/app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php +++ b/app/code/Magento/ImportExport/Block/Adminhtml/Export/Filter.php @@ -78,7 +78,7 @@ class Filter extends \Magento\Backend\Block\Widget\Grid\Extended 'id' => $this->getFilterElementId($attribute->getAttributeCode()), 'class' => 'input-text input-text-range-date', 'date_format' => $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ), 'image' => $this->getViewFileUrl('images/grid-cal.png'), ]; diff --git a/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php b/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php index 8803d34fc3d7061be086a9d5ad8c2627ac41377b..cf771ea7cdddbcb2b56d3811ee82e77592538815 100644 --- a/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php +++ b/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEav.php @@ -147,11 +147,11 @@ abstract class AbstractEav extends \Magento\ImportExport\Model\Export\AbstractEn $to = array_shift($exportFilter[$attributeCode]); if (is_scalar($from) && !empty($from)) { - $date = $this->_localeDate->date($from, null, null, false)->toString('MM/dd/YYYY'); + $date = (new \DateTime($from))->format('m/d/Y'); $collection->addAttributeToFilter($attributeCode, ['from' => $date, 'date' => true]); } if (is_scalar($to) && !empty($to)) { - $date = $this->_localeDate->date($to, null, null, false)->toString('MM/dd/YYYY'); + $date = (new \DateTime($to))->format('m/d/Y'); $collection->addAttributeToFilter($attributeCode, ['to' => $date, 'date' => true]); } } diff --git a/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEntity.php b/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEntity.php index b700658b9f166aad7dc9ccfe3090f19f8a8d6c84..4ed67c3b79911df439eea70b54a538d6aa112b0a 100644 --- a/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEntity.php +++ b/app/code/Magento/ImportExport/Model/Export/Entity/AbstractEntity.php @@ -283,11 +283,11 @@ abstract class AbstractEntity $to = array_shift($exportFilter[$attrCode]); if (is_scalar($from) && !empty($from)) { - $date = $this->_localeDate->date($from, null, null, false)->toString('MM/dd/YYYY'); + $date = (new \DateTime($from))->format('m/d/Y'); $collection->addAttributeToFilter($attrCode, ['from' => $date, 'date' => true]); } if (is_scalar($to) && !empty($to)) { - $date = $this->_localeDate->date($to, null, null, false)->toString('MM/dd/YYYY'); + $date = (new \DateTime($to))->format('m/d/Y'); $collection->addAttributeToFilter($attrCode, ['to' => $date, 'date' => true]); } } diff --git a/app/code/Magento/Indexer/Model/Indexer.php b/app/code/Magento/Indexer/Model/Indexer.php index 71c3a6704cea450b6fcc0d2a22e1509cc89cbc1b..87d4dd8d5e81d9b3251acc8e0775fe1f392abf20 100644 --- a/app/code/Magento/Indexer/Model/Indexer.php +++ b/app/code/Magento/Indexer/Model/Indexer.php @@ -254,9 +254,9 @@ class Indexer extends \Magento\Framework\Object implements IndexerInterface if (!$this->getState()->getUpdated()) { return $this->getView()->getUpdated(); } - $indexerUpdatedDate = new \Magento\Framework\Stdlib\DateTime\Date($this->getState()->getUpdated()); - $viewUpdatedDate = new \Magento\Framework\Stdlib\DateTime\Date($this->getView()->getUpdated()); - if ($viewUpdatedDate->compare($indexerUpdatedDate) == 1) { + $indexerUpdatedDate = new \DateTime($this->getState()->getUpdated()); + $viewUpdatedDate = new \DateTime($this->getView()->getUpdated()); + if ($viewUpdatedDate > $indexerUpdatedDate) { return $this->getView()->getUpdated(); } } diff --git a/app/code/Magento/Indexer/Model/Mview/View/State.php b/app/code/Magento/Indexer/Model/Mview/View/State.php index 2a7a7364aef97105d11a56350917bb0abeb03bfc..b51d14289b3962887ac57761f3049332c6c60dd8 100644 --- a/app/code/Magento/Indexer/Model/Mview/View/State.php +++ b/app/code/Magento/Indexer/Model/Mview/View/State.php @@ -140,7 +140,7 @@ class State extends \Magento\Framework\Model\AbstractModel implements \Magento\F /** * Set state updated time * - * @param string|int|\Magento\Framework\Stdlib\DateTime\DateInterface $updated + * @param string|int|\DateTime $updated * @return $this */ public function setUpdated($updated) diff --git a/app/code/Magento/Integration/Model/Oauth/Token.php b/app/code/Magento/Integration/Model/Oauth/Token.php index d4b000518187dba43910309c9b1e9ed6e3c1ddf0..7757ed194ffd3e2a249cc5c83f67a97887e59613 100644 --- a/app/code/Magento/Integration/Model/Oauth/Token.php +++ b/app/code/Magento/Integration/Model/Oauth/Token.php @@ -259,7 +259,7 @@ class Token extends \Magento\Framework\Model\AbstractModel public function beforeSave() { if ($this->isObjectNew() && null === $this->getCreatedAt()) { - $this->setCreatedAt($this->_dateTime->now()); + $this->setCreatedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)); } parent::beforeSave(); return $this; diff --git a/app/code/Magento/Log/Block/Adminhtml/Customer/Edit/Tab/View/Status.php b/app/code/Magento/Log/Block/Adminhtml/Customer/Edit/Tab/View/Status.php index a79bb9e48809f4156cd131293bb23190f00f84c5..0a6d8f2b1c8255a3db0b538695d7b25d6ba2adb5 100644 --- a/app/code/Magento/Log/Block/Adminhtml/Customer/Edit/Tab/View/Status.php +++ b/app/code/Magento/Log/Block/Adminhtml/Customer/Edit/Tab/View/Status.php @@ -5,11 +5,9 @@ */ namespace Magento\Log\Block\Adminhtml\Customer\Edit\Tab\View; -use Magento\Framework\Stdlib\DateTime\TimezoneInterface; - /** * Class Status - * @package Magento\Log\Block\Adminhtml\Customer\Edit\Tab\View + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Status extends \Magento\Backend\Block\Template { @@ -104,7 +102,7 @@ class Status extends \Magento\Backend\Block\Template $log = $this->getCustomerLog(); $interval = $this->modelLog->getOnlineMinutesInterval(); if ($log->getLogoutAt() || - strtotime($this->dateTime->now()) - strtotime($log->getLastVisitAt()) > $interval * 60 + (new \DateTime())->getTimestamp() - strtotime($log->getLastVisitAt()) > $interval * 60 ) { return __('Offline'); } @@ -120,7 +118,7 @@ class Status extends \Magento\Backend\Block\Template { $date = $this->getCustomerLog()->getLoginAt(); if ($date) { - return $this->formatDate($date, TimezoneInterface::FORMAT_TYPE_MEDIUM, true); + return $this->formatDate($date, \IntlDateFormatter::MEDIUM, true); } return __('Never'); } @@ -133,7 +131,7 @@ class Status extends \Magento\Backend\Block\Template $date = $this->getCustomerLog()->getLoginAtTimestamp(); if ($date) { $date = $this->_localeDate->scopeDate($this->getCustomer()->getStoreId(), $date, true); - return $this->formatDate($date, TimezoneInterface::FORMAT_TYPE_MEDIUM, true); + return $this->formatDate($date, \IntlDateFormatter::MEDIUM, true); } return __('Never'); } diff --git a/app/code/Magento/Log/Model/Customer.php b/app/code/Magento/Log/Model/Customer.php index 2272c261901f11ce1f3df3e61dbc48a1d5b6ad79..00eb53e17253721a9925c43839cf34b8ca21e58c 100644 --- a/app/code/Magento/Log/Model/Customer.php +++ b/app/code/Magento/Log/Model/Customer.php @@ -81,7 +81,7 @@ class Customer extends \Magento\Framework\Model\AbstractModel { $loginAt = $this->getLoginAt(); if ($loginAt) { - return $this->dateTime->toTimestamp($loginAt); + return (new \DateTime($loginAt))->getTimestamp(); } return null; diff --git a/app/code/Magento/Log/Model/Visitor.php b/app/code/Magento/Log/Model/Visitor.php index ddd051f7ba5c3703625e49e65ac9510caefe296c..99f9ff81530b7e25d732a8d805eb9b4500be7ea1 100644 --- a/app/code/Magento/Log/Model/Visitor.php +++ b/app/code/Magento/Log/Model/Visitor.php @@ -153,7 +153,7 @@ class Visitor extends \Magento\Framework\Model\AbstractModel public function getFirstVisitAt() { if (!$this->hasData('first_visit_at')) { - $this->setData('first_visit_at', $this->dateTime->now()); + $this->setData('first_visit_at', (new \DateTime())->getTimestamp()); } return $this->getData('first_visit_at'); } @@ -166,7 +166,7 @@ class Visitor extends \Magento\Framework\Model\AbstractModel public function getLastVisitAt() { if (!$this->hasData('last_visit_at')) { - $this->setData('last_visit_at', $this->dateTime->now()); + $this->setData('last_visit_at', (new \DateTime())->getTimestamp()); } return $this->getData('last_visit_at'); } @@ -184,7 +184,7 @@ class Visitor extends \Magento\Framework\Model\AbstractModel $visitor = $observer->getEvent()->getVisitor(); $this->setData($visitor->getData()); $this->initServerData(); - $this->setFirstVisitAt($this->dateTime->now()); + $this->setFirstVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)); $this->setIsNewVisitor(true); $this->save(); $visitor->setData($this->getData()); @@ -206,7 +206,9 @@ class Visitor extends \Magento\Framework\Model\AbstractModel $this->setData($visitor->getData()); if ($this->getId() && $this->getVisitorId()) { $this->initServerData(); - $this->setLastVisitAt($this->dateTime->now()); + $this->setLastVisitAt( + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ); $this->save(); $visitor->setData($this->getData()); } diff --git a/app/code/Magento/Log/Test/Unit/Block/Adminhtml/Customer/Edit/Tab/View/StatusTest.php b/app/code/Magento/Log/Test/Unit/Block/Adminhtml/Customer/Edit/Tab/View/StatusTest.php index 51434ab1b91daf5422c0e4afcbe28961fde4b580..c155c22aca514c592d5a87f4b04c3d99ef491e35 100644 --- a/app/code/Magento/Log/Test/Unit/Block/Adminhtml/Customer/Edit/Tab/View/StatusTest.php +++ b/app/code/Magento/Log/Test/Unit/Block/Adminhtml/Customer/Edit/Tab/View/StatusTest.php @@ -77,7 +77,7 @@ class StatusTest extends \PHPUnit_Framework_TestCase $backendSession->expects($this->any())->method('getCustomerData')->will($this->returnValue($customerData)); $this->localeDate = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\Timezone') - ->setMethods(['scopeDate', 'formatDate', 'getDefaultTimezonePath']) + ->setMethods(['scopeDate', 'formatDateTime', 'getDefaultTimezonePath']) ->disableOriginalConstructor()->getMock(); $this->localeDate->expects($this->any())->method('getDefaultTimezonePath') ->will($this->returnValue('path/to/default/timezone')); @@ -126,7 +126,7 @@ class StatusTest extends \PHPUnit_Framework_TestCase { $date = date('Y-m-d H:i:s'); $this->customerLog->expects($this->any())->method('getLoginAt')->will($this->returnValue($date)); - $this->localeDate->expects($this->once())->method('formatDate')->will($this->returnValue($date)); + $this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue($date)); $this->assertEquals($date, $this->block->getLastLoginDate()); } @@ -141,7 +141,7 @@ class StatusTest extends \PHPUnit_Framework_TestCase $time = strtotime($date); $this->localeDate->expects($this->once())->method('scopeDate')->will($this->returnValue($date)); - $this->localeDate->expects($this->once())->method('formatDate')->will($this->returnValue($date)); + $this->localeDate->expects($this->once())->method('formatDateTime')->will($this->returnValue($date)); $this->customerLog->expects($this->any())->method('getLoginAtTimestamp')->will($this->returnValue($time)); $this->assertEquals($date, $this->block->getStoreLastLoginDate()); diff --git a/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php b/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php index ad2173013629dd4dca84b16c3c1739669bcefa34..79e8d2bee271fd48e1e5b4854aa768cfae68c73a 100644 --- a/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php +++ b/app/code/Magento/Log/Test/Unit/Model/VisitorTest.php @@ -122,14 +122,12 @@ class VisitorTest extends \PHPUnit_Framework_TestCase public function testGetFirstVisitAt() { $time = time(); - $this->dateTime->expects($this->once())->method('now')->will($this->returnValue($time)); $this->assertEquals($time, $this->visitor->getFirstVisitAt()); } public function testGetLastVisitAt() { $time = time(); - $this->dateTime->expects($this->once())->method('now')->will($this->returnValue($time)); $this->assertEquals($time, $this->visitor->getLastVisitAt()); } diff --git a/app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit/Form.php b/app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit/Form.php index 924206f42ec41db8f96e3a404efdc570c31f5402..b590aa30c731f0a90799f55bee4a6926feeab409 100644 --- a/app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit/Form.php +++ b/app/code/Magento/Newsletter/Block/Adminhtml/Queue/Edit/Form.php @@ -78,10 +78,10 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic ); $dateFormat = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); $timeFormat = $this->_localeDate->getTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); if ($queue->getQueueStatus() == \Magento\Newsletter\Model\Queue::STATUS_NEVER) { @@ -157,7 +157,7 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic $form->getElement( 'date' )->setValue( - $this->_localeDate->date($queue->getQueueStartAt(), \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + $this->_localeDate->date(new \DateTime($queue->getQueueStartAt())) ); } diff --git a/app/code/Magento/Newsletter/Model/Queue.php b/app/code/Magento/Newsletter/Model/Queue.php index 72239c7dcfabd57bc466a3773e292e719169dfbf..05a4ef51bc9ef698ae2ad71add8caf14dd71999f 100644 --- a/app/code/Magento/Newsletter/Model/Queue.php +++ b/app/code/Magento/Newsletter/Model/Queue.php @@ -87,11 +87,6 @@ class Queue extends \Magento\Email\Model\AbstractTemplate */ protected $_date; - /** - * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface - */ - protected $_localeDate; - /** * Problem factory * @@ -134,7 +129,6 @@ class Queue extends \Magento\Email\Model\AbstractTemplate \Magento\Store\Model\App\Emulation $appEmulation, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Newsletter\Model\Template\Filter $templateFilter, - \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Stdlib\DateTime\DateTime $date, \Magento\Newsletter\Model\TemplateFactory $templateFactory, \Magento\Newsletter\Model\ProblemFactory $problemFactory, @@ -145,7 +139,6 @@ class Queue extends \Magento\Email\Model\AbstractTemplate parent::__construct($context, $design, $registry, $appEmulation, $storeManager, $data); $this->_templateFilter = $templateFilter; $this->_date = $date; - $this->_localeDate = $localeDate; $this->_templateFactory = $templateFactory; $this->_problemFactory = $problemFactory; $this->_subscribersCollection = $subscriberCollectionFactory->create(); @@ -184,10 +177,7 @@ class Queue extends \Magento\Email\Model\AbstractTemplate if (is_null($startAt) || $startAt == '') { $this->setQueueStartAt(null); } else { - $format = $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM - ); - $time = $this->_localeDate->date($startAt, $format)->getTimestamp(); + $time = (new \DateTime($startAt))->getTimestamp(); $this->setQueueStartAt($this->_date->gmtDate(null, $time)); } return $this; diff --git a/app/code/Magento/Payment/Block/Info/Cc.php b/app/code/Magento/Payment/Block/Info/Cc.php index 0cb99fe22f0d8ffe764746265dabaaff90ae459f..bd92161c86834c161277851a5895e8d86d9152a1 100644 --- a/app/code/Magento/Payment/Block/Info/Cc.php +++ b/app/code/Magento/Payment/Block/Info/Cc.php @@ -73,13 +73,12 @@ class Cc extends \Magento\Payment\Block\Info /** * Retrieve CC expiration date * - * @return \Magento\Framework\Stdlib\DateTime\Date + * @return \DateTime */ public function getCcExpDate() { - $date = $this->_localeDate->date(0); - $date->setYear($this->getInfo()->getCcExpYear()); - $date->setMonth($this->getInfo()->getCcExpMonth()); + $date = new \DateTime('now', new \DateTimeZone($this->_localeDate->getConfigTimezone())); + $date->setDate($this->getInfo()->getCcExpYear(), $this->getInfo()->getCcExpMonth(), $date->format('d')); return $date; } diff --git a/app/code/Magento/Payment/Model/Config.php b/app/code/Magento/Payment/Model/Config.php index a36c3dff9ec978b8ab3ac436079b267165f522eb..62a196bfce79f0b267fea1af1edc2cbf5dd35097 100644 --- a/app/code/Magento/Payment/Model/Config.php +++ b/app/code/Magento/Payment/Model/Config.php @@ -5,6 +5,7 @@ */ namespace Magento\Payment\Model; +use Magento\Framework\Locale\Bundle\DataBundle; use Magento\Payment\Model\Method\AbstractMethod; use Magento\Store\Model\ScopeInterface; @@ -40,9 +41,9 @@ class Config /** * Locale model * - * @var \Magento\Framework\Locale\ListsInterface + * @var \Magento\Framework\Locale\ResolverInterface */ - protected $_localeLists; + protected $localeResolver; /** * Payment method factory @@ -63,21 +64,21 @@ class Config * * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Payment\Model\Method\Factory $paymentMethodFactory - * @param \Magento\Framework\Locale\ListsInterface $localeLists + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\Config\DataInterface $dataStorage * @param \Magento\Framework\Stdlib\DateTime\DateTime $date */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Payment\Model\Method\Factory $paymentMethodFactory, - \Magento\Framework\Locale\ListsInterface $localeLists, + \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Config\DataInterface $dataStorage, \Magento\Framework\Stdlib\DateTime\DateTime $date ) { $this->_scopeConfig = $scopeConfig; $this->_dataStorage = $dataStorage; $this->_paymentMethodFactory = $paymentMethodFactory; - $this->_localeLists = $localeLists; + $this->localeResolver = $localeResolver; $this->_date = $date; } @@ -139,9 +140,12 @@ class Config */ public function getMonths() { - $data = $this->_localeLists->getTranslationList('month'); - foreach ($data as $key => $value) { - $monthNum = $key < 10 ? '0' . $key : $key; + $data = []; + $months = (new DataBundle())->get( + $this->localeResolver->getLocale() + )['calendar']['gregorian']['monthNames']['format']['wide']; + foreach ($months as $key => $value) { + $monthNum = ++$key < 10 ? '0' . $key : $key; $data[$key] = $monthNum . ' - ' . $value; } return $data; diff --git a/app/code/Magento/Payment/Model/Method/Cc.php b/app/code/Magento/Payment/Model/Method/Cc.php index 8cc8dd3632fe4bd13bbc41028f8de672bc66362a..23e7dfda59a9b40a4da2e115d01deb1ff1017307 100644 --- a/app/code/Magento/Payment/Model/Method/Cc.php +++ b/app/code/Magento/Payment/Model/Method/Cc.php @@ -285,14 +285,9 @@ class Cc extends \Magento\Payment\Model\Method\AbstractMethod */ protected function _validateExpDate($expYear, $expMonth) { - $date = $this->_localeDate->date(); - if (!$expYear || !$expMonth || $date->compareYear( - $expYear - ) == 1 || $date->compareYear( - $expYear - ) == 0 && $date->compareMonth( - $expMonth - ) == 1 + $date = new \DateTime(); + if (!$expYear || !$expMonth || (int)$date->format('Y') > $expYear + || (int)$date->format('Y') == $expYear && (int)$date->format('m') > $expMonth ) { return false; } diff --git a/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php b/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php index 233b554d435344fd1817d4b43cb3b545055d6c08..98760f01eacc72e2c5536061b47d90dc130638dc 100644 --- a/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php +++ b/app/code/Magento/Payment/Test/Unit/Block/Info/CcTest.php @@ -139,29 +139,12 @@ class CcTest extends \PHPUnit_Framework_TestCase ->method('getCcExpYear')->will($this->returnValue($ccExpYear)); $this->model->setData('info', $paymentInfo); - $date = $this->getMock( - 'Magento\Framework\Stdlib\DateTime\TimezoneInterface', - [ - 'setYear', 'getYear', 'setMonth', 'getMonth', 'getDefaultTimezonePath', 'getDefaultTimezone', - 'getDateFormat', 'getDateFormatWithLongYear', 'getTimeFormat', 'getDateTimeFormat', 'date', - 'scopeDate', 'utcDate', 'scopeTimeStamp', 'formatDate', 'formatTime', 'getConfigTimezone', - 'isScopeDateInInterval' - ], - [], - '', - false - ); - $date->expects($this->any()) - ->method('getYear') - ->willReturn($ccExpYear); - $date->expects($this->any()) - ->method('getMonth') - ->willReturn($ccExpMonth); - $this->localeDate->expects($this->any()) - ->method('date') - ->will($this->returnValue($date)); - $this->assertEquals($ccExpYear, $this->model->getCcExpDate()->getYear()); - $this->assertEquals($ccExpMonth, $this->model->getCcExpDate()->getMonth()); + $this->localeDate->expects($this->exactly(2)) + ->method('getConfigTimezone') + ->willReturn('America/Los_Angeles'); + + $this->assertEquals($ccExpYear, $this->model->getCcExpDate()->format('Y')); + $this->assertEquals($ccExpMonth, $this->model->getCcExpDate()->format('m')); } /** diff --git a/app/code/Magento/Payment/Test/Unit/Model/ConfigTest.php b/app/code/Magento/Payment/Test/Unit/Model/ConfigTest.php index cd16afc559a683ad23790e47b6dc9201b5521afc..ee549bebbe29c8678ba693e4b878b726b5851010 100644 --- a/app/code/Magento/Payment/Test/Unit/Model/ConfigTest.php +++ b/app/code/Magento/Payment/Test/Unit/Model/ConfigTest.php @@ -27,8 +27,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Payment\Model\Method\Factory|\PHPUnit_Framework_MockObject_MockObject */ protected $paymentMethodFactory; - /** @var \Magento\Framework\Locale\ListsInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $localeLists; + /** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $localeResolver; /** @var \Magento\Framework\Config\DataInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $dataStorage; @@ -55,8 +55,18 @@ class ConfigTest extends \PHPUnit_Framework_TestCase * @var array */ protected $monthList = [ - 1 => 'Marsabruary', - 11 => 'Venusly', + 1 => 'January', + 'February', + 'March', + 'April', + 'May', + 'June', + 'July', + 'August', + 'September', + 'October', + 'November', + 'December', ]; /** @@ -65,8 +75,18 @@ class ConfigTest extends \PHPUnit_Framework_TestCase * @var array */ protected $expectedMonthList = [ - 1 => '01 - Marsabruary', - 11 => '11 - Venusly', + 1 => '01 - January', + '02 - February', + '03 - March', + '04 - April', + '05 - May', + '06 - June', + '07 - July', + '08 - August', + '09 - September', + '10 - October', + '11 - November', + '12 - December', ]; /** @@ -84,7 +104,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase false ); $this->paymentMethodFactory = $this->getMock('Magento\Payment\Model\Method\Factory', [], [], '', false); - $this->localeLists = $this->getMock('Magento\Framework\Locale\ListsInterface', [], [], '', false); + $this->localeResolver = $this->getMock('Magento\Framework\Locale\ResolverInterface', [], [], '', false); $this->dataStorage = $this->getMock('Magento\Framework\Config\DataInterface', [], [], '', false); $this->date = $this->getMock('Magento\Framework\Stdlib\DateTime\DateTime', [], [], '', false); @@ -94,7 +114,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase [ 'scopeConfig' => $this->scopeConfig, 'paymentMethodFactory' => $this->paymentMethodFactory, - 'localeLists' => $this->localeLists, + 'localeResolver' => $this->localeResolver, 'dataStorage' => $this->dataStorage, 'date' => $this->date ] @@ -161,9 +181,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetMonths() { - $this->localeLists->expects($this->once())->method('getTranslationList')->with('month')->will( - $this->returnValue($this->monthList) - ); + $this->localeResolver->expects($this->once())->method('getLocale')->willReturn('en_US'); $this->assertEquals($this->expectedMonthList, $this->config->getMonths()); } diff --git a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php index fa7025f4ae385ac75a07874571b5919a7b3bc2b2..b56638fcbd9f68ca8ca0dfa040494b5f710c9b6b 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Config/Form/Field/YtdStart.php @@ -23,7 +23,7 @@ class YtdStart extends \Magento\Config\Block\System\Config\Form\Field { $_months = []; for ($i = 1; $i <= 12; $i++) { - $_months[$i] = $this->_localeDate->date(mktime(null, null, null, $i))->get(\Zend_Date::MONTH_NAME); + $_months[$i] = $this->_localeDate->date(mktime(null, null, null, $i))->format('m'); } $_days = []; diff --git a/app/code/Magento/Reports/Block/Adminhtml/Filter/Form.php b/app/code/Magento/Reports/Block/Adminhtml/Filter/Form.php index 48e968de6798c0e2c1191c4d1eff1af216ff1b1b..ebb83d33ff59e4793fe68abc806ad30e7fd9a8e3 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Filter/Form.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Filter/Form.php @@ -120,7 +120,7 @@ class Form extends \Magento\Backend\Block\Widget\Form\Generic $form->setHtmlIdPrefix($htmlIdPrefix); $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Filter')]); - $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $fieldset->addField('store_ids', 'hidden', ['name' => 'store_ids']); diff --git a/app/code/Magento/Reports/Block/Adminhtml/Grid.php b/app/code/Magento/Reports/Block/Adminhtml/Grid.php index ffe52417938c1a70831f6e7c517b0f5615ae7526..5a09854e7c076d98bf3ea5c7587bc4ea5bc8a5dc 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Grid.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Grid.php @@ -92,14 +92,22 @@ class Grid extends \Magento\Backend\Block\Widget\Grid if (!isset($data['report_from'])) { // getting all reports from 2001 year - $date = new \Magento\Framework\Stdlib\DateTime\Date(mktime(0, 0, 0, 1, 1, 2001)); - $data['report_from'] = $date->toString($this->_localeDate->getDateFormat('short')); + $date = new \DateTime('@' . mktime(0, 0, 0, 1, 1, 2001)); + $data['report_from'] = $this->_localeDate->formatDateTime( + $date, + \IntlDateFormatter::SHORT, + \IntlDateFormatter::NONE + ); } if (!isset($data['report_to'])) { // getting all reports from 2001 year - $date = new \Magento\Framework\Stdlib\DateTime\Date(); - $data['report_to'] = $date->toString($this->_localeDate->getDateFormat('short')); + $date = new \DateTime(); + $data['report_to'] = $this->_localeDate->formatDateTime( + $date, + \IntlDateFormatter::SHORT, + \IntlDateFormatter::NONE + ); } $this->_setFilterValues($data); @@ -121,11 +129,10 @@ class Grid extends \Magento\Backend\Block\Widget\Grid try { $from = $this->_localeDate->date( $this->getFilter('report_from'), - \Zend_Date::DATE_SHORT, null, false ); - $to = $this->_localeDate->date($this->getFilter('report_to'), \Zend_Date::DATE_SHORT, null, false); + $to = $this->_localeDate->date($this->getFilter('report_to'), null, false); $collection->setInterval($from, $to); } catch (\Exception $e) { @@ -281,7 +288,7 @@ class Grid extends \Magento\Backend\Block\Widget\Grid */ public function getDateFormat() { - return $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + return $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); } /** diff --git a/app/code/Magento/Reports/Block/Adminhtml/Sales/Grid/Column/Renderer/Date.php b/app/code/Magento/Reports/Block/Adminhtml/Sales/Grid/Column/Renderer/Date.php index e6beaf64c46af0227697fa6c3a3e9b2af000fdee..35767de5d79cfb72b72223283c411d572ad8ba8b 100644 --- a/app/code/Magento/Reports/Block/Adminhtml/Sales/Grid/Column/Renderer/Date.php +++ b/app/code/Magento/Reports/Block/Adminhtml/Sales/Grid/Column/Renderer/Date.php @@ -5,6 +5,8 @@ */ namespace Magento\Reports\Block\Adminhtml\Sales\Grid\Column\Renderer; +use Magento\Framework\Locale\Bundle\DataBundle; + /** * Adminhtml grid item renderer date */ @@ -35,20 +37,22 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Date if (!$format) { if (is_null(self::$_format)) { try { - $localeCode = $this->_localeResolver->getLocaleCode(); - $localeData = new \Zend_Locale_Data(); + $formats = (new DataBundle())->get( + $this->_localeResolver->getLocale() + )['calendar']['gregorian']['availableFormats']; + switch ($this->getColumn()->getPeriodType()) { case 'month': - self::$_format = $localeData->getContent($localeCode, 'dateitem', 'yM'); + self::$_format = $formats['yM']; break; case 'year': - self::$_format = $localeData->getContent($localeCode, 'dateitem', 'y'); + self::$_format = $formats['y']; break; default: self::$_format = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); break; } @@ -68,6 +72,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Date */ public function render(\Magento\Framework\Object $row) { + //@todo: check this logic manually if ($data = $row->getData($this->getColumn()->getIndex())) { switch ($this->getColumn()->getPeriodType()) { case 'month': @@ -83,33 +88,33 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Date $format = $this->_getFormat(); try { - $data = $this->getColumn()->getGmtoffset() ? $this->_localeDate->date( - $data, - $dateFormat - )->toString( - $format - ) : $this->_localeDate->date( - $data, - \Zend_Date::ISO_8601, - null, - false - )->toString( - $format - ); + $data = $this->getColumn()->getGmtoffset() + ? \IntlDateFormatter::formatObject( + $this->_localeDate->date(new \DateTime($data)), + $format + ) + : \IntlDateFormatter::formatObject( + $this->_localeDate->date( + new \DateTime($data), + null, + false + ), + $format + ); } catch (\Exception $e) { - $data = $this->getColumn()->getTimezone() ? $this->_localeDate->date( - $data, - $dateFormat - )->toString( - $format - ) : $this->_localeDate->date( - $data, - $dateFormat, - null, - false - )->toString( - $format - ); + $data = $this->getColumn()->getTimezone() + ? \IntlDateFormatter::formatObject( + $this->_localeDate->date(new \DateTime($data)), + $format + ) + : \IntlDateFormatter::formatObject( + $this->_localeDate->date( + new \DateTime($data), + null, + false + ), + $format + ); } return $data; } diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php index 3fd529b3fb3b9f94777427a9535fe5c4931bb18d..950022b1649bb60f8ffae60c9e540142f172e762 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php @@ -124,16 +124,14 @@ abstract class AbstractReport extends \Magento\Backend\App\Action $flag = $this->_objectManager->create('Magento\Reports\Model\Flag')->setReportFlagCode($flagCode)->loadSelf(); $updatedAt = 'undefined'; if ($flag->hasData()) { - $date = new \Magento\Framework\Stdlib\DateTime\Date( - $flag->getLastUpdate(), - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); - $updatedAt = $this->_objectManager->get( - 'Magento\Framework\Stdlib\DateTime\TimezoneInterface' - )->scopeDate( - 0, - $date, - true + $updatedAt = \IntlDateFormatter::formatObject( + $this->_objectManager->get( + 'Magento\Framework\Stdlib\DateTime\TimezoneInterface' + )->scopeDate( + 0, + $flag->getLastUpdate(), + true + ) ); } diff --git a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php index e9a7af224129c85700d9c2f3550b1acbc744e5d4..e4e5c4e651095eb8a147b5d1ccc88522bd6038ef 100644 --- a/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php +++ b/app/code/Magento/Reports/Controller/Adminhtml/Report/Statistics/RefreshRecent.php @@ -18,9 +18,9 @@ class RefreshRecent extends \Magento\Reports\Controller\Adminhtml\Report\Statist { try { $collectionsNames = $this->_getCollectionNames(); - /** @var \Magento\Framework\Stdlib\DateTime\DateInterface $currentDate */ + /** @var \DateTime $currentDate */ $currentDate = $this->_objectManager->get('Magento\Framework\Stdlib\DateTime\TimezoneInterface')->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->modify('-25 hours'); foreach ($collectionsNames as $collectionName) { $this->_objectManager->create($collectionName)->aggregate($date); } diff --git a/app/code/Magento/Reports/Helper/Data.php b/app/code/Magento/Reports/Helper/Data.php index 7553ee48de465cc896f4dc1d07015272b579be43..50856d3b37cde36d9b1066dcc9aa5d608a004b9b 100644 --- a/app/code/Magento/Reports/Helper/Data.php +++ b/app/code/Magento/Reports/Helper/Data.php @@ -53,44 +53,23 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper return $intervals; } - $start = new \Magento\Framework\Stdlib\DateTime\Date($from, \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT); - - if ($period == self::REPORT_PERIOD_TYPE_DAY) { - $dateStart = $start; - } - - if ($period == self::REPORT_PERIOD_TYPE_MONTH) { - $dateStart = new \Magento\Framework\Stdlib\DateTime\Date( - date("Y-m", $start->getTimestamp()), - DateTime::DATE_INTERNAL_FORMAT - ); - } - - if ($period == self::REPORT_PERIOD_TYPE_YEAR) { - $dateStart = new \Magento\Framework\Stdlib\DateTime\Date( - date("Y", $start->getTimestamp()), - DateTime::DATE_INTERNAL_FORMAT - ); - } - - $dateEnd = new \Magento\Framework\Stdlib\DateTime\Date($to, DateTime::DATE_INTERNAL_FORMAT); - - while ($dateStart->compare($dateEnd) <= 0) { + $dateStart = new \DateTime($from); + $dateEnd = new \DateTime($to); + while ($dateStart->diff($dateEnd)->invert = 0) { switch ($period) { case self::REPORT_PERIOD_TYPE_DAY: - $t = $dateStart->toString('yyyy-MM-dd'); - $dateStart->addDay(1); + $intervals[] = $dateStart->format('Y-m-d'); + $dateStart->add(new \DateInterval('P1D')); break; case self::REPORT_PERIOD_TYPE_MONTH: - $t = $dateStart->toString('yyyy-MM'); - $dateStart->addMonth(1); + $intervals[] = $dateStart->format('Y-m'); + $dateStart->add(new \DateInterval('P1M')); break; case self::REPORT_PERIOD_TYPE_YEAR: - $t = $dateStart->toString('yyyy'); - $dateStart->addYear(1); + $intervals[] = $dateStart->format('Y'); + $dateStart->add(new \DateInterval('P1Y')); break; } - $intervals[] = $t; } return $intervals; } diff --git a/app/code/Magento/Reports/Model/DateFactory.php b/app/code/Magento/Reports/Model/DateFactory.php deleted file mode 100644 index b604af9135446a9aea30ce5a684cd1fd1c68b5e4..0000000000000000000000000000000000000000 --- a/app/code/Magento/Reports/Model/DateFactory.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -namespace Magento\Reports\Model; - -class DateFactory -{ - /** - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface|array $date OPTIONAL Date value or value of date part to set - * ,depending on $part. If null the actual time is set - * @param string $part OPTIONAL Defines the input format of $date - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\Date - */ - public function create($date = null, $part = null, $locale = null) - { - return new \Magento\Framework\Stdlib\DateTime\Date($date, $part, $locale); - } -} diff --git a/app/code/Magento/Reports/Model/Product/Index/AbstractIndex.php b/app/code/Magento/Reports/Model/Product/Index/AbstractIndex.php index 4d3ca4716833f3ba99cd5dae823c9085e92880c6..6f6f216e634e88817fc9bcfe35fc379f73b11e73 100644 --- a/app/code/Magento/Reports/Model/Product/Index/AbstractIndex.php +++ b/app/code/Magento/Reports/Model/Product/Index/AbstractIndex.php @@ -102,7 +102,7 @@ abstract class AbstractIndex extends \Magento\Framework\Model\AbstractModel $this->setStoreId($this->getStoreId()); } if (!$this->hasAddedAt()) { - $this->setAddedAt($this->dateTime->now()); + $this->setAddedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)); } return $this; diff --git a/app/code/Magento/Reports/Model/Resource/Entity/Summary/Collection/AbstractCollection.php b/app/code/Magento/Reports/Model/Resource/Entity/Summary/Collection/AbstractCollection.php deleted file mode 100644 index 5da4e2f6b1efdd2fbf944ec31f1e46baeb12de40..0000000000000000000000000000000000000000 --- a/app/code/Magento/Reports/Model/Resource/Entity/Summary/Collection/AbstractCollection.php +++ /dev/null @@ -1,130 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -/** - * Reports summary collection - * - * @author Magento Core Team <core@magentocommerce.com> - */ -namespace Magento\Reports\Model\Resource\Entity\Summary\Collection; - -class AbstractCollection extends \Magento\Framework\Data\Collection -{ - /** - * Entity collection for summaries - * - * @var \Magento\Eav\Model\Entity\Collection\AbstractCollection - */ - protected $_entityCollection; - - /** - * @var \Magento\Framework\Stdlib\DateTime - */ - protected $dateTime; - - /** - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory - * @param \Magento\Framework\Stdlib\DateTime $dateTime - */ - public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Stdlib\DateTime $dateTime) - { - $this->dateTime = $dateTime; - parent::__construct($entityFactory); - } - - /** - * Filters the summaries by some period - * - * @param string $periodType - * @param string|int|null $customStart - * @param string|int|null $customEnd - * @return $this - */ - public function setSelectPeriod($periodType, $customStart = null, $customEnd = null) - { - switch ($periodType) { - case "24h": - $customStart = $this->dateTime->toTimestamp(true) - 86400; - $customEnd = $this->dateTime->toTimestamp(true); - break; - - case "7d": - $customStart = $this->dateTime->toTimestamp(true) - 604800; - $customEnd = $this->dateTime->toTimestamp(true); - break; - - case "30d": - $customStart = $this->dateTime->toTimestamp(true) - 2592000; - $customEnd = $this->dateTime->toTimestamp(true); - break; - - case "1y": - $customStart = $this->dateTime->toTimestamp(true) - 31536000; - $customEnd = $this->dateTime->toTimestamp(true); - break; - - default: - if (is_string($customStart)) { - $customStart = strtotime($customStart); - } - if (is_string($customEnd)) { - $customEnd = strtotime($customEnd); - } - break; - } - - return $this; - } - - /** - * Set date period - * - * @param int $period - * @return $this - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function setDatePeriod($period) - { - return $this; - } - - /** - * Set store filter - * - * @param int $storeId - * @return $this - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function setStoreFilter($storeId) - { - return $this; - } - - /** - * Return collection for summaries - * - * @return \Magento\Eav\Model\Entity\Collection\AbstractCollection - */ - public function getCollection() - { - if (empty($this->_entityCollection)) { - $this->_initCollection(); - } - return $this->_entityCollection; - } - - /** - * Init collection - * - * @return $this - */ - protected function _initCollection() - { - return $this; - } -} diff --git a/app/code/Magento/Reports/Model/Resource/Order/Collection.php b/app/code/Magento/Reports/Model/Resource/Order/Collection.php index 107112fb91026b8dc1c63d403962e4fccb629b47..68558080b6670588778570df2e4506f4a246536d 100644 --- a/app/code/Magento/Reports/Model/Resource/Order/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Order/Collection.php @@ -372,12 +372,16 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Collection protected function _getTZRangeExpressionForAttribute($range, $attribute, $tzFrom = '+00:00', $tzTo = null) { if (null == $tzTo) { - $tzTo = $this->_localeDate->scopeDate()->toString(\Zend_Date::GMT_DIFF_SEP); + $tzTo = $this->_localeDate->scopeDate()->format('P'); } $adapter = $this->getConnection(); $expression = $this->_getRangeExpression($range); $attribute = $adapter->quoteIdentifier($attribute); - $periodExpr = $adapter->getDateAddSql($attribute, $tzTo, \Magento\Framework\DB\Adapter\AdapterInterface::INTERVAL_HOUR); + $periodExpr = $adapter->getDateAddSql( + $attribute, + $tzTo, + \Magento\Framework\DB\Adapter\AdapterInterface::INTERVAL_HOUR + ); return str_replace('{{attribute}}', $periodExpr, $expression); } @@ -394,34 +398,32 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Collection */ public function getDateRange($range, $customStart, $customEnd, $returnObjects = false) { - $dateEnd = $this->_localeDate->date(); - $dateStart = clone $dateEnd; + $dateEnd = new \DateTime(); + $dateStart = new \DateTime(); // go to the end of a day - $dateEnd->setHour(23); - $dateEnd->setMinute(59); - $dateEnd->setSecond(59); + $dateEnd->setTime(23, 59, 59); - $dateStart->setHour(0); - $dateStart->setMinute(0); - $dateStart->setSecond(0); + $dateStart->setTime(0, 0, 0); switch ($range) { case '24h': - $dateEnd = $this->_localeDate->date(); - $dateEnd->addHour(1); + $dateEnd = new \DateTime(); + $dateEnd->modify('+1 hour'); $dateStart = clone $dateEnd; - $dateStart->subDay(1); + $dateStart->modify('-1 day'); break; case '7d': // substract 6 days we need to include // only today and not hte last one from range - $dateStart->subDay(6); + $dateStart->modify('-6 days'); break; case '1m': - $dateStart->setDay( + $dateStart->setDate( + $dateStart->format('Y'), + $dateStart->format('m'), $this->_scopeConfig->getValue( 'reports/dashboard/mtd_start', \Magento\Store\Model\ScopeInterface::SCOPE_STORE @@ -445,16 +447,15 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Collection ); $startMonth = isset($startMonthDay[0]) ? (int)$startMonthDay[0] : 1; $startDay = isset($startMonthDay[1]) ? (int)$startMonthDay[1] : 1; - $dateStart->setMonth($startMonth); - $dateStart->setDay($startDay); + $dateStart->setDate($dateStart->format('Y'), $startMonth, $startDay); if ($range == '2y') { - $dateStart->subYear(1); + $dateStart->modify('-1 year'); } break; } - $dateStart->setTimezone('Etc/UTC'); - $dateEnd->setTimezone('Etc/UTC'); + $dateStart->setTimezone(new \DateTimeZone('Etc/UTC')); + $dateEnd->setTimezone(new \DateTimeZone('Etc/UTC')); if ($returnObjects) { return [$dateStart, $dateEnd]; @@ -896,8 +897,8 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Collection $this->addFieldToFilter( $fieldToFilter, [ - 'from' => $from->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT), - 'to' => $to->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + 'from' => $from->format(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT), + 'to' => $to->format(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) ] ); diff --git a/app/code/Magento/Reports/Model/Resource/Product/Index/AbstractIndex.php b/app/code/Magento/Reports/Model/Resource/Product/Index/AbstractIndex.php index 8eb599d23118d20be6ccbb7d1aa2fa10c339566c..52d72406cb130d56d6a11e75ed1d68e139268287 100644 --- a/app/code/Magento/Reports/Model/Resource/Product/Index/AbstractIndex.php +++ b/app/code/Magento/Reports/Model/Resource/Product/Index/AbstractIndex.php @@ -84,14 +84,14 @@ abstract class AbstractIndex extends \Magento\Framework\Model\Resource\Db\Abstra $data = [ 'visitor_id' => $object->getVisitorId(), 'store_id' => $object->getStoreId(), - 'added_at' => $this->dateTime->now(), + 'added_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), ]; } else { $where = ['index_id = ?' => $row['index_id']]; $data = [ 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), - 'added_at' => $this->dateTime->now(), + 'added_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), ]; } @@ -202,7 +202,7 @@ abstract class AbstractIndex extends \Magento\Framework\Model\Resource\Db\Abstra 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), ]; - $addedAt = $this->dateTime->toTimestamp(true); + $addedAt = (new \DateTime())->getTimestamp(); $data = []; foreach ($productIds as $productId) { $productId = (int)$productId; diff --git a/app/code/Magento/Reports/Model/Resource/Refresh/Collection.php b/app/code/Magento/Reports/Model/Resource/Refresh/Collection.php index 930dbf4ce444e43bb5b3827dbc091b86186ae758..51710f72ab2c11e7677aad3cfdad9c2630a94366 100644 --- a/app/code/Magento/Reports/Model/Resource/Refresh/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Refresh/Collection.php @@ -42,17 +42,14 @@ class Collection extends \Magento\Framework\Data\Collection * Get if updated * * @param string $reportCode - * @return string|\Magento\Framework\Stdlib\DateTime\DateInterface + * @return string|\DateTime */ protected function _getUpdatedAt($reportCode) { $flag = $this->_reportsFlagFactory->create()->setReportFlagCode($reportCode)->loadSelf(); return $flag->hasData() ? $this->_localeDate->scopeDate( 0, - new \Magento\Framework\Stdlib\DateTime\Date( - $flag->getLastUpdate(), - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ), + $flag->getLastUpdate(), true ) : ''; } diff --git a/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php b/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php index 215051833602f4bfb69d738a2db062aecf84c782..2de8eaf41e183af60a117dd093ccc338adaba2a5 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php +++ b/app/code/Magento/Reports/Model/Resource/Report/AbstractReport.php @@ -90,7 +90,7 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr $this->_getFlag()->setFlagData($value); } - $time = $this->dateTime->toTimestamp(true); + $time = (new \DateTime())->getTimestamp(); // touch last_update $this->_getFlag()->setLastUpdate($this->dateTime->formatDate($time)); @@ -175,8 +175,8 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr * @param string $table * @param string $column * @param string $whereColumn - * @param null|string $from - * @param null|string $to + * @param null|string|\DateTime $from + * @param null|string|\DateTime $to * @param array $additionalWhere * @param string $alias * @return \Magento\Framework\DB\Select @@ -341,26 +341,6 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr return $select; } - /** - * Check range dates and transforms it to strings - * - * @param mixed &$dateFrom - * @param mixed &$dateTo - * @return $this - */ - protected function _checkDates(&$dateFrom, &$dateTo) - { - if ($dateFrom !== null) { - $dateFrom = $this->dateTime->formatDate($dateFrom); - } - - if ($dateTo !== null) { - $dateTo = $this->dateTime->formatDate($dateTo); - } - - return $this; - } - /** * Retrieve query for attribute with timezone conversion * @@ -381,7 +361,7 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr } $periods = $this->_getTZOffsetTransitions( - $this->_localeDate->scopeDate($store)->toString(\Zend_Date::TIMEZONE_NAME), + $this->_localeDate->scopeDate($store)->format('e'), $from, $to ); @@ -424,19 +404,17 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr $tzTransitions = []; try { if (!empty($from)) { - $from = new \Magento\Framework\Stdlib\DateTime\Date($from, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); - $from = $from->getTimestamp(); + $from = (new \DateTime($from))->getTimestamp(); } - $to = new \Magento\Framework\Stdlib\DateTime\Date($to, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT); + $to = new \DateTime($to); $nextPeriod = $this->_getWriteAdapter()->formatDate( - $to->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + $to->format('Y-m-d H:i:s') ); $to = $to->getTimestamp(); $dtz = new \DateTimeZone($timezone); $transitions = $dtz->getTransitions(); - $dateTimeObject = new \Magento\Framework\Stdlib\DateTime\Date('c'); for ($i = count($transitions) - 1; $i >= 0; $i--) { $tr = $transitions[$i]; @@ -446,9 +424,8 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr continue; } - $dateTimeObject->set($tr['time']); $tr['time'] = $this->_getWriteAdapter()->formatDate( - $dateTimeObject->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + (new \DateTime($tr['time']))->format('Y-m-d H:i:s') ); $tzTransitions[$tr['offset']][] = ['from' => $tr['time'], 'to' => $nextPeriod]; @@ -472,22 +449,28 @@ abstract class AbstractReport extends \Magento\Framework\Model\Resource\Db\Abstr */ protected function _getStoreTimezoneUtcOffset($store = null) { - return $this->_localeDate->scopeDate($store)->toString(\Zend_Date::GMT_DIFF_SEP); + return $this->_localeDate->scopeDate($store)->format('P'); } /** * Retrieve date in UTC timezone * * @param mixed $date - * @return null|\Magento\Framework\Stdlib\DateTime\DateInterface + * @return null|\DateTime */ protected function _dateToUtc($date) { if ($date === null) { return null; } - $dateUtc = new \Magento\Framework\Stdlib\DateTime\Date($date); - $dateUtc->setTimezone('Etc/UTC'); - return $dateUtc; + + if ($date instanceof \DateTimeInterface) { + $dateUtc = $date; + } else { + $dateUtc = new \DateTime($date); + } + + $dateUtc->setTimezone(new \DateTimeZone('UTC')); + return $dateUtc->format('Y-m-d H:i:s'); } } diff --git a/app/code/Magento/Reports/Model/Resource/Report/Collection.php b/app/code/Magento/Reports/Model/Resource/Report/Collection.php index 79968a4d34d0575aafe52537a5d264b9c16f9249..4c3eff00d4171366fab8490aeafa10413aa21855 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Report/Collection.php @@ -69,11 +69,6 @@ class Collection extends \Magento\Framework\Data\Collection */ protected $_reportCollection = null; - /** - * @var \Magento\Reports\Model\DateFactory - */ - protected $_dateFactory; - /** * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface */ @@ -87,16 +82,13 @@ class Collection extends \Magento\Framework\Data\Collection /** * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate - * @param \Magento\Reports\Model\DateFactory $dateFactory * @param \Magento\Reports\Model\Resource\Report\Collection\Factory $collectionFactory */ public function __construct( \Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, - \Magento\Reports\Model\DateFactory $dateFactory, \Magento\Reports\Model\Resource\Report\Collection\Factory $collectionFactory ) { - $this->_dateFactory = $dateFactory; $this->_localeDate = $localeDate; $this->_collectionFactory = $collectionFactory; parent::__construct($entityFactory); @@ -117,8 +109,8 @@ class Collection extends \Magento\Framework\Data\Collection /** * Set interval * - * @param int $fromDate - * @param int $toDate + * @param \DateTime $fromDate + * @param \DateTime $toDate * @return $this */ public function setInterval($fromDate, $toDate) @@ -141,16 +133,15 @@ class Collection extends \Magento\Framework\Data\Collection if (!$this->_from && !$this->_to) { return $this->_intervals; } - $dateStart = $this->_dateFactory->create($this->_from); - $dateEnd = $this->_dateFactory->create($this->_to); + $dateStart = $this->_from; + $dateEnd = $this->_to; - $interval = []; $firstInterval = true; - while ($dateStart->compare($dateEnd) <= 0) { + while ($dateStart <= $dateEnd) { switch ($this->_period) { case 'day': $interval = $this->_getDayInterval($dateStart); - $dateStart->addDay(1); + $dateStart->modify('+1 day'); break; case 'month': $interval = $this->_getMonthInterval($dateStart, $dateEnd, $firstInterval); @@ -172,15 +163,19 @@ class Collection extends \Magento\Framework\Data\Collection /** * Get interval for a day * - * @param \Magento\Framework\Stdlib\DateTime\DateInterface $dateStart + * @param \DateTime $dateStart * @return array */ - protected function _getDayInterval(\Magento\Framework\Stdlib\DateTime\DateInterface $dateStart) + protected function _getDayInterval(\DateTime $dateStart) { $interval = [ - 'period' => $dateStart->toString($this->_localeDate->getDateFormat()), - 'start' => $dateStart->toString('yyyy-MM-dd HH:mm:ss'), - 'end' => $dateStart->toString('yyyy-MM-dd 23:59:59'), + 'period' => $this->_localeDate->formatDateTime( + $dateStart, + \IntlDateFormatter::SHORT, + \IntlDateFormatter::NONE + ), + 'start' => $dateStart->format('Y-m-d H:i:s'), + 'end' => $dateStart->format('Y-m-d 23:59:59'), ]; return $interval; } @@ -188,36 +183,37 @@ class Collection extends \Magento\Framework\Data\Collection /** * Get interval for a month * - * @param \Magento\Framework\Stdlib\DateTime\DateInterface $dateStart - * @param \Magento\Framework\Stdlib\DateTime\DateInterface $dateEnd + * @param \DateTime $dateStart + * @param \DateTime $dateEnd * @param bool $firstInterval * @return array */ - protected function _getMonthInterval( - \Magento\Framework\Stdlib\DateTime\DateInterface $dateStart, - \Magento\Framework\Stdlib\DateTime\DateInterface $dateEnd, - $firstInterval - ) { + protected function _getMonthInterval(\DateTime $dateStart, \DateTime $dateEnd, $firstInterval) + { $interval = []; - $interval['period'] = $dateStart->toString('MM/yyyy'); + $interval['period'] = $dateStart->format('m/Y'); if ($firstInterval) { - $interval['start'] = $dateStart->toString('yyyy-MM-dd 00:00:00'); + $interval['start'] = $dateStart->format('Y-m-d 00:00:00'); } else { - $interval['start'] = $dateStart->toString('yyyy-MM-01 00:00:00'); + $interval['start'] = $dateStart->format('Y-m-01 00:00:00'); } - $lastInterval = $dateStart->compareMonth($dateEnd->getMonth()) == 0; - - if ($lastInterval) { - $interval['end'] = $dateStart->setDay($dateEnd->getDay())->toString('yyyy-MM-dd 23:59:59'); + if ($dateStart->diff($dateEnd)->m == 0) { + $interval['end'] = $dateStart->setDate( + $dateStart->format('Y'), + $dateStart->format('m'), + $dateEnd->format('d') + )->format( + 'Y-m-d 23:59:59' + ); } else { - $interval['end'] = $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59'); + $interval['end'] = $dateStart->format('Y-m-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59'); } - $dateStart->addMonth(1); + $dateStart->modify('+1 month'); - if ($dateStart->compareMonth($dateEnd->getMonth()) == 0) { - $dateStart->setDay(1); + if ($dateStart->diff($dateEnd)->m == 0) { + $dateStart->setDate($dateStart->format('Y'), $dateStart->format('m'), 1); } return $interval; @@ -226,39 +222,27 @@ class Collection extends \Magento\Framework\Data\Collection /** * Get Interval for a year * - * @param \Magento\Framework\Stdlib\DateTime\DateInterface $dateStart - * @param \Magento\Framework\Stdlib\DateTime\DateInterface $dateEnd + * @param \DateTime $dateStart + * @param \DateTime $dateEnd * @param bool $firstInterval * @return array */ - protected function _getYearInterval( - \Magento\Framework\Stdlib\DateTime\DateInterface $dateStart, - \Magento\Framework\Stdlib\DateTime\DateInterface $dateEnd, - $firstInterval - ) { + protected function _getYearInterval(\DateTime $dateStart, \DateTime $dateEnd, $firstInterval) + { $interval = []; - $interval['period'] = $dateStart->toString('yyyy'); - $interval['start'] = $firstInterval ? $dateStart->toString( - 'yyyy-MM-dd 00:00:00' - ) : $dateStart->toString( - 'yyyy-01-01 00:00:00' - ); - - $lastInterval = $dateStart->compareYear($dateEnd->getYear()) == 0; - - $interval['end'] = $lastInterval ? $dateStart->setMonth( - $dateEnd->getMonth() - )->setDay( - $dateEnd->getDay() - )->toString( - 'yyyy-MM-dd 23:59:59' - ) : $dateStart->toString( - 'yyyy-12-31 23:59:59' - ); - $dateStart->addYear(1); - - if ($dateStart->compareYear($dateEnd->getYear()) == 0) { - $dateStart->setMonth(1)->setDay(1); + $interval['period'] = $dateStart->format('Y'); + $interval['start'] = $firstInterval + ? $dateStart->format('Y-m-dd 00:00:00') + : $dateStart->format('Y-01-01 00:00:00'); + + $interval['end'] = $dateStart->diff($dateEnd)->y == 0 + ? $dateStart->setDate($dateStart->format('Y'), $dateEnd->format('m'), $dateEnd->format('d')) + ->format('Y-m-d 23:59:59') + : $dateStart->format('Y-12-31 23:59:59'); + $dateStart->modify('+1 year'); + + if ($dateStart->diff($dateEnd)->y == 0) { + $dateStart->setDate($dateStart->format('Y'), 1, 1); } return $interval; @@ -379,14 +363,9 @@ class Collection extends \Magento\Framework\Data\Collection */ public function timeShift($datetime) { - return $this->_localeDate->utcDate( - null, - $datetime, - true, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - )->toString( - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); + return $this->_localeDate->scopeDate(null, $datetime, true) + ->setTimezone(new \DateTimeZone('UTC')) + ->format('Y-m-d H:i:s'); } /** diff --git a/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php b/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php index 10e3ece5c87289e85dc0ac619832ebb1f391909a..9ebd26efbd7e7dc3edd48e5e8a00dc901ec666ab 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php +++ b/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed.php @@ -102,8 +102,6 @@ class Viewed extends \Magento\Sales\Model\Resource\Report\AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); - if ($from !== null || $to !== null) { $subSelect = $this->_getTableDateRangeSelect( $this->getTable('report_event'), diff --git a/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed/Collection.php b/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed/Collection.php index 1a3f120b6df895e73561edc41709a3e58a8f2b82..d1b75ea2a05c4b8736a63ff611529784d5a8924c 100644 --- a/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed/Collection.php +++ b/app/code/Magento/Reports/Model/Resource/Report/Product/Viewed/Collection.php @@ -4,393 +4,28 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - -/** - * Report most viewed collection - */ namespace Magento\Reports\Model\Resource\Report\Product\Viewed; -/** - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class Collection extends \Magento\Reports\Model\Resource\Report\Collection\AbstractCollection +class Collection extends \Magento\Sales\Model\Resource\Report\Bestsellers\Collection { /** - * Rating limit - * - * @var int - */ - protected $_ratingLimit = 5; - - /** - * Selected columns + * Tables per period * * @var array */ - protected $_selectedColumns = []; - - /** - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Sales\Model\Resource\Report $resource - * @param mixed $connection - */ - public function __construct( - \Magento\Framework\Data\Collection\EntityFactory $entityFactory, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Sales\Model\Resource\Report $resource, - $connection = null - ) { - $resource->init(\Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_DAILY); - parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); - $this->setModel('Magento\Reports\Model\Item'); - } - - /** - * Retrieve selected columns - * - * @return array - */ - protected function _getSelectedColumns() - { - $adapter = $this->getConnection(); - - if (!$this->_selectedColumns) { - if ($this->isTotals()) { - $this->_selectedColumns = $this->getAggregatedColumns(); - } else { - $this->_selectedColumns = [ - 'period' => sprintf('MAX(%s)', $adapter->getDateFormatSql('period', '%Y-%m-%d')), - 'views_num' => 'SUM(views_num)', - 'product_id' => 'product_id', - 'product_name' => 'MAX(product_name)', - 'product_price' => 'MAX(product_price)', - ]; - if ('year' == $this->_period) { - $this->_selectedColumns['period'] = $adapter->getDateFormatSql('period', '%Y'); - } elseif ('month' == $this->_period) { - $this->_selectedColumns['period'] = $adapter->getDateFormatSql('period', '%Y-%m'); - } - } - } - return $this->_selectedColumns; - } - - /** - * Make select object for date boundary - * - * @param mixed $from - * @param mixed $to - * @return \Zend_Db_Select - */ - protected function _makeBoundarySelect($from, $to) - { - $adapter = $this->getConnection(); - $cols = $this->_getSelectedColumns(); - $cols['views_num'] = 'SUM(views_num)'; - $select = $adapter->select()->from( - $this->getResource()->getMainTable(), - $cols - )->where( - 'period >= ?', - $from - )->where( - 'period <= ?', - $to - )->group( - 'product_id' - )->order( - 'views_num DESC' - )->limit( - $this->_ratingLimit - ); - - $this->_applyStoresFilterToSelect($select); - - return $select; - } - - /** - * Init collection select - * - * @return $this - */ - protected function _applyAggregatedTable() - { - $select = $this->getSelect(); - - // if grouping by product, not by period - if (!$this->_period) { - $cols = $this->_getSelectedColumns(); - $cols['views_num'] = 'SUM(views_num)'; - if ($this->_from || $this->_to) { - $mainTable = $this->getTable(\Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_DAILY); - $select->from($mainTable, $cols); - } else { - $mainTable = $this->getTable( - \Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_YEARLY - ); - $select->from($mainTable, $cols); - } - - //exclude removed products - $subSelect = $this->getConnection()->select(); - $subSelect->from( - ['existed_products' => $this->getTable('catalog_product_entity')], - new \Zend_Db_Expr('1)') - ); - - $select->exists( - $subSelect, - $mainTable . '.product_id = existed_products.entity_id' - )->group( - 'product_id' - )->order( - 'views_num ' . \Magento\Framework\DB\Select::SQL_DESC - )->limit( - $this->_ratingLimit - ); - - return $this; - } - - if ('year' == $this->_period) { - $mainTable = $this->getTable(\Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_YEARLY); - $select->from($mainTable, $this->_getSelectedColumns()); - } elseif ('month' == $this->_period) { - $mainTable = $this->getTable(\Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_MONTHLY); - $select->from($mainTable, $this->_getSelectedColumns()); - } else { - $mainTable = $this->getTable(\Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_DAILY); - $select->from($mainTable, $this->_getSelectedColumns()); - } - if (!$this->isTotals()) { - $select->group(['period', 'product_id']); - } - $select->where('rating_pos <= ?', $this->_ratingLimit); - - return $this; - } - - /** - * Get SQL for get record count - * - * @return \Magento\Framework\DB\Select - */ - public function getSelectCountSql() - { - $this->_renderFilters(); - $select = clone $this->getSelect(); - $select->reset(\Zend_Db_Select::ORDER); - return $this->getConnection()->select()->from($select, 'COUNT(*)'); - } - - /** - * Set ids for store restrictions - * - * @param array $storeIds - * @return $this - */ - public function addStoreRestrictions($storeIds) - { - if (!is_array($storeIds)) { - $storeIds = [$storeIds]; - } - $currentStoreIds = $this->_storesIds; - if (isset( - $currentStoreIds - ) && $currentStoreIds != \Magento\Store\Model\Store::DEFAULT_STORE_ID && $currentStoreIds != [ - \Magento\Store\Model\Store::DEFAULT_STORE_ID - ] - ) { - if (!is_array($currentStoreIds)) { - $currentStoreIds = [$currentStoreIds]; - } - $this->_storesIds = array_intersect($currentStoreIds, $storeIds); - } else { - $this->_storesIds = $storeIds; - } - - return $this; - } + protected $tableForPeriod = [ + 'daily' => \Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_DAILY, + 'monthly' => \Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_MONTHLY, + 'yearly' => \Magento\Reports\Model\Resource\Report\Product\Viewed::AGGREGATION_YEARLY, + ]; /** - * Re-declare parent method for applying filters after parent method, but before adding unions and calculating - * totals + * Return ordered filed * - * @return $this|\Magento\Framework\Model\Resource\Db\Collection\AbstractCollection - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @return string */ - protected function _beforeLoad() + protected function getOrderedField() { - parent::_beforeLoad(); - - $this->_applyStoresFilter(); - - if ($this->_period) { - $selectUnions = []; - - // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; - $periodFrom = !is_null($this->_from) ? new \Magento\Framework\Stdlib\DateTime\Date($this->_from, $dtFormat) : null; - $periodTo = !is_null($this->_to) ? new \Magento\Framework\Stdlib\DateTime\Date($this->_to, $dtFormat) : null; - if ('year' == $this->_period) { - if ($periodFrom) { - // not the first day of the year - if ($periodFrom->toValue(\Zend_Date::MONTH) != 1 || $periodFrom->toValue(\Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the year - $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // first day of the next year - $this->_from = $periodFrom->getDate()->addYear( - 1 - )->setMonth( - 1 - )->setDay( - 1 - )->toString( - $dtFormat - ); - } - } - } - - if ($periodTo) { - // not the last day of the year - if ($periodTo->toValue(\Zend_Date::MONTH) != 12 || $periodTo->toValue(\Zend_Date::DAY) != 31) { - $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); - // first day of the year - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // last day of the previous year - $this->_to = $periodTo->getDate()->subYear( - 1 - )->setMonth( - 12 - )->setDay( - 31 - )->toString( - $dtFormat - ); - } - } - } - - if ($periodFrom && $periodTo) { - // the same year - if ($periodFrom->toValue(\Zend_Date::YEAR) == $periodTo->toValue(\Zend_Date::YEAR)) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - $this->getSelect()->where('1<>1'); - } - } - } elseif ('month' == $this->_period) { - if ($periodFrom) { - // not the first day of the month - if ($periodFrom->toValue(\Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); - // last day of the month - $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // first day of the next month - $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); - } - } - } - - if ($periodTo) { - // not the last day of the month - if ($periodTo->toValue(\Zend_Date::DAY) != $periodTo->toValue(\Zend_Date::MONTH_DAYS)) { - $dtFrom = $periodTo->getDate()->setDay(1); - // first day of the month - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - // last day of the previous month - $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); - } - } - } - - if ($periodFrom && $periodTo) { - // the same month - if ($periodFrom->toValue( - \Zend_Date::YEAR - ) == $periodTo->toValue( - \Zend_Date::YEAR - ) && $periodFrom->toValue( - \Zend_Date::MONTH - ) == $periodTo->toValue( - \Zend_Date::MONTH - ) - ) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); - $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) - ); - - $this->getSelect()->where('1<>1'); - } - } - } - - $this->_applyDateRangeFilter(); - - // add unions to select - if ($selectUnions) { - $unionParts = []; - $cloneSelect = clone $this->getSelect(); - $unionParts[] = '(' . $cloneSelect . ')'; - foreach ($selectUnions as $union) { - $unionParts[] = '(' . $union . ')'; - } - $this->getSelect()->reset()->union($unionParts, \Zend_Db_Select::SQL_UNION_ALL); - } - - if ($this->isTotals()) { - // calculate total - $cloneSelect = clone $this->getSelect(); - $this->getSelect()->reset()->from($cloneSelect, $this->getAggregatedColumns()); - } else { - // add sorting - $this->getSelect()->order(['period ASC', 'views_num DESC']); - } - } - - return $this; + return 'views_num'; } } diff --git a/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/CollectionTest.php b/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/CollectionTest.php index 61ef8da7318b61e154fc7dad6f37d572512dfd21..c1e8adeeee7d3c16a6bb8984939699ef12c1ef48 100644 --- a/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/CollectionTest.php +++ b/app/code/Magento/Reports/Test/Unit/Model/Resource/Report/CollectionTest.php @@ -12,43 +12,23 @@ class CollectionTest extends \PHPUnit_Framework_TestCase */ protected $_model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_factoryMock; - protected function setUp() { $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->_factoryMock = $this->getMock( - '\Magento\Reports\Model\DateFactory', - ['create'], - [], - '', - false - ); - $arguments = ['dateFactory' => $this->_factoryMock]; - $this->_model = $helper->getObject('Magento\Reports\Model\Resource\Report\Collection', $arguments); + $this->_model = $helper->getObject('Magento\Reports\Model\Resource\Report\Collection'); } public function testGetIntervalsWithoutSpecifiedPeriod() { - $startDate = date('m/d/Y', strtotime('-3 day')); - $endDate = date('m/d/Y', strtotime('+3 day')); + $startDate = new \DateTime('-3 day'); + $endDate = new \DateTime('+3 day'); $this->_model->setInterval($startDate, $endDate); - $startDateMock = $this->getMock('Magento\Framework\Stdlib\DateTime\DateInterface', [], [], '', false); - $endDateMock = $this->getMock('Magento\Framework\Stdlib\DateTime\DateInterface', [], [], '', false); - $map = [[$startDate, null, null, $startDateMock], [$endDate, null, null, $endDateMock]]; - $this->_factoryMock->expects($this->exactly(2))->method('create')->will($this->returnValueMap($map)); - $startDateMock->expects($this->once())->method('compare')->with($endDateMock)->will($this->returnValue(true)); - $this->assertEquals(0, $this->_model->getSize()); } public function testGetIntervalsWithoutSpecifiedInterval() { - $this->_factoryMock->expects($this->never())->method('create'); $this->assertEquals(0, $this->_model->getSize()); } } diff --git a/app/code/Magento/Review/Block/Customer/ListCustomer.php b/app/code/Magento/Review/Block/Customer/ListCustomer.php index c8caacb6a0afc776b9fc4f034ce3d558a09cfe2f..30a856c8384f419fb2e11d46bbdf888c7c3940ac 100644 --- a/app/code/Magento/Review/Block/Customer/ListCustomer.php +++ b/app/code/Magento/Review/Block/Customer/ListCustomer.php @@ -168,7 +168,7 @@ class ListCustomer extends \Magento\Customer\Block\Account\Dashboard */ public function dateFormat($date) { - return $this->formatDate($date, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + return $this->formatDate($date, \IntlDateFormatter::SHORT); } /** diff --git a/app/code/Magento/Review/Block/Customer/Recent.php b/app/code/Magento/Review/Block/Customer/Recent.php index 1adc0a3e587adb8685148f3c1f2ab82069025da8..bbb8cf71cb44bb7af39c2ca26cb7d8984c1a20ba 100644 --- a/app/code/Magento/Review/Block/Customer/Recent.php +++ b/app/code/Magento/Review/Block/Customer/Recent.php @@ -150,7 +150,7 @@ class Recent extends \Magento\Framework\View\Element\Template */ public function dateFormat($date) { - return $this->formatDate($date, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + return $this->formatDate($date, \IntlDateFormatter::SHORT); } /** diff --git a/app/code/Magento/Review/Block/Customer/View.php b/app/code/Magento/Review/Block/Customer/View.php index 19414ec64e8f0d8a03a4dfb5a70f38110bcc9efa..7ca1541ba9842f61f3454f6a4a1babc4a46cf5db 100644 --- a/app/code/Magento/Review/Block/Customer/View.php +++ b/app/code/Magento/Review/Block/Customer/View.php @@ -196,7 +196,7 @@ class View extends \Magento\Catalog\Block\Product\AbstractProduct */ public function dateFormat($date) { - return $this->formatDate($date, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_LONG); + return $this->formatDate($date, \IntlDateFormatter::LONG); } /** diff --git a/app/code/Magento/Review/Block/View.php b/app/code/Magento/Review/Block/View.php index 12adedfd3542c7763211e04a7c89648e186411f6..f596e4c5042507bb29743a1a1b341e78e6fbe197 100644 --- a/app/code/Magento/Review/Block/View.php +++ b/app/code/Magento/Review/Block/View.php @@ -56,6 +56,7 @@ class View extends \Magento\Catalog\Block\Product\AbstractProduct ) { $this->_voteFactory = $voteFactory; $this->_reviewFactory = $reviewFactory; + $this->_ratingFactory = $ratingFactory; parent::__construct( $context, @@ -155,7 +156,7 @@ class View extends \Magento\Catalog\Block\Product\AbstractProduct */ public function dateFormat($date) { - return $this->formatDate($date, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_LONG); + return $this->formatDate($date, \IntlDateFormatter::LONG); } /** diff --git a/app/code/Magento/Review/view/frontend/templates/product/view/list.phtml b/app/code/Magento/Review/view/frontend/templates/product/view/list.phtml index 95e8ad599d4f9b8cbde68ee0d6e3aeef0ca8b89c..431dcf446e66e6f073e4c01b347b71a5d616ccf3 100644 --- a/app/code/Magento/Review/view/frontend/templates/product/view/list.phtml +++ b/app/code/Magento/Review/view/frontend/templates/product/view/list.phtml @@ -15,7 +15,7 @@ ?> <?php $_items = $block->getReviewsCollection()->getItems(); - $format = $block->getDateFormat() ?: 'short'; + $format = $block->getDateFormat() ?: \IntlDateFormatter::SHORT; ?> <?php if (count($_items)):?> <div class="block review-list" id="customer-reviews"> diff --git a/app/code/Magento/Rule/Model/AbstractModel.php b/app/code/Magento/Rule/Model/AbstractModel.php index d5e0837b37343f988217fe030b9b5e3a61d438d6..786635077534fa972b45ed061ec5b28cf2b0142f 100644 --- a/app/code/Magento/Rule/Model/AbstractModel.php +++ b/app/code/Magento/Rule/Model/AbstractModel.php @@ -294,7 +294,7 @@ abstract class AbstractModel extends \Magento\Framework\Model\AbstractModel /** * Set specified data to current rule. * Set conditions and actions recursively. - * Convert dates into \Zend_Date. + * Convert dates into \DateTime. * * @param array $data * @return array @@ -320,15 +320,10 @@ abstract class AbstractModel extends \Magento\Framework\Model\AbstractModel } } else { /** - * Convert dates into \Zend_Date + * Convert dates into \DateTime */ if (in_array($key, ['from_date', 'to_date']) && $value) { - $value = $this->_localeDate->date( - $value, - \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, - null, - false - ); + $value = new \DateTime($value); } $this->setData($key, $value); } @@ -367,10 +362,10 @@ abstract class AbstractModel extends \Magento\Framework\Model\AbstractModel } if ($fromDate && $toDate) { - $fromDate = new \Magento\Framework\Stdlib\DateTime\Date($fromDate, \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT); - $toDate = new \Magento\Framework\Stdlib\DateTime\Date($toDate, \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT); + $fromDate = new \DateTime($fromDate); + $toDate = new \DateTime($toDate); - if ($fromDate->compare($toDate) === 1) { + if ($fromDate > $toDate) { $result[] = __('End Date must follow Start Date.'); } } diff --git a/app/code/Magento/Rule/Model/Condition/AbstractCondition.php b/app/code/Magento/Rule/Model/Condition/AbstractCondition.php index 6bc5bd70d37e79939021284eda38e6c0a4812bb2..022aad5ad09fbde4638dc8d6586ed4d17bc3e5f3 100644 --- a/app/code/Magento/Rule/Model/Condition/AbstractCondition.php +++ b/app/code/Magento/Rule/Model/Condition/AbstractCondition.php @@ -397,14 +397,7 @@ abstract class AbstractCondition extends \Magento\Framework\Object implements Co if ($this->getInputType() == 'date' && !$this->getIsValueParsed()) { // date format intentionally hard-coded $this->setValue( - $this->_localeDate->date( - $this->getData('value'), - \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, - null, - false - )->toString( - \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT - ) + (new \DateTime($this->getData('value')))->format('Y-m-d H:i:s') ); $this->setIsValueParsed(true); } diff --git a/app/code/Magento/Rule/Model/Resource/AbstractResource.php b/app/code/Magento/Rule/Model/Resource/AbstractResource.php index ee4a276ec1d9a6a0e593b0cf1035371619fdfb6b..070086bac80eb2a4cbc2f919416553c64518b5ee 100644 --- a/app/code/Magento/Rule/Model/Resource/AbstractResource.php +++ b/app/code/Magento/Rule/Model/Resource/AbstractResource.php @@ -44,15 +44,15 @@ abstract class AbstractResource extends \Magento\Framework\Model\Resource\Db\Abs public function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { $fromDate = $object->getFromDate(); - if ($fromDate instanceof \Zend_Date) { - $object->setFromDate($fromDate->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT)); + if ($fromDate instanceof \DateTime) { + $object->setFromDate($fromDate->format('Y-m-d H:i:s')); } elseif (!is_string($fromDate) || empty($fromDate)) { $object->setFromDate(null); } $toDate = $object->getToDate(); - if ($toDate instanceof \Zend_Date) { - $object->setToDate($toDate->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT)); + if ($toDate instanceof \DateTime) { + $object->setToDate($toDate->format('Y-m-d H:i:s')); } elseif (!is_string($toDate) || empty($toDate)) { $object->setToDate(null); } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractForm.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractForm.php index 79951197f43d1873903d949891c2d41042a1fc46..8cafee1d7ee9dee625337a965c94d7ff2c7fe5cd 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractForm.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractForm.php @@ -202,7 +202,7 @@ abstract class AbstractForm extends \Magento\Sales\Block\Adminhtml\Order\Create\ $element->setValues($options); } elseif ($inputType == 'date') { $format = $this->_localeDate->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ); $element->setImage($this->getViewFileUrl('images/grid-cal.png')); $element->setDateFormat($format); diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/View.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/View.php index ae12ef9bb44dead928fea0a4509fe53b1cf9b1e0..c319a376a1bb36434a953c5ce7bcc221acf79852 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/View.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Creditmemo/View.php @@ -137,7 +137,7 @@ class View extends \Magento\Backend\Block\Widget\Form\Container return __( 'Credit Memo #%1 | %3 | %2 (%4)', $this->getCreditmemo()->getIncrementId(), - $this->formatDate($this->getCreditmemo()->getCreatedAtDate(), 'medium', true), + $this->formatDate($this->getCreditmemo()->getCreatedAtDate(), \IntlDateFormatter::MEDIUM, true), $this->getCreditmemo()->getStateName(), $emailSent ); diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Invoice/View.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Invoice/View.php index 10732ed47b941bce313c3ed0c71111ab9855d309..de3a079d0894f9233392a3d1a6a652372aec7313 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Invoice/View.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Invoice/View.php @@ -198,7 +198,7 @@ class View extends \Magento\Backend\Block\Widget\Form\Container $this->getInvoice()->getIncrementId(), $this->getInvoice()->getStateName(), $emailSent, - $this->formatDate($this->getInvoice()->getCreatedAtDate(), 'medium', true) + $this->formatDate($this->getInvoice()->getCreatedAtDate(), \IntlDateFormatter::MEDIUM, true) ); } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View.php index b295e9a275f211d005768a55b5cef9e8b89dbb8f..ffa72f42735bf81a8f1f96d6db68e0c9e58d96d3 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/View.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View.php @@ -287,7 +287,7 @@ class View extends \Magento\Backend\Block\Widget\Form\Container 'Order # %1 %2 | %3', $this->getOrder()->getRealOrderId(), $_extOrderId, - $this->formatDate($this->getOrder()->getCreatedAtDate(), 'medium', true) + $this->formatDate($this->getOrder()->getCreatedAtDate(), \IntlDateFormatter::MEDIUM, true) ); } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php index 70de5fcfcd62d0b3a9b7b521ee2ed4cdba153e06..7e1f2548c0bf45fa36436c9825dabde5466cc32c 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php @@ -141,18 +141,21 @@ class History extends \Magento\Backend\Block\Template implements \Magento\Backen * * @param array $item * @param string $dateType - * @param string $format + * @param int $format * @return string */ - public function getItemCreatedAt(array $item, $dateType = 'date', $format = 'medium') + public function getItemCreatedAt(array $item, $dateType = 'date', $format = \IntlDateFormatter::MEDIUM) { if (!isset($item['created_at'])) { return ''; } + $date = $item['created_at'] instanceof \DateTimeInterface + ? $item['created_at'] + : new \DateTime($item['created_at']); if ('date' === $dateType) { - return $this->formatDate($item['created_at'], $format); + return $this->_localeDate->formatDateTime($date, $format, $format); } - return $this->formatTime($item['created_at'], $format); + return $this->_localeDate->formatDateTime($date, \IntlDateFormatter::NONE, $format); } /** @@ -198,7 +201,7 @@ class History extends \Magento\Backend\Block\Template implements \Magento\Backen * * @param string $label * @param bool $notified - * @param \Magento\Framework\Stdlib\DateTime\DateInterface $created + * @param \DateTime $created * @param string $comment * @return array */ @@ -293,7 +296,7 @@ class History extends \Magento\Backend\Block\Template implements \Magento\Backen $createdAtA = $a['created_at']; $createdAtB = $b['created_at']; - /** @var $createdAta \Magento\Framework\Stdlib\DateTime\DateInterface */ + /** @var $createdAtA \DateTime */ if ($createdAtA->getTimestamp() == $createdAtB->getTimestamp()) { return 0; } diff --git a/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php b/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php index 04882426490e8275ed64312142c4ac334b093c76..8eed288ca073359398473eb23997870c5b03db36 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Transactions/Detail.php @@ -84,7 +84,7 @@ class Detail extends \Magento\Backend\Block\Widget\Container $this->_txn->getTxnId(), $this->formatDate( $this->_txn->getCreatedAt(), - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, + \IntlDateFormatter::MEDIUM, true ) ); @@ -119,7 +119,7 @@ class Detail extends \Magento\Backend\Block\Widget\Container $this->_txn->getCreatedAt() ) ? $this->formatDate( $this->_txn->getCreatedAt(), - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, + \IntlDateFormatter::MEDIUM, true ) : __( 'N/A' diff --git a/app/code/Magento/Sales/Model/AbstractModel.php b/app/code/Magento/Sales/Model/AbstractModel.php index 3020f422be2b68bcffce2ec51ad0ad3ba67ae530..b87d43e79f47cb97ceedab4e14bdd9babb13e002 100644 --- a/app/code/Magento/Sales/Model/AbstractModel.php +++ b/app/code/Magento/Sales/Model/AbstractModel.php @@ -69,23 +69,23 @@ abstract class AbstractModel extends AbstractExtensibleModel /** * Get object created at date affected current active store timezone * - * @return \Magento\Framework\Stdlib\DateTime\Date + * @return \DateTime */ public function getCreatedAtDate() { - return $this->_localeDate->date($this->dateTime->toTimestamp($this->getCreatedAt()), null, null, true); + return $this->_localeDate->date(new \DateTime($this->getCreatedAt())); } /** * Get object created at date affected with object store timezone * - * @return \Magento\Framework\Stdlib\DateTime\Date + * @return \DateTime */ public function getCreatedAtStoreDate() { return $this->_localeDate->scopeDate( $this->getStore(), - $this->dateTime->toTimestamp($this->getCreatedAt()), + $this->getCreatedAt(), true ); } diff --git a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportBestsellersData.php b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportBestsellersData.php index 4ddd51afacdce51cc71737d3ad35e607249ba469..e31a27b612e148a9e34f777baad7d0c03960342c 100644 --- a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportBestsellersData.php +++ b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportBestsellersData.php @@ -52,7 +52,7 @@ class AggregateSalesReportBestsellersData { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->sub(new \DateInterval('PT25H')); $this->bestsellersFactory->create()->aggregate($date); $this->localeResolver->revert(); } diff --git a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportInvoicedData.php b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportInvoicedData.php index 53d85b00206a7608f704aca21ad9ffd232b0b664..d849812c97b37f4a6887a5a60522b6619709b578 100644 --- a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportInvoicedData.php +++ b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportInvoicedData.php @@ -49,7 +49,7 @@ class AggregateSalesReportInvoicedData { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->sub(new \DateInterval('PT25H')); $this->invoicedFactory->create()->aggregate($date); $this->localeResolver->revert(); } diff --git a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportOrderData.php b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportOrderData.php index 7e9ca13863aa433fc1ede090f8f346ed63230256..441a48958f665106fa9284a4444768c41faf8991 100644 --- a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportOrderData.php +++ b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportOrderData.php @@ -49,7 +49,7 @@ class AggregateSalesReportOrderData { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->sub(new \DateInterval('PT25H')); $this->orderFactory->create()->aggregate($date); $this->localeResolver->revert(); } diff --git a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportRefundedData.php b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportRefundedData.php index 2246aad3738ee6c67e25aa027e6879c9ecc051be..22c1d56d9a2e905bb49316aa424d0470e2e51987 100644 --- a/app/code/Magento/Sales/Model/Observer/AggregateSalesReportRefundedData.php +++ b/app/code/Magento/Sales/Model/Observer/AggregateSalesReportRefundedData.php @@ -52,7 +52,7 @@ class AggregateSalesReportRefundedData { $this->localeResolver->emulate(0); $currentDate = $this->localeDate->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->sub(new \DateInterval('PT25H')); $this->refundedFactory->create()->aggregate($date); $this->localeResolver->revert(); } diff --git a/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php b/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php index e3c1f1c0010394db484f35a9f7c0f50ee1cb4034..87bac857aa6a9a0d82fef129c00f159491d0dcd0 100644 --- a/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php +++ b/app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php @@ -390,7 +390,7 @@ abstract class AbstractPdf extends \Magento\Framework\Object $page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8'); } $page->drawText( - __('Order Date: ') . $this->_localeDate->formatDate($order->getCreatedAtStoreDate(), 'medium', false), + __('Order Date: ') . $this->_localeDate->formatDate($order->getCreatedAtStoreDate(), \IntlDateFormatter::MEDIUM, false), 35, $top -= 15, 'UTF-8' diff --git a/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php b/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php index 0526cdde459118b67e5fc53041ab18421d54d68a..43d3b6911072c8b354383f9dd07b9598a9d12eeb 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Bestsellers.php @@ -88,8 +88,8 @@ class Bestsellers extends AbstractReport /** * Aggregate Orders data by order created at * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this * @throws \Exception * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -100,7 +100,6 @@ class Bestsellers extends AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); $adapter = $this->_getWriteAdapter(); //$this->_getWriteAdapter()->beginTransaction(); diff --git a/app/code/Magento/Sales/Model/Resource/Report/Bestsellers/Collection.php b/app/code/Magento/Sales/Model/Resource/Report/Bestsellers/Collection.php index 1b4f298b38dfb66a8269ffc6bd1c1245e715f06c..3e08b43e5e835b5d0d86b04409eee4102e5f1ac3 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Bestsellers/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Bestsellers/Collection.php @@ -9,9 +9,7 @@ namespace Magento\Sales\Model\Resource\Report\Bestsellers; /** - * Report bestsellers collection - * - * @author Magento Core Team <core@magentocommerce.com> + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\AbstractCollection { @@ -23,12 +21,23 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac protected $_ratingLimit = 5; /** - * Columns for select + * Selected columns * * @var array */ protected $_selectedColumns = []; + /** + * Tables per period + * + * @var array + */ + protected $tableForPeriod = [ + 'daily' => 'sales_bestsellers_aggregated_daily', + 'monthly' => 'sales_bestsellers_aggregated_monthly', + 'yearly' => 'sales_bestsellers_aggregated_yearly', + ]; + /** * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory * @param \Psr\Log\LoggerInterface $logger @@ -45,12 +54,33 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac \Magento\Sales\Model\Resource\Report $resource, $connection = null ) { - $resource->init('sales_bestsellers_aggregated_daily'); + $resource->init($this->getTableByAggregationPeriod('daily')); parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $resource, $connection); } /** - * Retrieve columns for select + * Return ordered filed + * + * @return string + */ + protected function getOrderedField() + { + return 'qty_ordered'; + } + + /** + * Return table per period + * + * @param string $period + * @return mixed + */ + public function getTableByAggregationPeriod($period) + { + return $this->tableForPeriod[$period]; + } + + /** + * Retrieve selected columns * * @return array */ @@ -64,7 +94,7 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac } else { $this->_selectedColumns = [ 'period' => sprintf('MAX(%s)', $adapter->getDateFormatSql('period', '%Y-%m-%d')), - 'qty_ordered' => 'SUM(qty_ordered)', + $this->getOrderedField() => 'SUM(' . $this->getOrderedField() . ')', 'product_id' => 'product_id', 'product_name' => 'MAX(product_name)', 'product_price' => 'MAX(product_price)', @@ -90,8 +120,8 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac { $adapter = $this->getConnection(); $cols = $this->_getSelectedColumns(); - $cols['qty_ordered'] = 'SUM(qty_ordered)'; - $sel = $adapter->select()->from( + $cols[$this->getOrderedField()] = 'SUM(' . $this->getOrderedField() . ')'; + $select = $adapter->select()->from( $this->getResource()->getMainTable(), $cols )->where( @@ -103,18 +133,18 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac )->group( 'product_id' )->order( - 'qty_ordered DESC' + $this->getOrderedField() . ' DESC' )->limit( $this->_ratingLimit ); - $this->_applyStoresFilterToSelect($sel); + $this->_applyStoresFilterToSelect($select); - return $sel; + return $select; } /** - * Add selected data + * Init collection select * * @return $this */ @@ -125,12 +155,12 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac // if grouping by product, not by period if (!$this->_period) { $cols = $this->_getSelectedColumns(); - $cols['qty_ordered'] = 'SUM(qty_ordered)'; + $cols[$this->getOrderedField()] = 'SUM(' . $this->getOrderedField() . ')'; if ($this->_from || $this->_to) { - $mainTable = $this->getTable('sales_bestsellers_aggregated_daily'); + $mainTable = $this->getTable($this->getTableByAggregationPeriod('daily')); $select->from($mainTable, $cols); } else { - $mainTable = $this->getTable('sales_bestsellers_aggregated_yearly'); + $mainTable = $this->getTable($this->getTableByAggregationPeriod('yearly')); $select->from($mainTable, $cols); } @@ -147,7 +177,7 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac )->group( 'product_id' )->order( - 'qty_ordered ' . \Magento\Framework\DB\Select::SQL_DESC + $this->getOrderedField() . ' ' . \Magento\Framework\DB\Select::SQL_DESC )->limit( $this->_ratingLimit ); @@ -156,13 +186,13 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac } if ('year' == $this->_period) { - $mainTable = $this->getTable('sales_bestsellers_aggregated_yearly'); + $mainTable = $this->getTable($this->getTableByAggregationPeriod('yearly')); $select->from($mainTable, $this->_getSelectedColumns()); } elseif ('month' == $this->_period) { - $mainTable = $this->getTable('sales_bestsellers_aggregated_monthly'); + $mainTable = $this->getTable($this->getTableByAggregationPeriod('monthly')); $select->from($mainTable, $this->_getSelectedColumns()); } else { - $mainTable = $this->getTable('sales_bestsellers_aggregated_daily'); + $mainTable = $this->getTable($this->getTableByAggregationPeriod('daily')); $select->from($mainTable, $this->_getSelectedColumns()); } if (!$this->isTotals()) { @@ -219,7 +249,7 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac * Redeclare parent method for applying filters after parent method * but before adding unions and calculating totals * - * @return $this + * @return $this|\Magento\Framework\Model\Resource\Db\Collection\AbstractCollection * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -231,74 +261,64 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac $this->_applyStoresFilter(); if ($this->_period) { - // $selectUnions = []; // apply date boundaries (before calling $this->_applyDateRangeFilter()) - $dtFormat = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; - $periodFrom = !is_null($this->_from) ? new \Magento\Framework\Stdlib\DateTime\Date($this->_from, $dtFormat) : null; - $periodTo = !is_null($this->_to) ? new \Magento\Framework\Stdlib\DateTime\Date($this->_to, $dtFormat) : null; + $periodFrom = !is_null($this->_from) ? new \DateTime($this->_from) : null; + $periodTo = !is_null($this->_to) ? new \DateTime($this->_to) : null; if ('year' == $this->_period) { if ($periodFrom) { // not the first day of the year - if ($periodFrom->toValue(\Zend_Date::MONTH) != 1 || $periodFrom->toValue(\Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); + if ($periodFrom->format('m') != 1 || $periodFrom->format('d') != 1) { + $dtFrom = clone $periodFrom; // last day of the year - $dtTo = $periodFrom->getDate()->setMonth(12)->setDay(31); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $dtTo = clone $periodFrom; + $dtTo->setDate($dtTo->format('Y'), 12, 31); + if (!$periodTo || $dtTo < $periodTo) { $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) + $dtFrom->format('Y-m-d'), + $dtTo->format('Y-m-d') ); // first day of the next year - $this->_from = $periodFrom->getDate()->addYear( - 1 - )->setMonth( - 1 - )->setDay( - 1 - )->toString( - $dtFormat - ); + $this->_from = clone $periodFrom; + $this->_from->modify('+1 year'); + $this->_from->setDate($this->_from->format('Y'), 1, 1); + $this->_from = $this->_from->format('Y-m-d'); } } } if ($periodTo) { // not the last day of the year - if ($periodTo->toValue(\Zend_Date::MONTH) != 12 || $periodTo->toValue(\Zend_Date::DAY) != 31) { - $dtFrom = $periodTo->getDate()->setMonth(1)->setDay(1); + if ($periodTo->format('m') != 12 || $periodTo->format('d') != 31) { + $dtFrom = clone $periodTo; + $dtFrom->setDate($dtFrom->format('Y'), 1, 1); // first day of the year - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { + $dtTo = clone $periodTo; + if (!$periodFrom || $dtFrom > $periodFrom) { $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) + $dtFrom->format('Y-m-d'), + $dtTo->format('Y-m-d') ); // last day of the previous year - $this->_to = $periodTo->getDate()->subYear( - 1 - )->setMonth( - 12 - )->setDay( - 31 - )->toString( - $dtFormat - ); + $this->_to = clone $periodTo; + $this->_to->modify('-1 year'); + $this->_to->setDate($this->_to->format('Y'), 12, 31); + $this->_to = $this->_to->format('Y-m-d'); } } } if ($periodFrom && $periodTo) { // the same year - if ($periodFrom->toValue(\Zend_Date::YEAR) == $periodTo->toValue(\Zend_Date::YEAR)) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); + if ($periodTo->format('Y') == $periodFrom->format('Y')) { + $dtFrom = clone $periodFrom; + $dtTo = clone $periodTo; $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) + $dtFrom->format('Y-m-d'), + $dtTo->format('Y-m-d') ); $this->getSelect()->where('1<>1'); @@ -307,57 +327,60 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac } elseif ('month' == $this->_period) { if ($periodFrom) { // not the first day of the month - if ($periodFrom->toValue(\Zend_Date::DAY) != 1) { - $dtFrom = $periodFrom->getDate(); + if ($periodFrom->format('d') != 1) { + $dtFrom = clone $periodFrom; // last day of the month - $dtTo = $periodFrom->getDate()->addMonth(1)->setDay(1)->subDay(1); - if (!$periodTo || $dtTo->isEarlier($periodTo)) { + $dtTo = clone $periodFrom; + $dtTo->modify('+1 month'); + $dtTo->setDate($dtTo->format('Y'), $dtTo->format('m'), 1); + $dtTo->modify('-1 day'); + if (!$periodTo || $dtTo < $periodTo) { $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) + $dtFrom->format('Y-m-d'), + $dtTo->format('Y-m-d') ); // first day of the next month - $this->_from = $periodFrom->getDate()->addMonth(1)->setDay(1)->toString($dtFormat); + $this->_from = clone $periodFrom; + $this->_from->modify('+1 month'); + $this->_from->setDate($this->_from->format('Y'), $this->_from->format('m'), 1); + $this->_from = $this->_from->format('Y-m-d'); } } } if ($periodTo) { // not the last day of the month - if ($periodTo->toValue(\Zend_Date::DAY) != $periodTo->toValue(\Zend_Date::MONTH_DAYS)) { - $dtFrom = $periodTo->getDate()->setDay(1); + if ($periodTo->format('d') != $periodTo->format('t')) { + $dtFrom = clone $periodTo; + $dtFrom->setDate($dtFrom->format('Y'), $dtFrom->format('m'), 1); // first day of the month - $dtTo = $periodTo->getDate(); - if (!$periodFrom || $dtFrom->isLater($periodFrom)) { + $dtTo = clone $periodTo; + if (!$periodFrom || $dtFrom > $periodFrom) { $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) + $dtFrom->format('Y-m-d'), + $dtTo->format('Y-m-d') ); // last day of the previous month - $this->_to = $periodTo->getDate()->setDay(1)->subDay(1)->toString($dtFormat); + $this->_to = clone $periodTo; + $this->_to->setDate($this->_to->format('Y'), $this->_to->format('m'), 1); + $this->_to->modify('-1 day'); + $this->_to = $this->_to->format('Y-m-d'); } } } if ($periodFrom && $periodTo) { // the same month - if ($periodFrom->toValue( - \Zend_Date::YEAR - ) == $periodTo->toValue( - \Zend_Date::YEAR - ) && $periodFrom->toValue( - \Zend_Date::MONTH - ) == $periodTo->toValue( - \Zend_Date::MONTH - ) + if ($periodTo->format('Y') == $periodFrom->format('Y') && + $periodTo->format('m') == $periodFrom->format('m') ) { - $dtFrom = $periodFrom->getDate(); - $dtTo = $periodTo->getDate(); + $dtFrom = clone $periodFrom; + $dtTo = clone $periodTo; $selectUnions[] = $this->_makeBoundarySelect( - $dtFrom->toString($dtFormat), - $dtTo->toString($dtFormat) + $dtFrom->format('Y-m-d'), + $dtTo->format('Y-m-d') ); $this->getSelect()->where('1<>1'); @@ -384,7 +407,7 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac $this->getSelect()->reset()->from($cloneSelect, $this->getAggregatedColumns()); } else { // add sorting - $this->getSelect()->order(['period ASC', 'qty_ordered DESC']); + $this->getSelect()->order(['period ASC', $this->getOrderedField() . ' DESC']); } } diff --git a/app/code/Magento/Sales/Model/Resource/Report/Collection/AbstractCollection.php b/app/code/Magento/Sales/Model/Resource/Report/Collection/AbstractCollection.php index 8aac1910ca9c3ea6e388323fbb30e85cc707f879..c9bf2f1b8d4d324af67f2fb80a5585b064e1cb55 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Collection/AbstractCollection.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Collection/AbstractCollection.php @@ -25,7 +25,7 @@ class AbstractCollection extends \Magento\Reports\Model\Resource\Report\Collecti * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Sales\Model\Resource\Report $resource - * @param \Zend_Db_Adapter_Abstract $connection + * @param null $connection */ public function __construct( \Magento\Framework\Data\Collection\EntityFactory $entityFactory, diff --git a/app/code/Magento/Sales/Model/Resource/Report/Invoiced.php b/app/code/Magento/Sales/Model/Resource/Report/Invoiced.php index ceb64d2658b67dcee2baf3763617168bb9290570..a56ed1886c43aaba41cf50910f59dc557bb020c8 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Invoiced.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Invoiced.php @@ -25,8 +25,8 @@ class Invoiced extends AbstractReport /** * Aggregate Invoiced data * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this */ public function aggregate($from = null, $to = null) @@ -35,7 +35,6 @@ class Invoiced extends AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); $this->_aggregateByOrderCreatedAt($from, $to); $this->_aggregateByInvoiceCreatedAt($from, $to); diff --git a/app/code/Magento/Sales/Model/Resource/Report/Order.php b/app/code/Magento/Sales/Model/Resource/Report/Order.php index c128a2ba3794b24c492aac5a618f1cac2b58718f..d1b7d02ad6395e2d9bb3d86f9619b935f1b93c63 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Order.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Order.php @@ -68,8 +68,8 @@ class Order extends AbstractReport /** * Aggregate Orders data * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this */ public function aggregate($from = null, $to = null) diff --git a/app/code/Magento/Sales/Model/Resource/Report/Order/Createdat.php b/app/code/Magento/Sales/Model/Resource/Report/Order/Createdat.php index 0de50475f360db0bbc4491d5b1e3ce398f02a118..0847e441109157daef079ae1a7fa26a854f16ad2 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Order/Createdat.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Order/Createdat.php @@ -25,8 +25,8 @@ class Createdat extends \Magento\Sales\Model\Resource\Report\AbstractReport /** * Aggregate Orders data by order created at * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this */ public function aggregate($from = null, $to = null) @@ -38,8 +38,8 @@ class Createdat extends \Magento\Sales\Model\Resource\Report\AbstractReport * Aggregate Orders data by custom field * * @param string $aggregationField - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this * @throws \Exception * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -51,7 +51,6 @@ class Createdat extends \Magento\Sales\Model\Resource\Report\AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); $adapter = $this->_getWriteAdapter(); $adapter->beginTransaction(); diff --git a/app/code/Magento/Sales/Model/Resource/Report/Order/Updatedat.php b/app/code/Magento/Sales/Model/Resource/Report/Order/Updatedat.php index e8f108cf853d8ff78485bc05859fac933f24444e..be7479f9335fd9d1b123f1dd931b0c2e1d54d118 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Order/Updatedat.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Order/Updatedat.php @@ -25,8 +25,8 @@ class Updatedat extends Createdat /** * Aggregate Orders data by order updated at * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this */ public function aggregate($from = null, $to = null) diff --git a/app/code/Magento/Sales/Model/Resource/Report/Refunded.php b/app/code/Magento/Sales/Model/Resource/Report/Refunded.php index 80a0f43fb28d2daab8e2edfe8b0754a95336b731..0444f43b81077debe6c38d03212da25dacc1e8e6 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Refunded.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Refunded.php @@ -25,8 +25,8 @@ class Refunded extends AbstractReport /** * Aggregate Refunded data * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this */ public function aggregate($from = null, $to = null) @@ -35,7 +35,6 @@ class Refunded extends AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); $this->_aggregateByOrderCreatedAt($from, $to); $this->_aggregateByRefundCreatedAt($from, $to); diff --git a/app/code/Magento/Sales/Model/Resource/Report/Shipping.php b/app/code/Magento/Sales/Model/Resource/Report/Shipping.php index 5d041dac931ef9b188f71d3d873e7b12e10de816..c19e0beb5746f0dd7f5824a0a5d36ece648cdc1a 100644 --- a/app/code/Magento/Sales/Model/Resource/Report/Shipping.php +++ b/app/code/Magento/Sales/Model/Resource/Report/Shipping.php @@ -25,8 +25,8 @@ class Shipping extends AbstractReport /** * Aggregate Shipping data * - * @param string|int|\Zend_Date|array|null $from - * @param string|int|\Zend_Date|array|null $to + * @param string|int|\DateTime|array|null $from + * @param string|int|\DateTime|array|null $to * @return $this */ public function aggregate($from = null, $to = null) @@ -35,7 +35,6 @@ class Shipping extends AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); $this->_aggregateByOrderCreatedAt($from, $to); $this->_aggregateByShippingCreatedAt($from, $to); $this->_setFlagData(\Magento\Reports\Model\Flag::REPORT_SHIPPING_FLAG_CODE); diff --git a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportBestsellersDataTest.php b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportBestsellersDataTest.php index 37952d0a6371d4720f6ef9151e59da1f7efec014..3321509f914b3c0bbf83e886a850fc8d7c61b20e 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportBestsellersDataTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportBestsellersDataTest.php @@ -71,26 +71,21 @@ class AggregateSalesReportBestsellersDataTest extends \PHPUnit_Framework_TestCas /** * Set up aggregate * - * @return \Magento\Framework\Stdlib\DateTime\DateInterface + * @return \DateTime */ protected function setupAggregate() { - $date = $this->getMock('Magento\Framework\Stdlib\DateTime\Date', ['emulate', 'revert'], [], '', false); $this->localeResolverMock->expects($this->once()) ->method('emulate') ->with(0); $this->localeResolverMock->expects($this->once()) ->method('revert'); - $dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateInterface') - ->disableOriginalConstructor() - ->getMock(); - $dateMock->expects($this->once()) - ->method('subHour') - ->with(25) - ->will($this->returnValue($date)); + + $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once()) ->method('date') - ->will($this->returnValue($dateMock)); + ->will($this->returnValue($date)); + return $date; } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportInvoicedDataTest.php b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportInvoicedDataTest.php index 65d1c9daa266edb437b79e2dba421298b992cac6..602754ba9e2818ea3f73b714eaa6c3728129eb0f 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportInvoicedDataTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportInvoicedDataTest.php @@ -71,26 +71,21 @@ class AggregateSalesReportInvoicedDataTest extends \PHPUnit_Framework_TestCase /** * Set up aggregate * - * @return \Magento\Framework\Stdlib\DateTime\DateInterface + * @return \DateTime */ protected function setupAggregate() { - $date = $this->getMock('Magento\Framework\Stdlib\DateTime\Date', ['emulate', 'revert'], [], '', false); $this->localeResolverMock->expects($this->once()) ->method('emulate') ->with(0); $this->localeResolverMock->expects($this->once()) ->method('revert'); - $dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateInterface') - ->disableOriginalConstructor() - ->getMock(); - $dateMock->expects($this->once()) - ->method('subHour') - ->with(25) - ->will($this->returnValue($date)); + + $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once()) ->method('date') - ->will($this->returnValue($dateMock)); + ->will($this->returnValue($date)); + return $date; } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportOrderDataTest.php b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportOrderDataTest.php index 40279eab419ee75e37829f9e6847bbf550cc2b79..81a719a67187d865403add4a5acd1340ec13eb4e 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportOrderDataTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportOrderDataTest.php @@ -71,26 +71,21 @@ class AggregateSalesReportOrderDataTest extends \PHPUnit_Framework_TestCase /** * Set up aggregate * - * @return \Magento\Framework\Stdlib\DateTime\DateInterface + * @return \DateTime */ protected function setupAggregate() { - $date = $this->getMock('Magento\Framework\Stdlib\DateTime\Date', ['emulate', 'revert'], [], '', false); $this->localeResolverMock->expects($this->once()) ->method('emulate') ->with(0); $this->localeResolverMock->expects($this->once()) ->method('revert'); - $dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateInterface') - ->disableOriginalConstructor() - ->getMock(); - $dateMock->expects($this->once()) - ->method('subHour') - ->with(25) - ->will($this->returnValue($date)); + + $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once()) ->method('date') - ->will($this->returnValue($dateMock)); + ->will($this->returnValue($date)); + return $date; } } diff --git a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportRefundedDataTest.php b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportRefundedDataTest.php index d940eb59451f582d202883c6bbb25caa45f85150..2525439b893d638def14128b73c2e24955ea0855 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportRefundedDataTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Observer/AggregateSalesReportRefundedDataTest.php @@ -71,26 +71,21 @@ class AggregateSalesReportRefundedDataTest extends \PHPUnit_Framework_TestCase /** * Set up aggregate * - * @return \Magento\Framework\Stdlib\DateTime\DateInterface + * @return \DateTime */ protected function setupAggregate() { - $date = $this->getMock('Magento\Framework\Stdlib\DateTime\Date', ['emulate', 'revert'], [], '', false); $this->localeResolverMock->expects($this->once()) ->method('emulate') ->with(0); $this->localeResolverMock->expects($this->once()) ->method('revert'); - $dateMock = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateInterface') - ->disableOriginalConstructor() - ->getMock(); - $dateMock->expects($this->once()) - ->method('subHour') - ->with(25) - ->will($this->returnValue($date)); + + $date = (new \DateTime())->sub(new \DateInterval('PT25H')); $this->localeDateMock->expects($this->once()) ->method('date') - ->will($this->returnValue($dateMock)); + ->will($this->returnValue($date)); + return $date; } } diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/comments/view.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/comments/view.phtml index 2547a415f2cae044f9a2f618d4044ee3887964c4..cbe3b6f40e5b08784d20e03f978f0940d9ee0ddc 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/comments/view.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/comments/view.phtml @@ -27,8 +27,8 @@ <ul class="note-list"> <?php foreach ($_entity->getCommentsCollection(true) as $_comment): ?> <li> - <span class="note-list-date"><?php echo $block->formatDate($_comment->getCreatedAtDate(), 'medium') ?></span> - <span class="note-list-time"><?php echo $block->formatTime($_comment->getCreatedAtDate(), 'medium') ?></span> + <span class="note-list-date"><?php echo $block->formatDate($_comment->getCreatedAtDate(), \IntlDateFormatter::MEDIUM) ?></span> + <span class="note-list-time"><?php echo $block->formatTime($_comment->getCreatedAtDate(), \IntlDateFormatter::MEDIUM) ?></span> <span class="note-list-customer"> <?php echo __('Customer') ?> <?php if ($_comment->getIsCustomerNotified()): ?> diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml index 13e01ff7b101a5a91faa4b42220091a5510bea88..a202b3aa0dcee89d76652153dadcd23cb3e2476a 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/view/history.phtml @@ -39,8 +39,8 @@ <ul class="note-list"> <?php foreach ($block->getOrder()->getStatusHistoryCollection(true) as $_item): ?> <li> - <span class="note-list-date"><?php echo $block->formatDate($_item->getCreatedAtDate(), 'medium') ?></span> - <span class="note-list-time"><?php echo $block->formatTime($_item->getCreatedAtDate(), 'medium') ?></span> + <span class="note-list-date"><?php echo $block->formatDate($_item->getCreatedAtDate(), \IntlDateFormatter::MEDIUM) ?></span> + <span class="note-list-time"><?php echo $block->formatTime($_item->getCreatedAtDate(), \IntlDateFormatter::MEDIUM) ?></span> <span class="note-list-status"><?php echo $_item->getStatusLabel() ?></span> <span class="note-list-customer"> <?php echo __('Customer') ?> diff --git a/app/code/Magento/Sales/view/adminhtml/templates/order/view/info.phtml b/app/code/Magento/Sales/view/adminhtml/templates/order/view/info.phtml index cedcfdd1ea109fff61129463c65baa20e837627b..fbcdaf14723840f56efa7b8ea620fd93f629d4f1 100644 --- a/app/code/Magento/Sales/view/adminhtml/templates/order/view/info.phtml +++ b/app/code/Magento/Sales/view/adminhtml/templates/order/view/info.phtml @@ -10,8 +10,8 @@ <?php /** @var $block \Magento\Sales\Block\Adminhtml\Order\View\Info */ ?> <?php $_order = $block->getOrder() ?> <?php -$orderAdminDate = $block->formatDate($_order->getCreatedAtDate(), 'medium', true); -$orderStoreDate = $block->formatDate($_order->getCreatedAtStoreDate(), 'medium', true); +$orderAdminDate = $block->formatDate($_order->getCreatedAtDate(), \IntlDateFormatter::MEDIUM, true); +$orderStoreDate = $block->formatDate($_order->getCreatedAtStoreDate(), \IntlDateFormatter::MEDIUM, true); ?> <?php /* the opening and closing divs of these two clearfixes are in app\code\core\Mage\Adminhtml\view\adminhtml\sales\order\invoice\create\form.phtml */?> @@ -43,7 +43,7 @@ $orderStoreDate = $block->formatDate($_order->getCreatedAtStoreDate(), 'medium', </tr> <?php if ($orderAdminDate != $orderStoreDate):?> <tr> - <th><?php echo __('Order Date (%1)', $_order->getCreatedAtStoreDate()->getTimezone()) ?></th> + <th><?php echo __('Order Date (%1)', $_order->getCreatedAtStoreDate()->getTimezone()->getName()) ?></th> <td><?php echo $orderStoreDate ?></td> </tr> <?php endif;?> diff --git a/app/code/Magento/Sales/view/email/order_new.html b/app/code/Magento/Sales/view/email/order_new.html index b6d4877836375cd27117cb45ea2e0f85e6def466..0063a9e6b6130d7da0283b378463feb0fec1f075 100644 --- a/app/code/Magento/Sales/view/email/order_new.html +++ b/app/code/Magento/Sales/view/email/order_new.html @@ -13,7 +13,7 @@ "var store.getFrontendName()":"Store Name", "store url=\"customer/account/\"":"Customer Account Url", "var order.increment_id":"Order Id", -"var order.getCreatedAtFormated('long')":"Order Created At (datetime)", +"var order.getCreatedAtFormated(1)":"Order Created At (datetime)", "var order.getBillingAddress().format('html')":"Billing Address", "var payment_html":"Payment Details", "var order.getShippingAddress().format('html')":"Shipping Address", @@ -50,7 +50,7 @@ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; </tr> <tr> <td> - <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} <small>(placed on {{var order.getCreatedAtFormated('long')}})</small></h2> + <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} <small>(placed on {{var order.getCreatedAtFormated(1)}})</small></h2> </td> </tr> <tr> diff --git a/app/code/Magento/Sales/view/email/order_new_guest.html b/app/code/Magento/Sales/view/email/order_new_guest.html index 53f9120dd9ae29aa1e7c44426613def9e4d20e35..202714ed9b56b496a24d432f14c76ee22abe2af2 100644 --- a/app/code/Magento/Sales/view/email/order_new_guest.html +++ b/app/code/Magento/Sales/view/email/order_new_guest.html @@ -12,7 +12,7 @@ "escapehtml var=$order.getBillingAddress().getName()":"Guest Customer Name", "var store.getFrontendName()":"Store Name", "var order.increment_id":"Order Id", -"var order.getCreatedAtFormated('long')":"Order Created At (datetime)", +"var order.getCreatedAtFormated(1)":"Order Created At (datetime)", "var order.getBillingAddress().format('html')":"Billing Address", "var payment_html":"Payment Details", "var order.getShippingAddress().format('html')":"Shipping Address", @@ -48,7 +48,7 @@ body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; </tr> <tr> <td> - <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} <small>(placed on {{var order.getCreatedAtFormated('long')}})</small></h2> + <h2 style="font-size:18px; font-weight:normal; margin:0;">Your Order #{{var order.increment_id}} <small>(placed on {{var order.getCreatedAtFormated(1)}})</small></h2> </td> </tr> <tr> diff --git a/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml b/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml index 0a3d4469ac54ced19b18358d08dcfa5ebb8fb49c..4027cb5b2337af1992fdaedcba249cfae04ec113 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/comments.phtml @@ -18,7 +18,7 @@ <h3 class="subtitle"><?php echo $block->getTitle() ?></h3> <dl class="order comments"> <?php foreach ($block->getComments() as $_commentItem): ?> - <dt class="comment date"><?php echo $block->formatDate($_commentItem->getCreatedAtStoreDate(), 'medium', true) ?></dt> + <dt class="comment date"><?php echo $block->formatDate($_commentItem->getCreatedAtStoreDate(), \IntlDateFormatter::MEDIUM, true) ?></dt> <dd class="comment text"><?php echo $block->escapeHtml($_commentItem->getComment()) ?></dd> <?php endforeach; ?> </dl> diff --git a/app/code/Magento/Sales/view/frontend/templates/order/order_comments.phtml b/app/code/Magento/Sales/view/frontend/templates/order/order_comments.phtml index a13cfe16685ab15e55c7806afea62e00fbe17b62..c4bedbcdb5aeb95bd7f5aa7ec17de17de88a8875 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/order_comments.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/order_comments.phtml @@ -16,7 +16,7 @@ <div class="block-content"> <dl class="order-comments"> <?php foreach ($_history as $_historyItem): ?> - <dt class="comment-date"><?php echo $block->formatDate($_historyItem->getCreatedAtStoreDate(), 'medium', true) ?></dt> + <dt class="comment-date"><?php echo $block->formatDate($_historyItem->getCreatedAtStoreDate(), \IntlDateFormatter::MEDIUM, true) ?></dt> <dd class="comment-content"><?php echo $block->escapeHtml($_historyItem->getComment()) ?></dd> <?php endforeach; ?> </dl> diff --git a/app/code/Magento/Sales/view/frontend/templates/order/order_date.phtml b/app/code/Magento/Sales/view/frontend/templates/order/order_date.phtml index 304aa827e10dda9fb2d6e0bab31b0051b0eb1ccf..4558eccaf040abd7c1af0138ab359ff7dfde1dd7 100644 --- a/app/code/Magento/Sales/view/frontend/templates/order/order_date.phtml +++ b/app/code/Magento/Sales/view/frontend/templates/order/order_date.phtml @@ -8,4 +8,4 @@ ?> -<div class="order-date"><?php echo __('<span class="label">Order Date:</span> %1', '<date>' . $block->formatDate($block->getOrder()->getCreatedAtStoreDate(), 'long') . '</date>') ?></div> +<div class="order-date"><?php echo __('<span class="label">Order Date:</span> %1', '<date>' . $block->formatDate($block->getOrder()->getCreatedAtStoreDate(), \IntlDateFormatter::LONG) . '</date>') ?></div> diff --git a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Main.php b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Main.php index 66a0d45ed5b022ac73d4f9a762c075575a3d4c99..c0e0d6e522797fce7146788f4c2055a407554ba8 100644 --- a/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Main.php +++ b/app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Main.php @@ -257,7 +257,7 @@ class Main extends Generic implements TabInterface ] ); - $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); + $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT); $fieldset->addField( 'from_date', 'date', diff --git a/app/code/Magento/SalesRule/Block/Rss/Discounts.php b/app/code/Magento/SalesRule/Block/Rss/Discounts.php index 8227baf46e6a117128ab9af7b52e919e7e6a2199..c8691c2c9406d343979a5dcb9d5ec2550f856042 100644 --- a/app/code/Magento/SalesRule/Block/Rss/Discounts.php +++ b/app/code/Magento/SalesRule/Block/Rss/Discounts.php @@ -91,14 +91,14 @@ class Discounts extends \Magento\Framework\View\Element\AbstractBlock implements /** @var $rule \Magento\SalesRule\Model\Rule */ foreach ($this->rssModel->getDiscountCollection($websiteId, $customerGroupId) as $rule) { $toDate = $rule->getToDate() - ? '<br/>Discount End Date: ' . $this->formatDate($rule->getToDate(), 'medium') + ? '<br/>Discount End Date: ' . $this->formatDate($rule->getToDate(), \IntlDateFormatter::MEDIUM) : ''; $couponCode = $rule->getCouponCode() ? '<br/> Coupon Code: ' . $rule->getCouponCode() : ''; $description = sprintf( '<table><tr><td style="text-decoration:none;">%s<br/>Discount Start Date: %s %s %s</td></tr></table>', $rule->getDescription(), - $this->formatDate($rule->getFromDate(), 'medium'), + $this->formatDate($rule->getFromDate(), \IntlDateFormatter::MEDIUM), $toDate, $couponCode ); diff --git a/app/code/Magento/SalesRule/Model/Coupon/Massgenerator.php b/app/code/Magento/SalesRule/Model/Coupon/Massgenerator.php index 80188b18140bfc34b1e555b21df0204ee258200b..493d3cbfaf6f75c99978dde9fe5d7deeff5bb088 100644 --- a/app/code/Magento/SalesRule/Model/Coupon/Massgenerator.php +++ b/app/code/Magento/SalesRule/Model/Coupon/Massgenerator.php @@ -165,10 +165,8 @@ class Massgenerator extends \Magento\Framework\Model\AbstractModel implements } while ($this->getResource()->exists($code)); $expirationDate = $this->getToDate(); - if ($expirationDate instanceof \Zend_Date) { - $expirationDate = $expirationDate->toString( - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); + if ($expirationDate instanceof \DateTime) { + $expirationDate = $expirationDate->format('Y-m-d H:i:s'); } $coupon->setId(null) diff --git a/app/code/Magento/SalesRule/Model/Observer.php b/app/code/Magento/SalesRule/Model/Observer.php index a31d559ee54756197e8b6c1137069ad14f17c0ca..1bf3e12e752eb62bb186b8e2584322b02c9865dc 100644 --- a/app/code/Magento/SalesRule/Model/Observer.php +++ b/app/code/Magento/SalesRule/Model/Observer.php @@ -157,7 +157,7 @@ class Observer { $this->_localeResolver->emulate(0); $currentDate = $this->_localeDate->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->modify('-25 hours'); $this->_reportRule->aggregate($date); $this->_localeResolver->revert(); return $this; diff --git a/app/code/Magento/SalesRule/Model/Resource/Coupon.php b/app/code/Magento/SalesRule/Model/Resource/Coupon.php index cf3c76fbc96a15d89621aae0ad041180cd56a323..31562bda2af036466a2ebd1d0b6a545752e4c322 100644 --- a/app/code/Magento/SalesRule/Model/Resource/Coupon.php +++ b/app/code/Magento/SalesRule/Model/Resource/Coupon.php @@ -35,9 +35,9 @@ class Coupon extends \Magento\Framework\Model\Resource\Db\AbstractDb { if (!$object->getExpirationDate()) { $object->setExpirationDate(null); - } elseif ($object->getExpirationDate() instanceof \Zend_Date) { + } elseif ($object->getExpirationDate() instanceof \DateTimeInterface) { $object->setExpirationDate( - $object->getExpirationDate()->toString(\Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT) + $object->getExpirationDate()->format('Y-m-d H:i:s') ); } @@ -125,10 +125,10 @@ class Coupon extends \Magento\Framework\Model\Resource\Db\AbstractDb $updateArray['usage_per_customer'] = $rule->getUsesPerCustomer(); } - $ruleNewDate = new \Magento\Framework\Stdlib\DateTime\Date($rule->getToDate()); - $ruleOldDate = new \Magento\Framework\Stdlib\DateTime\Date($rule->getOrigData('to_date')); + $ruleNewDate = new \DateTime($rule->getToDate()); + $ruleOldDate = new \DateTime($rule->getOrigData('to_date')); - if ($ruleNewDate->compare($ruleOldDate)) { + if ($ruleNewDate != $ruleOldDate) { $updateArray['expiration_date'] = $rule->getToDate(); } diff --git a/app/code/Magento/SalesRule/Model/Resource/Report/Collection.php b/app/code/Magento/SalesRule/Model/Resource/Report/Collection.php index 4c8dc6f056004a7f75267bb76d73bbbbb9fafe71..96883618eeabdb6c71da9d0d444aff5d6d15f029 100644 --- a/app/code/Magento/SalesRule/Model/Resource/Report/Collection.php +++ b/app/code/Magento/SalesRule/Model/Resource/Report/Collection.php @@ -50,8 +50,8 @@ class Collection extends \Magento\Sales\Model\Resource\Report\Collection\Abstrac * @param \Psr\Log\LoggerInterface $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Sales\Model\Resource\Report $resource * @param \Magento\SalesRule\Model\Resource\Report\RuleFactory $ruleFactory + * @param \Magento\Sales\Model\Resource\Report $resource * @param mixed $connection */ public function __construct( diff --git a/app/code/Magento/SalesRule/Model/Resource/Report/Rule/Createdat.php b/app/code/Magento/SalesRule/Model/Resource/Report/Rule/Createdat.php index 8f87fc3feb640e41759c71091bc638bf37575cc8..09ac004deb982ed5f51a8e537d60a50617bdc763 100644 --- a/app/code/Magento/SalesRule/Model/Resource/Report/Rule/Createdat.php +++ b/app/code/Magento/SalesRule/Model/Resource/Report/Rule/Createdat.php @@ -52,8 +52,6 @@ class Createdat extends \Magento\Reports\Model\Resource\Report\AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); - $table = $this->getMainTable(); $sourceTable = $this->getTable('sales_order'); $adapter = $this->_getWriteAdapter(); diff --git a/app/code/Magento/SalesRule/Model/Rss/Discounts.php b/app/code/Magento/SalesRule/Model/Rss/Discounts.php index 2a45ca5af889a226671cb7d89f11c6b5a5cb4e76..54b45399455ada22045511adb76365de460eaa6f 100644 --- a/app/code/Magento/SalesRule/Model/Rss/Discounts.php +++ b/app/code/Magento/SalesRule/Model/Rss/Discounts.php @@ -42,7 +42,11 @@ class Discounts { /** @var $collection \Magento\SalesRule\Model\Resource\Rule\Collection */ $collection = $this->collectionFactory->create(); - $collection->addWebsiteGroupDateFilter($websiteId, $customerGroupId, $this->dateTime->now(true)) + $collection->addWebsiteGroupDateFilter( + $websiteId, + $customerGroupId, + (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) + ) ->addFieldToFilter('is_rss', 1) ->setOrder('from_date', 'desc'); $collection->load(); diff --git a/app/code/Magento/SalesRule/Test/Unit/Block/Rss/DiscountsTest.php b/app/code/Magento/SalesRule/Test/Unit/Block/Rss/DiscountsTest.php index 768ef3e4bda028936f603269f22c276d42d57b56..1205bfa3273095ee9a3f09cdd8a6d036ff55fb5c 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Block/Rss/DiscountsTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Block/Rss/DiscountsTest.php @@ -181,7 +181,7 @@ class DiscountsTest extends \PHPUnit_Framework_TestCase $ruleModel->expects($this->once())->method('getName')->will($this->returnValue($ruleData['name'])); $this->rssModel->expects($this->any())->method('getDiscountCollection') ->will($this->returnValue([$ruleModel])); - $this->timezoneInterface->expects($this->any())->method('formatDate')->will($this->returnValue('12/12/14')); + $this->timezoneInterface->expects($this->any())->method('formatDateTime')->will($this->returnValue('12/12/14')); $data = $this->block->getRssData(); diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/ObserverTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/ObserverTest.php index 9a5c7df8ff6db4e04d4fb26845c930258c4dae69..544ee949a91179d5c6b78b00ecf38ee61e246f7c 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/ObserverTest.php @@ -249,20 +249,16 @@ class ObserverTest extends \PHPUnit_Framework_TestCase public function testAggregateSalesReportCouponsData() { - $dateMock = $this->getMock('Magento\Framework\Stdlib\DateTime\DateInterface', [], [], '', false); + $data = new \DateTime(); $this->localeResolver->expects($this->once()) ->method('emulate') ->with(0); $this->localeDate->expects($this->once()) ->method('date') - ->will($this->returnValue($dateMock)); - $dateMock->expects($this->once()) - ->method('subHour') - ->with(25) - ->will($this->returnSelf()); + ->will($this->returnValue($data)); $this->reportRule->expects($this->once()) ->method('aggregate') - ->with($dateMock); + ->with($data); $this->localeResolver->expects($this->once()) ->method('revert'); diff --git a/app/code/Magento/SalesRule/Test/Unit/Model/Rss/DiscountsTest.php b/app/code/Magento/SalesRule/Test/Unit/Model/Rss/DiscountsTest.php index 7b82b5b9ef08ffbc5aa263527eaa0ef30fab38eb..e0cf41a83ec86ba02f9a60f628dc67a4ecd84dbd 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Model/Rss/DiscountsTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Model/Rss/DiscountsTest.php @@ -23,11 +23,6 @@ class DiscountsTest extends \PHPUnit_Framework_TestCase */ protected $objectManagerHelper; - /** - * @var \Magento\Framework\Stdlib\DateTime|\PHPUnit_Framework_MockObject_MockObject - */ - protected $dateTime; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -35,7 +30,6 @@ class DiscountsTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->dateTime = $this->getMock('Magento\Framework\Stdlib\DateTime'); $this->collectionFactory = $this->getMock( 'Magento\SalesRule\Model\Resource\Rule\CollectionFactory', ['create'], @@ -48,7 +42,6 @@ class DiscountsTest extends \PHPUnit_Framework_TestCase $this->discounts = $this->objectManagerHelper->getObject( 'Magento\SalesRule\Model\Rss\Discounts', [ - 'dateTime' => $this->dateTime, 'collectionFactory' => $this->collectionFactory ] ); @@ -68,7 +61,6 @@ class DiscountsTest extends \PHPUnit_Framework_TestCase '', false ); - $this->dateTime->expects($this->once())->method('now'); $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCollection)); $ruleCollection->expects($this->once())->method('addWebsiteGroupDateFilter')->will($this->returnSelf()); $ruleCollection->expects($this->once())->method('addFieldToFilter')->will($this->returnSelf()); diff --git a/app/code/Magento/Shipping/Block/Adminhtml/View.php b/app/code/Magento/Shipping/Block/Adminhtml/View.php index 70885bfe1de7e4edd45a6802ceed4686f8456624..ad98a7e5a97c95578bf1316e6e567f24de562390 100644 --- a/app/code/Magento/Shipping/Block/Adminhtml/View.php +++ b/app/code/Magento/Shipping/Block/Adminhtml/View.php @@ -96,7 +96,7 @@ class View extends \Magento\Backend\Block\Widget\Form\Container 'Shipment #%1 | %3 (%2)', $this->getShipment()->getIncrementId(), $emailSent, - $this->formatDate($this->getShipment()->getCreatedAtDate(), 'medium', true) + $this->formatDate($this->getShipment()->getCreatedAtDate(), \IntlDateFormatter::MEDIUM, true) ); } diff --git a/app/code/Magento/Shipping/Block/Tracking/Popup.php b/app/code/Magento/Shipping/Block/Tracking/Popup.php index 2959384a80acd7377399d80ca1a36fa266619e9b..0430f049fdb737fef68cb392e2856efc1349fd86 100644 --- a/app/code/Magento/Shipping/Block/Tracking/Popup.php +++ b/app/code/Magento/Shipping/Block/Tracking/Popup.php @@ -64,8 +64,8 @@ class Popup extends \Magento\Framework\View\Element\Template */ public function formatDeliveryDate($date) { - $format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); - return $this->_localeDate->date(strtotime($date), \Zend_Date::TIMESTAMP, null, false)->toString($format); + $format = $this->_localeDate->getDateFormat(\IntlDateFormatter::MEDIUM); + return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($date)), $format); } /** @@ -81,8 +81,8 @@ class Popup extends \Magento\Framework\View\Element\Template $time = $date . ' ' . $time; } - $format = $this->_localeDate->getTimeFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); - return $this->_localeDate->date(strtotime($time), \Zend_Date::TIMESTAMP, null, false)->toString($format); + $format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT); + return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($time)), $format); } /** diff --git a/app/code/Magento/Sitemap/Model/Sitemap.php b/app/code/Magento/Sitemap/Model/Sitemap.php index 8e0542d141ea130504b334f9ab5748ee541e2104..ffc884eef4af30737b8b567b63bca488a9c7ad03 100644 --- a/app/code/Magento/Sitemap/Model/Sitemap.php +++ b/app/code/Magento/Sitemap/Model/Sitemap.php @@ -411,7 +411,7 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel */ protected function _getCurrentDateTime() { - return $this->dateTime->now(); + return (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); } /** diff --git a/app/code/Magento/Store/Model/App/Emulation.php b/app/code/Magento/Store/Model/App/Emulation.php index 5b64511218ac279cc0bc1bb8c56a4e73436d9f8a..cf960361e21db45ca103210893d78fde70b45e8c 100644 --- a/app/code/Magento/Store/Model/App/Emulation.php +++ b/app/code/Magento/Store/Model/App/Emulation.php @@ -134,7 +134,7 @@ class Emulation extends \Magento\Framework\Object \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId ); - $this->_localeResolver->setLocaleCode($newLocaleCode); + $this->_localeResolver->setLocale($newLocaleCode); $this->_translate->setLocale($newLocaleCode); $this->_translate->loadData($area); @@ -182,7 +182,7 @@ class Emulation extends \Magento\Framework\Object 'store' => $this->_storeManager->getStore()->getStoreId(), ] )->setInitialLocaleCode( - $this->_localeResolver->getLocaleCode() + $this->_localeResolver->getLocale() ); } @@ -221,7 +221,7 @@ class Emulation extends \Magento\Framework\Object $initialLocaleCode, $initialArea = \Magento\Framework\App\Area::AREA_ADMIN ) { - $this->_localeResolver->setLocaleCode($initialLocaleCode); + $this->_localeResolver->setLocale($initialLocaleCode); $this->_translate->setLocale($initialLocaleCode); $this->_translate->loadData($initialArea); diff --git a/app/code/Magento/Store/Test/Unit/Model/App/EmulationTest.php b/app/code/Magento/Store/Test/Unit/Model/App/EmulationTest.php index 6a8e42dfaaeb670c577c57bc4b4e4e680f027d8e..3a78de2dee4960fe5675db9b434966cb326dff75 100644 --- a/app/code/Magento/Store/Test/Unit/Model/App/EmulationTest.php +++ b/app/code/Magento/Store/Test/Unit/Model/App/EmulationTest.php @@ -141,7 +141,7 @@ class EmulationTest extends \PHPUnit_Framework_TestCase $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->any()) ->method('getStoreId')->willReturn($initStore); - $this->localeResolverMock->expects($this->any())->method('getLocaleCode')->willReturn($initLocale); + $this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn($initLocale); $this->inlineConfigMock->expects($this->any())->method('isActive')->willReturn($newInlineTranslate); $this->viewDesignMock->expects($this->any())->method('getConfigurationDesignTheme')->willReturn($initTheme); $this->scopeConfigMock->expects($this->any())->method('getValue')->willReturn($newLocale); @@ -150,7 +150,7 @@ class EmulationTest extends \PHPUnit_Framework_TestCase $this->storeMock->expects($this->any())->method('getStoreId')->willReturn($initStore); $this->inlineTranslationMock->expects($this->any())->method('suspend')->with($newInlineTranslate); $this->viewDesignMock->expects($this->any())->method('setDesignTheme')->with($initTheme); - $this->localeResolverMock->expects($this->any())->method('setLocaleCode')->with($newLocale); + $this->localeResolverMock->expects($this->any())->method('setLocale')->with($newLocale); $this->translateMock->expects($this->any())->method('setLocale')->with($newLocale); $this->translateMock->expects($this->any())->method('loadData')->with($newArea); $this->storeManagerMock->expects($this->any()) @@ -181,7 +181,7 @@ class EmulationTest extends \PHPUnit_Framework_TestCase $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock); $this->storeMock->expects($this->once())->method('getStoreId')->willReturn($initialStore); $this->localeResolverMock->expects($this->once()) - ->method('getLocaleCode') + ->method('getLocale') ->willReturn($initLocale); $this->model->storeCurrentEnvironmentInfo(); @@ -196,7 +196,7 @@ class EmulationTest extends \PHPUnit_Framework_TestCase $this->storeManagerMock->expects($this->once()) ->method('setCurrentStore')->with($initialStore); $this->localeResolverMock->expects($this->once()) - ->method('setLocaleCode') + ->method('setLocale') ->with($initLocale); $this->translateMock->expects($this->once()) ->method('setLocale') diff --git a/app/code/Magento/Tax/Model/Observer.php b/app/code/Magento/Tax/Model/Observer.php index 834a8d825b6bdf3f8b5f35ff6f02d16ffed928d4..70767d87251dd70aa4a189d9aeecc57d95aef0ae 100644 --- a/app/code/Magento/Tax/Model/Observer.php +++ b/app/code/Magento/Tax/Model/Observer.php @@ -264,7 +264,7 @@ class Observer { $this->_localeResolver->emulate(0); $currentDate = $this->_localeDate->date(); - $date = $currentDate->subHour(25); + $date = $currentDate->modify('-25 hours'); /** @var $reportTax \Magento\Tax\Model\Resource\Report\Tax */ $reportTax = $this->_reportTaxFactory->create(); $reportTax->aggregate($date); diff --git a/app/code/Magento/Tax/Model/Resource/Report/Tax/Createdat.php b/app/code/Magento/Tax/Model/Resource/Report/Tax/Createdat.php index a54cdc3512ce1ca77c7fb3e54f5dbec453325e00..c1e02c6c840655dda3506d1b888769975a404656 100644 --- a/app/code/Magento/Tax/Model/Resource/Report/Tax/Createdat.php +++ b/app/code/Magento/Tax/Model/Resource/Report/Tax/Createdat.php @@ -50,7 +50,6 @@ class Createdat extends \Magento\Reports\Model\Resource\Report\AbstractReport $from = $this->_dateToUtc($from); $to = $this->_dateToUtc($to); - $this->_checkDates($from, $to); $writeAdapter = $this->_getWriteAdapter(); $writeAdapter->beginTransaction(); diff --git a/app/code/Magento/Theme/Model/Resource/Design.php b/app/code/Magento/Theme/Model/Resource/Design.php index 4364a24c8eec8ed77dac90ce4dbd4206e654154e..38782199dcad0b6ef86aef7fbc5f5f881b61bfd3 100644 --- a/app/code/Magento/Theme/Model/Resource/Design.php +++ b/app/code/Magento/Theme/Model/Resource/Design.php @@ -66,15 +66,10 @@ class Design extends \Magento\Framework\Model\Resource\Db\AbstractDb $object->setDateTo(null); } - if (!is_null( - $object->getDateFrom() - ) && !is_null( - $object->getDateTo() - ) && $this->dateTime->toTimestamp( - $object->getDateFrom() - ) > $this->dateTime->toTimestamp( - $object->getDateTo() - ) + if (!is_null($object->getDateFrom()) + && !is_null($object->getDateTo()) + && (new \DateTime($object->getDateFrom()))->getTimestamp() + > (new \DateTime($object->getDateTo()))->getTimestamp() ) { throw new \Magento\Framework\Exception\LocalizedException(__('Start date cannot be greater than end date.')); } diff --git a/app/code/Magento/Theme/Model/Resource/Design/Collection.php b/app/code/Magento/Theme/Model/Resource/Design/Collection.php index 82b97096f8d68894134a59e8a1f5f9d3396bbde9..dda3e02b2fcf331ccb9cc1b04c823a654c6cb0f0 100644 --- a/app/code/Magento/Theme/Model/Resource/Design/Collection.php +++ b/app/code/Magento/Theme/Model/Resource/Design/Collection.php @@ -60,7 +60,7 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac /** * Add date filter to collection * - * @param null|int|string|\Zend_Date $date + * @param null|int|string|\DateTime $date * @return $this */ public function addDateFilter($date = null) diff --git a/app/code/Magento/Theme/Model/View/Design.php b/app/code/Magento/Theme/Model/View/Design.php index 3d7e2067cc3c8f42f39bcc009ed507496d5c2704..f839d6ba900f71e2998634aa9e36776bcd863105 100644 --- a/app/code/Magento/Theme/Model/View/Design.php +++ b/app/code/Magento/Theme/Model/View/Design.php @@ -247,7 +247,7 @@ class Design implements \Magento\Framework\View\DesignInterface if (null === $this->_locale) { $this->_locale = $this->objectManager->get('Magento\Framework\Locale\ResolverInterface'); } - return $this->_locale->getLocaleCode(); + return $this->_locale->getLocale(); } /** diff --git a/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php b/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php index dbebb8dc82839d87f1ae3398a865ea3aa5a7f6f7..3c2d253a71790ddf579b6b6a5ab0a734e3fe354d 100644 --- a/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php +++ b/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php @@ -41,7 +41,7 @@ class DesignTest extends \PHPUnit_Framework_TestCase $expected = 'locale'; $localeMock = $this->getMockForAbstractClass('\Magento\Framework\Locale\ResolverInterface'); $localeMock->expects($this->once()) - ->method('getLocaleCode') + ->method('getLocale') ->will($this->returnValue($expected)); $this->objectManager->expects($this->once()) ->method('get') diff --git a/app/code/Magento/Translation/Model/Resource/String.php b/app/code/Magento/Translation/Model/Resource/String.php index d33c95badef8ec492f67f03d3abe84a0a5cf7f08..7d6891372bbad5b399c671988fccb190ed27636a 100644 --- a/app/code/Magento/Translation/Model/Resource/String.php +++ b/app/code/Magento/Translation/Model/Resource/String.php @@ -181,7 +181,7 @@ class String extends \Magento\Framework\Model\Resource\Db\AbstractDb public function deleteTranslate($string, $locale = null, $storeId = null) { if (is_null($locale)) { - $locale = $this->_localeResolver->getLocaleCode(); + $locale = $this->_localeResolver->getLocale(); } $where = ['locale = ?' => $locale, 'string = ?' => $string]; @@ -212,7 +212,7 @@ class String extends \Magento\Framework\Model\Resource\Db\AbstractDb $table = $this->getMainTable(); if (is_null($locale)) { - $locale = $this->_localeResolver->getLocaleCode(); + $locale = $this->_localeResolver->getLocale(); } if (is_null($storeId)) { diff --git a/app/code/Magento/Ui/Component/Filter/Type/Date.php b/app/code/Magento/Ui/Component/Filter/Type/Date.php index fa7a9564032774cf76e01c3078f7a403d7251ed9..90b7e16a4aeeb16e7d70fa2a4da2663a0f4df92e 100644 --- a/app/code/Magento/Ui/Component/Filter/Type/Date.php +++ b/app/code/Magento/Ui/Component/Filter/Type/Date.php @@ -6,7 +6,6 @@ namespace Magento\Ui\Component\Filter\Type; use Magento\Framework\Locale\ResolverInterface; -use Magento\Framework\LocaleInterface; use Magento\Framework\View\Element\Template\Context as TemplateContext; use Magento\Framework\View\Element\UiComponent\ConfigBuilderInterface; use Magento\Framework\View\Element\UiComponent\ConfigFactory; @@ -117,7 +116,7 @@ class Date extends FilterAbstract $value['to'] = $this->convertDate(strtotime($value['to']), $locale); } $value['datetime'] = true; - $value['locale'] = $locale->toString(); + $value['locale'] = $this->localeResolver->getLocale(); } else { $value = null; } @@ -129,33 +128,16 @@ class Date extends FilterAbstract * Convert given date to default (UTC) timezone * * @param int $date - * @param LocaleInterface $locale - * @return \Magento\Framework\Stdlib\DateTime\Date|null + * @param string $locale + * @return \DateTime|null */ - protected function convertDate($date, LocaleInterface $locale) + protected function convertDate($date, $locale) { try { - $dateObj = $this->localeDate->date(null, null, $locale, false); - - //set default timezone for store (admin) - $dateObj->setTimezone( - $this->scopeConfig->getValue( - $this->localeDate->getDefaultTimezonePath(), - \Magento\Store\Model\ScopeInterface::SCOPE_STORE - ) - ); - - //set beginning of day - $dateObj->setHour(00); - $dateObj->setMinute(00); - $dateObj->setSecond(00); - - //set date with applying timezone of store - $dateObj->set($date, null, $locale); - + $dateObj = $this->localeDate->date(new \DateTime($date), $locale, false); + $dateObj->setTime(0, 0, 0); //convert store date to default date in UTC timezone without DST - $dateObj->setTimezone(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE); - + $dateObj->setTimezone(new \DateTimeZone('UTC')); return $dateObj; } catch (\Exception $e) { return null; diff --git a/app/code/Magento/Ui/Component/Listing.php b/app/code/Magento/Ui/Component/Listing.php index efd05db22a826931acf8edfae37ce4f25c6cb533..edc8d667758a7396d77b60ba7dcdbe0f10525854 100644 --- a/app/code/Magento/Ui/Component/Listing.php +++ b/app/code/Magento/Ui/Component/Listing.php @@ -147,7 +147,7 @@ class Listing extends AbstractView foreach ($meta['fields'] as $key => $field) { if ($field['data_type'] === 'date') { $field['date_format'] = $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM + \IntlDateFormatter::MEDIUM ); } diff --git a/app/code/Magento/Ui/Test/Unit/Component/ListingTest.php b/app/code/Magento/Ui/Test/Unit/Component/ListingTest.php index a489bf14e49968ee9be6d91f4035d6626bb775cc..e5f795227c825879d26bb72cd441cdb7c32eaa22 100644 --- a/app/code/Magento/Ui/Test/Unit/Component/ListingTest.php +++ b/app/code/Magento/Ui/Test/Unit/Component/ListingTest.php @@ -154,7 +154,7 @@ class ListingTest extends \PHPUnit_Framework_TestCase $this->listingView->setData('meta', $meta); $this->localeDate->expects($this->any()) ->method('getDateTimeFormat') - ->with('medium') + ->with(\IntlDateFormatter::MEDIUM) ->willReturn('format_type'); $options = $this->getMock('Magento\Cms\Ui\DataProvider\Page\Options\PageLayout', [], [], '', false); $this->optionsFactory->expects($this->any()) diff --git a/app/code/Magento/Ui/composer.json b/app/code/Magento/Ui/composer.json index 60a6ded8ec6e28d38070c33d7bf71531b3e310e9..303f152dda5dd73a90eb7292cfb11315ea3af158 100644 --- a/app/code/Magento/Ui/composer.json +++ b/app/code/Magento/Ui/composer.json @@ -3,7 +3,6 @@ "description": "N/A", "require": { "php": "~5.5.0|~5.6.0", - "magento/module-store": "0.42.0-beta11", "magento/module-backend": "0.42.0-beta11", "magento/framework": "0.42.0-beta11", "magento/module-eav": "0.42.0-beta11", diff --git a/app/code/Magento/User/Model/Resource/User.php b/app/code/Magento/User/Model/Resource/User.php index 17f4806688a6f9a92e16bf17cac860c82274fcb3..992d8e1c834478ee040049dcd2b4518a50c54a4b 100644 --- a/app/code/Magento/User/Model/Resource/User.php +++ b/app/code/Magento/User/Model/Resource/User.php @@ -100,7 +100,10 @@ class User extends \Magento\Framework\Model\Resource\Db\AbstractDb { $adapter = $this->_getWriteAdapter(); - $data = ['logdate' => $this->dateTime->now(), 'lognum' => $user->getLognum() + 1]; + $data = [ + 'logdate' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), + 'lognum' => $user->getLognum() + 1, + ]; $condition = ['user_id = ?' => (int)$user->getUserId()]; diff --git a/app/code/Magento/User/Model/User.php b/app/code/Magento/User/Model/User.php index a2aff90186976cd054c09ab21cba5afa7b15e0f2..17579addd8c51b7f572a07f3536d5eb3e41f278b 100644 --- a/app/code/Magento/User/Model/User.php +++ b/app/code/Magento/User/Model/User.php @@ -229,7 +229,7 @@ class User extends AbstractModel implements StorageInterface 'firstname' => $this->getFirstname(), 'lastname' => $this->getLastname(), 'email' => $this->getEmail(), - 'modified' => $this->dateTime->now(), + 'modified' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), 'extra' => serialize($this->getExtra()), ]; @@ -674,7 +674,7 @@ class User extends AbstractModel implements StorageInterface throw new \Magento\Framework\Exception\LocalizedException(__('Please correct the password reset token.')); } $this->setRpToken($newToken); - $this->setRpTokenCreatedAt($this->dateTime->now()); + $this->setRpTokenCreatedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)); return $this; } @@ -695,8 +695,8 @@ class User extends AbstractModel implements StorageInterface $expirationPeriod = $this->_userData->getResetPasswordLinkExpirationPeriod(); - $currentTimestamp = $this->dateTime->toTimestamp($this->dateTime->now()); - $tokenTimestamp = $this->dateTime->toTimestamp($linkTokenCreatedAt); + $currentTimestamp = (new \DateTime())->getTimestamp(); + $tokenTimestamp = (new \DateTime($linkTokenCreatedAt))->getTimestamp(); if ($tokenTimestamp > $currentTimestamp) { return true; } diff --git a/app/code/Magento/Usps/Test/Unit/Helper/DataTest.php b/app/code/Magento/Usps/Test/Unit/Helper/DataTest.php index f7c6fa4b490940c3bc2562567edcb58c7852ade6..46f0740b94c84207a735c5ec17afc6217a791190 100644 --- a/app/code/Magento/Usps/Test/Unit/Helper/DataTest.php +++ b/app/code/Magento/Usps/Test/Unit/Helper/DataTest.php @@ -17,7 +17,6 @@ class DataTest extends \PHPUnit_Framework_TestCase $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $arguments = [ 'context' => $this->getMock('Magento\Framework\App\Helper\Context', [], [], '', false), - 'locale' => $this->getMock('Magento\Framework\Locale', [], [], '', false), ]; $this->_helperData = $helper->getObject('Magento\Usps\Helper\Data', $arguments); diff --git a/app/code/Magento/Webapi/Model/Soap/Fault.php b/app/code/Magento/Webapi/Model/Soap/Fault.php index 411b4770ddec94e48c92932b2a8350c8fa68784f..940fc85e4446b07d9e36fc3942ae4b08fbe63e6b 100644 --- a/app/code/Magento/Webapi/Model/Soap/Fault.php +++ b/app/code/Magento/Webapi/Model/Soap/Fault.php @@ -196,7 +196,7 @@ class Fault extends \RuntimeException */ public function getLanguage() { - return $this->_localeResolver->getLocale()->getLanguage(); + return \Locale::getPrimaryLanguage($this->_localeResolver->getLocale()); } /** diff --git a/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php b/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php index 7eb4036a0a2d1c83c78aba758f1c9b1d6b029f4c..fa71cf08332d5ed0f9f5a1111c1cc5d60ccdd6d7 100644 --- a/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Controller/SoapTest.php @@ -72,18 +72,13 @@ class SoapTest extends \PHPUnit_Framework_TestCase ->setMethods(['maskException']) ->getMock(); $this->_appStateMock = $this->getMock('\Magento\Framework\App\State', [], [], '', false); - $localeMock = $this->getMockBuilder('Magento\Framework\Locale') - ->disableOriginalConstructor() - ->setMethods(['getLanguage']) - ->getMock(); - $localeMock->expects($this->any())->method('getLanguage')->will($this->returnValue('en')); $localeResolverMock = $this->getMockBuilder( 'Magento\Framework\Locale\Resolver' )->disableOriginalConstructor()->setMethods( ['getLocale'] )->getMock(); - $localeResolverMock->expects($this->any())->method('getLocale')->will($this->returnValue($localeMock)); + $localeResolverMock->expects($this->any())->method('getLocale')->will($this->returnValue('en')); $this->_responseMock->expects($this->any())->method('clearHeaders')->will($this->returnSelf()); $this->_responseMock diff --git a/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php b/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php index e2f10c7c4243891ab2c08aa98261e7099f2d9c77..fa0c51de71a8019044be6578cd7bab7158450e75 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/Soap/FaultTest.php @@ -59,7 +59,7 @@ class FaultTest extends \PHPUnit_Framework_TestCase )->method( 'getLocale' )->will( - $this->returnValue(new \Zend_Locale('en_US')) + $this->returnValue('en_US') ); $this->_appStateMock = $this->getMock('\Magento\Framework\App\State', [], [], '', false); diff --git a/app/code/Magento/Wishlist/Block/AbstractBlock.php b/app/code/Magento/Wishlist/Block/AbstractBlock.php index a8a1b6a56abe0f25e76f8f9d86e853491ed2d215..b4f82d988af11f346aef365fb33350232bf19703 100644 --- a/app/code/Magento/Wishlist/Block/AbstractBlock.php +++ b/app/code/Magento/Wishlist/Block/AbstractBlock.php @@ -213,7 +213,7 @@ abstract class AbstractBlock extends \Magento\Catalog\Block\Product\AbstractProd */ public function getFormatedDate($date) { - return $this->formatDate($date, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM); + return $this->formatDate($date, \IntlDateFormatter::MEDIUM); } /** diff --git a/app/code/Magento/Wishlist/Model/LocaleQuantityProcessor.php b/app/code/Magento/Wishlist/Model/LocaleQuantityProcessor.php index 1c533cc6f4a7b0c6cd1809db5e60078a459fc7d7..ce0fdfcf8539e42909844400fabc30edf21acd23 100644 --- a/app/code/Magento/Wishlist/Model/LocaleQuantityProcessor.php +++ b/app/code/Magento/Wishlist/Model/LocaleQuantityProcessor.php @@ -38,7 +38,7 @@ class LocaleQuantityProcessor */ public function process($qty) { - $this->localFilter->setOptions(['locale' => $this->localeResolver->getLocaleCode()]); + $this->localFilter->setOptions(['locale' => $this->localeResolver->getLocale()]); $qty = $this->localFilter->filter((double)$qty); if ($qty < 0) { $qty = null; diff --git a/app/code/Magento/Wishlist/Model/Resource/Item/Collection.php b/app/code/Magento/Wishlist/Model/Resource/Item/Collection.php index 6552345f30f3dff942846b789708c352caf9cdf7..3d5b15fc2c7752c2bf1081dac7c73607f020e5b5 100644 --- a/app/code/Magento/Wishlist/Model/Resource/Item/Collection.php +++ b/app/code/Magento/Wishlist/Model/Resource/Item/Collection.php @@ -445,23 +445,16 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac $filter = []; - $now = $this->_date->date(); - $gmtOffset = (int)$this->_date->getGmtOffset(); + $gmtOffset = (new \DateTimeZone(date_default_timezone_get()))->getOffset(new \DateTime()); if (isset($constraints['from'])) { - $lastDay = new \Magento\Framework\Stdlib\DateTime\Date( - $now, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); - $lastDay->subSecond($gmtOffset)->subDay(intval($constraints['from'])); + $lastDay = new \DateTime(); + $lastDay->modify('-' . $gmtOffset . ' second')->modify('-' . $constraints['from'] . ' day'); $filter['to'] = $lastDay; } if (isset($constraints['to'])) { - $firstDay = new \Magento\Framework\Stdlib\DateTime\Date( - $now, - \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT - ); - $firstDay->subSecond($gmtOffset)->subDay(intval($constraints['to']) + 1); + $firstDay = new \DateTime(); + $firstDay->modify('-' . $gmtOffset . ' second')->modify('-' . (intval($constraints['to']) + 1) . ' day'); $filter['from'] = $firstDay; } diff --git a/app/code/Magento/Wishlist/Model/Wishlist.php b/app/code/Magento/Wishlist/Model/Wishlist.php index 6a65ef8b7f79f362e2202b0bdec1f6f8baa4ef38..03dcabd313f0c51e20d988e53b8bdfc264b0212f 100644 --- a/app/code/Magento/Wishlist/Model/Wishlist.php +++ b/app/code/Magento/Wishlist/Model/Wishlist.php @@ -295,7 +295,7 @@ class Wishlist extends \Magento\Framework\Model\AbstractModel implements \Magent $item = $this->_wishlistItemFactory->create(); $item->setProductId($product->getId()); $item->setWishlistId($this->getId()); - $item->setAddedAt($this->dateTime->now()); + $item->setAddedAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)); $item->setStoreId($storeId); $item->setOptions($product->getCustomOptions()); $item->setProduct($product); diff --git a/app/code/Magento/Wishlist/Test/Unit/Model/LocaleQuantityProcessorTest.php b/app/code/Magento/Wishlist/Test/Unit/Model/LocaleQuantityProcessorTest.php index 81b29766f1d3144c7a90349626e940043c74e842..304bef75da99b70dc51a2a96108e6bc9d99130ab 100644 --- a/app/code/Magento/Wishlist/Test/Unit/Model/LocaleQuantityProcessorTest.php +++ b/app/code/Magento/Wishlist/Test/Unit/Model/LocaleQuantityProcessorTest.php @@ -44,7 +44,7 @@ class LocaleQuantityProcessorTest extends \PHPUnit_Framework_TestCase $localCode = 'en_US'; $this->resolver->expects($this->once()) - ->method('getLocaleCode') + ->method('getLocale') ->willReturn($localCode); $this->filter->expects($this->once()) diff --git a/app/etc/di.xml b/app/etc/di.xml index 6b6b81fa43b0a42a4e9942a99ee43f1581bb252f..6ae1eaa1529f5d0f392f41de92ef6248fa7d94f0 100755 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -117,13 +117,11 @@ <preference for="Magento\Framework\Url\ScopeResolverInterface" type="Magento\Framework\Url\ScopeResolver" /> <preference for="Magento\Framework\Url\SecurityInfoInterface" type="Magento\Framework\Url\SecurityInfo\Proxy" /> <preference for="Magento\Framework\Css\PreProcessor\AdapterInterface" type="Magento\Framework\Css\PreProcessor\Adapter\Oyejorge" /> - <preference for="Magento\Framework\LocaleInterface" type="Magento\Framework\Locale" /> <preference for="Magento\Framework\Locale\CurrencyInterface" type="Magento\Framework\Locale\Currency" /> <preference for="Magento\Framework\CurrencyInterface" type="Magento\Framework\Currency" /> <preference for="Magento\Framework\Locale\FormatInterface" type="Magento\Framework\Locale\Format" /> <preference for="Magento\Framework\Locale\ResolverInterface" type="Magento\Framework\Locale\Resolver" /> <preference for="Magento\Framework\Stdlib\DateTime\TimezoneInterface" type="Magento\Framework\Stdlib\DateTime\Timezone" /> - <preference for="Magento\Framework\Stdlib\DateTime\DateInterface" type="Magento\Framework\Stdlib\DateTime\Date" /> <preference for="Magento\Framework\Less\PreProcessor\ErrorHandlerInterface" type="Magento\Framework\Less\PreProcessor\ErrorHandler" /> <preference for="Magento\Framework\Module\ResourceInterface" type="Magento\Framework\Module\Resource" /> <preference for="Magento\Framework\Pricing\Amount\AmountInterface" type="Magento\Framework\Pricing\Amount\Base" /> diff --git a/composer.json b/composer.json index 63dfea4e8a11e5131bea81fbaede3614dc76e5a3..f22f996c07214bdff779c678a7c4615c1f0f02a8 100644 --- a/composer.json +++ b/composer.json @@ -49,6 +49,7 @@ "ext-hash": "*", "ext-curl": "*", "ext-iconv": "*", + "ext-intl": "*", "sjparkinson/static-review": "~4.1", "fabpot/php-cs-fixer": "~1.2", "lusitanian/oauth": "~0.3" diff --git a/composer.lock b/composer.lock index 362b040032b7710e088c70c4a881a668f7442d21..02b43c39d185181e4bb80017a35c3dcb4b364d35 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "07ed79cc8ac7d4c2c61e13cf87cbab40", + "hash": "498056a32c33c43d23e5d2ee37362a2d", "packages": [ { "name": "composer/composer", @@ -3264,6 +3264,7 @@ "phpmd/phpmd": 0 }, "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": "~5.5.0|~5.6.0" }, @@ -3277,6 +3278,7 @@ "ext-mcrypt": "*", "ext-hash": "*", "ext-curl": "*", - "ext-iconv": "*" + "ext-iconv": "*", + "ext-intl": "*" } } diff --git a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Curl.php b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Curl.php index 388f1e37f0a7c874441aaebaf03fe78694734c26..bd1c8cce41667792e0296390e1a19aa96edb8534 100644 --- a/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Curl.php +++ b/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Curl.php @@ -22,7 +22,7 @@ class Curl extends Adapter\Rest\CurlClient */ public function constructResourceUrl($resourcePath) { - return rtrim(TESTS_BASE_URL, '/') . ltrim($resourcePath, '/'); + return rtrim(TESTS_BASE_URL, '/') . '/' . ltrim($resourcePath, '/'); } /** diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertSuccessfulReadinessCheck.php b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertSuccessfulReadinessCheck.php index a19b294970f38555a3c5d82bd6f4ba869b60ed1d..966ec84c1741151e082c5bf3bba260a13356c17d 100644 --- a/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertSuccessfulReadinessCheck.php +++ b/dev/tests/functional/tests/app/Magento/Install/Test/Constraint/AssertSuccessfulReadinessCheck.php @@ -22,12 +22,12 @@ class AssertSuccessfulReadinessCheck extends AbstractConstraint /** * PHP extensions message. */ - const PHP_EXTENSIONS_MESSAGE = 'You meet 9 out of 9 PHP extensions requirements.'; + const PHP_EXTENSIONS_REGEXP = '/You meet (\d+) out of \1 PHP extensions requirements\./'; /** * File permission message. */ - const FILE_PERMISSION_MESSAGE = 'You meet 4 out of 4 writable file permission requirements.'; + const FILE_PERMISSION_REGEXP = '/You meet (\d+) out of \1 writable file permission requirements\./'; /** * Assert that PHP Version, PHP Extensions and File Permission are ok. @@ -42,13 +42,13 @@ class AssertSuccessfulReadinessCheck extends AbstractConstraint $installPage->getReadinessBlock()->getPhpVersionCheck(), 'PHP version is incorrect.' ); - \PHPUnit_Framework_Assert::assertContains( - self::PHP_EXTENSIONS_MESSAGE, + \PHPUnit_Framework_Assert::assertRegExp( + self::PHP_EXTENSIONS_REGEXP, $installPage->getReadinessBlock()->getPhpExtensionsCheck(), 'PHP extensions missed.' ); - \PHPUnit_Framework_Assert::assertContains( - self::FILE_PERMISSION_MESSAGE, + \PHPUnit_Framework_Assert::assertRegExp( + self::FILE_PERMISSION_REGEXP, $installPage->getReadinessBlock()->getFilePermissionCheck(), 'File permissions does not meet requirements.' ); diff --git a/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php b/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php index 7000324f0497ac79b1d562043ea838f9f4b118d8..09c21758cba336cbd15982d610875cbc0aa19117 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Model/Locale/ResolverTest.php @@ -82,7 +82,7 @@ class ResolverTest extends \PHPUnit_Framework_TestCase protected function _checkSetLocale($localeCodeToCheck) { $this->_model->setLocale(); - $localeCode = $this->_model->getLocaleCode(); + $localeCode = $this->_model->getLocale(); $this->assertEquals($localeCode, $localeCodeToCheck); } } diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php index e91f71a3dbd3ac9d75ae3bbc81c8fee7d68f1705..cbbb86dcc3fef14860c8190f3937a1661e600558 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/CompareTest.php @@ -164,9 +164,9 @@ class CompareTest extends \Magento\TestFramework\TestCase\AbstractController $visitor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\Customer\Model\Visitor'); /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); - $visitor->setSessionId(md5(time()) . md5(microtime()))->setLastVisitAt($dateTime->now())->save(); + $visitor->setSessionId(md5(time()) . md5(microtime())) + ->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)) + ->save(); /** @var $item \Magento\Catalog\Model\Product\Compare\Item */ $item = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 'Magento\Catalog\Model\Product\Compare\Item' @@ -185,11 +185,9 @@ class CompareTest extends \Magento\TestFramework\TestCase\AbstractController $visitor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\Customer\Model\Visitor'); - /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); - - $visitor->setSessionId(md5(time()) . md5(microtime()))->setLastVisitAt($dateTime->now())->save(); + $visitor->setSessionId(md5(time()) . md5(microtime())) + ->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)) + ->save(); \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( 'Magento\Customer\Model\Visitor' @@ -205,10 +203,9 @@ class CompareTest extends \Magento\TestFramework\TestCase\AbstractController /** @var $visitor \Magento\Customer\Model\Visitor */ $visitor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\Customer\Model\Visitor'); - /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); - $visitor->setSessionId(md5(time()) . md5(microtime()))->setLastVisitAt($dateTime->now())->save(); + $visitor->setSessionId(md5(time()) . md5(microtime())) + ->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)) + ->save(); /** @var $item \Magento\Catalog\Model\Product\Compare\Item */ $item = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( @@ -261,11 +258,8 @@ class CompareTest extends \Magento\TestFramework\TestCase\AbstractController /** @var $visitor \Magento\Customer\Model\Visitor */ $visitor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\Customer\Model\Visitor'); - /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); $visitor->setSessionId(md5(time()) . md5(microtime())) - ->setLastVisitAt($dateTime->now()) + ->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)) ->save(); /** @var $item \Magento\Catalog\Model\Product\Compare\Item */ diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Compare/ListCompareTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Compare/ListCompareTest.php index f22c4493d3c7f9ee744ce543e29ee79fa91d6153..f777756f478b2cfa9fb6d2495e78723729662c9e 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Compare/ListCompareTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Compare/ListCompareTest.php @@ -32,11 +32,8 @@ class ListCompareTest extends \PHPUnit_Framework_TestCase ->get('Magento\Customer\Model\Session'); $this->_visitor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\Customer\Model\Visitor'); - /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); $this->_visitor->setSessionId(md5(time()) . md5(microtime())) - ->setLastVisitAt($dateTime->now()) + ->setLastVisitAt((new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)) ->save(); $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() ->create('Magento\Catalog\Model\Product\Compare\ListCompare', ['customerVisitor' => $this->_visitor]); diff --git a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/BatchIndexTest.php b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/BatchIndexTest.php index 93c43797b8a5cec03fe6fc0eb43fdd741ea3b79f..c7b7f38879fff62de91d8f4e258e1fa366703d6e 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/BatchIndexTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/BatchIndexTest.php @@ -54,7 +54,7 @@ class BatchIndexTest extends \PHPUnit_Framework_TestCase foreach ($productIds as $productId) { $this->assertEquals( $expectedPrice, - $this->resourceRule->getRulePrice(true, 1, $customerGroupId, $productId) + $this->resourceRule->getRulePrice(new \DateTime(), 1, $customerGroupId, $productId) ); } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/IndexerBuilderTest.php b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/IndexerBuilderTest.php index 8089458347928be7defef4ab53539365700e8e17..ad347d5464a305eda52d2c705a25e8bb240e79a4 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/IndexerBuilderTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/IndexerBuilderTest.php @@ -54,7 +54,7 @@ class IndexerBuilderTest extends \PHPUnit_Framework_TestCase $this->indexerBuilder->reindexById(1); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, 1)); + $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1)); } /** @@ -74,9 +74,12 @@ class IndexerBuilderTest extends \PHPUnit_Framework_TestCase $this->productThird->getId(), ]); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, 1)); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, $this->productSecond->getId())); - $this->assertFalse($this->resourceRule->getRulePrice(true, 1, 1, $this->productThird->getId())); + $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1)); + $this->assertEquals( + 9.8, + $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productSecond->getId()) + ); + $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productThird->getId())); } /** @@ -92,9 +95,12 @@ class IndexerBuilderTest extends \PHPUnit_Framework_TestCase $this->indexerBuilder->reindexFull(); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, 1)); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, $this->productSecond->getId())); - $this->assertFalse($this->resourceRule->getRulePrice(true, 1, 1, $this->productThird->getId())); + $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1)); + $this->assertEquals( + 9.8, + $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productSecond->getId()) + ); + $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, $this->productThird->getId())); } protected function prepareProducts() diff --git a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/ProductRuleTest.php b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/ProductRuleTest.php index ca18ab512b005ee73cbc0bd75a4273874086d2ce..71b8ce0ad73268fbf5d8583bb705df8450560edc 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/ProductRuleTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/ProductRuleTest.php @@ -42,6 +42,6 @@ class ProductRuleTest extends \PHPUnit_Framework_TestCase { $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save(); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, 1)); + $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1)); } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/RuleProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/RuleProductTest.php index 4e85ae368a7c58c354f6cc2b6fa12cb58724ac1e..8019307038d680f7d03c689b5977da0847164df8 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/RuleProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogRule/Model/Indexer/RuleProductTest.php @@ -42,13 +42,13 @@ class RuleProductTest extends \PHPUnit_Framework_TestCase public function testReindexAfterRuleCreation() { $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save(); - $this->assertFalse($this->resourceRule->getRulePrice(true, 1, 1, 1)); + $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1)); $this->saveRule(); // apply all rules $this->indexBuilder->reindexFull(); - $this->assertEquals(9.8, $this->resourceRule->getRulePrice(true, 1, 1, 1)); + $this->assertEquals(9.8, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1)); } protected function saveRule() diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php index d43e59c6c79b3fdb12e57f706b66859d7675e78e..ddfde2468a29865ae2b49b43d20be0baf06da530 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/View/PersonalInfoTest.php @@ -125,7 +125,7 @@ class PersonalInfoTest extends \PHPUnit_Framework_TestCase { $createdAt = $this->_block->formatDate( $this->_loadCustomer()->getCreatedAt(), - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, + \IntlDateFormatter::MEDIUM, true ); $this->assertEquals($createdAt, $this->_block->getCreateDate()); @@ -137,14 +137,10 @@ class PersonalInfoTest extends \PHPUnit_Framework_TestCase public function testGetStoreCreateDate() { $customer = $this->_loadCustomer(); - $date = $this->_context->getLocaleDate()->scopeDate( - $customer->getStoreId(), - $this->dateTime->toTimestamp($customer->getCreatedAt()), - true - ); + $date = $this->_context->getLocaleDate()->scopeDate($customer->getStoreId(), $customer->getCreatedAt(), true); $storeCreateDate = $this->_block->formatDate( $date, - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, + \IntlDateFormatter::MEDIUM, true ); $this->assertEquals($storeCreateDate, $this->_block->getStoreCreateDate()); diff --git a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/AddressTest.php b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/AddressTest.php index e2a0c09921236ec9f1c65b164782296ee1374d81..1fc387e604fe25b2cb16dcb274e17eeda5c5e34c 100644 --- a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/AddressTest.php +++ b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Import/AddressTest.php @@ -239,15 +239,11 @@ class AddressTest extends \PHPUnit_Framework_TestCase $addressId = $objectManager->get('Magento\ImportExport\Model\Resource\Helper') ->getNextAutoincrement($tableName); - /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); - $entityData = [ 'entity_id' => $addressId, 'parent_id' => $customerId, - 'created_at' => $dateTime->now(), - 'updated_at' => $dateTime->now(), + 'created_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), + 'updated_at' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), ]; // invoke _saveAddressEntities diff --git a/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php b/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php index e506d2edf663b247b8ed3992e7403e4a4aa42265..84e30d38787589e92ec8173f6b376282ccc759a4 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Data/Form/Element/DateTest.php @@ -16,11 +16,6 @@ class DateTest extends \PHPUnit_Framework_TestCase */ protected $_elementFactory; - /** - * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface - */ - protected $_localeDate; - /** * SetUp method */ @@ -28,7 +23,6 @@ class DateTest extends \PHPUnit_Framework_TestCase { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $this->_elementFactory = $objectManager->create('Magento\Framework\Data\Form\ElementFactory'); - $this->_localeDate = $objectManager->get('Magento\Framework\Stdlib\DateTime\Timezone'); } /** @@ -36,13 +30,7 @@ class DateTest extends \PHPUnit_Framework_TestCase */ public function testGetValue(array $data, $expect) { - if (isset($data['date_format'])) { - $data['date_format'] = $this->_localeDate->getDateFormat($data['date_format']); - } - if (isset($data['time_format'])) { - $data['time_format'] = $this->_localeDate->getTimeFormat($data['time_format']); - } - /** @var $date \Magento\Framework\Data\Form\Element\Date*/ + /** @var $date \Magento\Framework\Data\Form\Element\Date */ $date = $this->_elementFactory->create('Magento\Framework\Data\Form\Element\Date', $data); $this->assertEquals($expect, $date->getValue()); } @@ -56,25 +44,25 @@ class DateTest extends \PHPUnit_Framework_TestCase return [ [ [ - 'date_format' => \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, - 'time_format' => \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, + 'date_format' => 'MM/d/yy', + 'time_format' => 'h:mm a', 'value' => $testTimestamp, ], - date('n/j/y g:i A', $testTimestamp), + date('m/j/y g:i A', $testTimestamp), ], [ [ - 'time_format' => \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, + 'time_format' => 'h:mm a', 'value' => $testTimestamp, ], date('g:i A', $testTimestamp) ], [ [ - 'date_format' => \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, + 'date_format' => 'MM/d/yy', 'value' => $testTimestamp, ], - date('n/j/y', $testTimestamp) + date('m/j/y', $testTimestamp) ] ]; } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Locale/ResolverTest.php b/dev/tests/integration/testsuite/Magento/Framework/Locale/ResolverTest.php deleted file mode 100644 index 1da30c710888e345608dacd197a155c71cd2fba9..0000000000000000000000000000000000000000 --- a/dev/tests/integration/testsuite/Magento/Framework/Locale/ResolverTest.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Locale; - -class ResolverTest extends \PHPUnit_Framework_TestCase -{ - public function testGetLocale() - { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - \Zend_Locale_Data::removeCache(); - $this->assertNull(\Zend_Locale_Data::getCache()); - $model = $objectManager->create('Magento\Framework\Locale\ResolverInterface', ['locale' => 'some_locale']); - $this->assertInstanceOf('Zend_Locale', $model->getLocale()); - $this->assertInstanceOf('Zend_Cache_Core', \Zend_Locale_Data::getCache()); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php b/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php index 72682c6beb320af2c4fec7a68932021885c49494..569cd212239ee78cf3ddb8cf4f0d9c82ee79e5aa 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/View/Element/AbstractBlockTest.php @@ -481,23 +481,6 @@ class AbstractBlockTest extends \PHPUnit_Framework_TestCase $this->assertStringMatchesFormat('http://localhost/pub/static/frontend/%s/en_US/css/styles.css', $actualResult); } - public function testFormatDate() - { - $locale = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - 'Magento\Framework\Stdlib\DateTime\TimezoneInterface' - ); - $this->assertEquals($locale->formatDate(), $this->_block->formatDate()); - } - - public function testFormatTime() - { - $locale = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - 'Magento\Framework\Stdlib\DateTime\TimezoneInterface' - ); - $time = new \Magento\Framework\Stdlib\DateTime\Date(time()); - $this->assertEquals($locale->formatTime($time), $this->_block->formatTime($time)); - } - public function testGetModuleName() { $this->assertEquals('Magento_Core', $this->_block->getModuleName()); diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Export/FilterTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Export/FilterTest.php index 2a725612b9c4659ae6b9affbc088056aff7b3a52..5006351b61fe343071d3304b46fb1b1935fe7300 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Export/FilterTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Block/Adminhtml/Export/FilterTest.php @@ -46,7 +46,7 @@ class FilterTest extends \PHPUnit_Framework_TestCase $dateFormat = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( 'Magento\Framework\Stdlib\DateTime\TimezoneInterface' )->getDateFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ); $pieces = array_filter(explode('<strong>', $html)); foreach ($pieces as $piece) { diff --git a/dev/tests/integration/testsuite/Magento/Reports/Controller/Adminhtml/Report/Product/ViewedTest.php b/dev/tests/integration/testsuite/Magento/Reports/Controller/Adminhtml/Report/Product/ViewedTest.php index b5defd098a0dad2727e0a48f30505420586cbb82..d5040c34d3fe2f0a30ad123bc615cec745fe893a 100644 --- a/dev/tests/integration/testsuite/Magento/Reports/Controller/Adminhtml/Report/Product/ViewedTest.php +++ b/dev/tests/integration/testsuite/Magento/Reports/Controller/Adminhtml/Report/Product/ViewedTest.php @@ -23,7 +23,7 @@ class ViewedTest extends \Magento\Backend\Utility\Controller public function testExecuteWithoutError() { $this->dispatch('backend/reports/report_product/viewed/filter/' . - 'cGVyaW9kX3R5cGU9ZGF5JmZyb209NDY0NjQmdG89NDY0NjQ2JnNob3dfZW1wdHlfcm93cz0w/'); + 'cGVyaW9kX3R5cGU9ZGF5JmZyb209MDIlMkYxJTJGMjAxNSZ0bz0wMiUyRjE2JTJGMjAxNSZzaG93X2VtcHR5X3Jvd3M9MA'); $actual = $this->getResponse()->getBody(); $this->assertContains('Product Views Report', $actual); $this->assertNotContains('An error occurred while showing the product views report.', $actual); diff --git a/dev/tests/integration/testsuite/Magento/Test/Integrity/ViewFileReferenceTest.php b/dev/tests/integration/testsuite/Magento/Test/Integrity/ViewFileReferenceTest.php index 6d17602e4b09cb46dfaf06825537ed63dfd5bafb..9213416e3f5e383c18dd5bc16edc28c6afc832c9 100644 --- a/dev/tests/integration/testsuite/Magento/Test/Integrity/ViewFileReferenceTest.php +++ b/dev/tests/integration/testsuite/Magento/Test/Integrity/ViewFileReferenceTest.php @@ -89,8 +89,7 @@ class ViewFileReferenceTest extends \PHPUnit_Framework_TestCase { $result = []; $patternDir = self::_getLocalePatternDir($theme); - $localeModel = new \Zend_Locale(); - foreach (array_keys($localeModel->getLocaleList()) as $locale) { + foreach (\ResourceBundle::getLocales('') as $locale) { $dir = str_replace('<locale_placeholder>', $locale, $patternDir); if (is_dir($dir)) { $result[] = $locale; diff --git a/dev/tests/integration/testsuite/Magento/Theme/Model/DesignTest.php b/dev/tests/integration/testsuite/Magento/Theme/Model/DesignTest.php index b3f8bef35c017be17b458a873882c9cf1ae1773a..4975bb5be7f1aa4de29811449a74d8727eefa2e2 100644 --- a/dev/tests/integration/testsuite/Magento/Theme/Model/DesignTest.php +++ b/dev/tests/integration/testsuite/Magento/Theme/Model/DesignTest.php @@ -98,10 +98,7 @@ class DesignTest extends \PHPUnit_Framework_TestCase */ public function testLoadChangeCache() { - /** @var \Magento\Framework\Stdlib\DateTime $dateTime */ - $dateTime = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create('Magento\Framework\Stdlib\DateTime'); - $date = $dateTime->now(true); + $date = (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); $storeId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( 'Magento\Store\Model\StoreManagerInterface' )->getDefaultStoreView()->getId(); diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 37f6f3e6f80aec5e058e10ac42ab5831466a3f8c..3c8d02398cafa1eaf5144df8a652223e28d8aece 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -792,7 +792,6 @@ return [ ['Mage_Core_Model_Config_System'], ['Mage_Core_Model_Design_Source_Apply'], ['Mage_Core_Model_Language'], - ['Magento\Core\Helper\Data'], ['Magento\Core\Model\Flag', 'Magento\Framework\Flag'], ['Magento\Framework\Model\Exception', 'Magento\Framework\Exception\LocalizedException'], ['Magento\Core\Model\AbstractModel', 'Magento\Framework\Model\AbstractModel'], @@ -2276,7 +2275,7 @@ return [ ['Magento\Core\App\Router\Base', 'Magento\Framework\App\Router\Base'], ['Magento\Core\Block\Store\Switcher', 'Magento\Store\Block\Store\Switcher'], ['Magento\Core\Block\Switcher', 'Magento\Store\Block\Switcher'], - ['Magento\Core\Helper\Cookie', 'Magento\Store\Helper\Cookie'], + ['Magento\Core\Helper\Cookie', 'Magento\Cookie\Helper\Cookie'], ['Magento\Store\Helper\Cookie', 'Magento\Cookie\Helper\Cookie'], ['Magento\Core\Model\BaseScopeResolver'], ['Magento\Core\Model\Config\Scope\Processor\Placeholder', 'Magento\Store\Model\Config\Processor\Placeholder'], @@ -2428,10 +2427,7 @@ return [ ['Magento\ObjectManager', 'Magento\Framework\ObjectManagerInterface'], ['Magento\Translate', 'Magento\Framework\Translate'], ['Magento\TranslateInterface', 'Magento\Framework\TranslateInterface'], - ['Magento\Locale', 'Magento\Framework\Locale'], - ['Magento\LocaleFactory', 'Magento\Framework\LocaleFactory'], ['Magento\Integration\Model\Oauth\Token\Factory', 'Magento\Integration\Model\Oauth\TokenFactory'], - ['Magento\LocaleInterface', 'Magento\Framework\LocaleInterface'], ['Magento\Logger', 'Psr\Log\LoggerInterface'], ['Magento\Phrase', 'Magento\Framework\Phrase'], ['Magento\Pear', 'Magento\Framework\Pear'], @@ -2999,6 +2995,10 @@ return [ ['Magento\Core\Block\RequireCookie', 'Magento\Cookie\Block\RequireCookie'], ['Magento\Core\Controller\Index\NoCookies', 'Magento\Cookie\Controller\Index\NoCookies'], ['Magento\Core\Model\Asset\Config', 'Magento\Framework\View\Asset\Config'], + ['Magento\Reports\Model\DateFactory'], + ['Magento\Framework\Stdlib\DateTime\DateFactory'], + ['Magento\Framework\Stdlib\DateTime\Date'], + ['Magento\Framework\Stdlib\DateTime\DateInterface'], ['Magento\Framework\App\Http\RequestInterface'], ['Magento\Core\Model\Layout\Merge', 'Magento\Framework\View\Model\Layout\Merge'], ['Magento\Core\Model\Layout\Translator', 'Magento\Framework\View\Model\Layout\Translator'], @@ -3104,5 +3104,14 @@ return [ ['Magento\Setup\Module\SetupFactory'], ['Magento\Framework\Module\Updater\SetupFactory'], ['Magento\Backend\Model\Config\Source\Yesno', 'Magento\Config\Model\Config\Source\Yesno'], - ['Magento\Reports\Model\Resource\Shopcart\Product\Collection'] + ['Magento\Reports\Model\Resource\Shopcart\Product\Collection'], + ['Zend_Locale', '\Locale, \ResourceBundle'], + ['Zend_Locale_Data', '\Locale, \ResourceBundle'], + ['Zend_Locale_Content', '\Locale, \ResourceBundle'], + ['Magento\LocaleInterface', '\Locale, \ResourceBundle'], + ['Magento\Framework\LocaleInterface', '\Locale, \ResourceBundle'], + ['Magento\Framework\Locale', '\Locale, \ResourceBundle'], + ['Magento\LocaleFactory'], + ['Magento\Framework\LocaleFactory'], + ['Magento\Core\Helper\Data', 'Magento\Framework\Json\Helper\Data'], ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php index 70b36b2bdcd3717b6dba722980668e7d9459c370..4c9230c1665722ee3096b802cd2a598a98f5802d 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_constants.php @@ -54,24 +54,17 @@ return [ 'Mage_Core_Model_Resource', 'Magento_Core_Model_Config_Resource::DEFAULT_WRITE_CONNECTION' ], - ['DEFAULT_CURRENCY', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::DEFAULT_CURRENCY'], ['DEFAULT_READ_CONNECTION', 'Magento\Framework\App\Resource\Config'], ['DEFAULT_WRITE_CONNECTION', 'Magento\Framework\App\Resource\Config'], ['DEFAULT_ERROR_HANDLER', 'Mage'], - ['DEFAULT_LOCALE', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::DEFAULT_LOCALE'], ['DEFAULT_THEME_NAME', 'Magento\Core\Model\Design\PackageInterface'], ['DEFAULT_THEME_NAME', 'Magento\Core\Model\Design\Package'], - ['DEFAULT_TIMEZONE', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::DEFAULT_TIMEZONE'], ['DEFAULT_STORE_ID', 'Magento\Catalog\Model\AbstractModel', 'Magento\Store\Model\Store::DEFAULT_STORE_ID'], ['DEFAULT_VALUE_TABLE_PREFIX'], ['DIVIDE_EPSILON', 'Magento\Core\Helper\Data'], ['ENTITY_PRODUCT', 'Magento\Review\Model\Review'], ['EXCEPTION_CODE_IS_GROUPED_PRODUCT'], ['FALLBACK_MAP_DIR', 'Magento\Core\Model\Design\PackageInterface'], - ['FORMAT_TYPE_FULL', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::FORMAT_TYPE_FULL'], - ['FORMAT_TYPE_LONG', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::FORMAT_TYPE_LONG'], - ['FORMAT_TYPE_MEDIUM', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::FORMAT_TYPE_MEDIUM'], - ['FORMAT_TYPE_SHORT', 'Magento\Framework\Locale', 'Magento_Core_Model_LocaleInterface::FORMAT_TYPE_SHORT'], ['GALLERY_IMAGE_TABLE', 'Magento\Catalog\Model\Resource\Product\Attribute\Backend\Media'], ['HASH_ALGO'], ['INIT_OPTION_DIRS', 'Magento\Core\Model\App', 'Magento_Core_Model_App::PARAM_APP_DIRS'], @@ -147,12 +140,6 @@ return [ 'Magento\Catalog\Model\Resource\Product\Flat\Indexer', 'XML_NODE_ATTRIBUTE_GROUPS' ], - [ - 'XML_PATH_ALLOW_CURRENCIES', - 'Magento\Framework\Locale', - 'Magento_Core_Model_LocaleInterface::XML_PATH_ALLOW_CURRENCIES' - ], - ['XML_PATH_ALLOW_CODES', 'Magento\Framework\LocaleInterface'], [ 'XML_PATH_ALLOW_DUPLICATION', 'Magento\Core\Model\Design\PackageInterface', @@ -175,15 +162,8 @@ return [ 'Magento\Framework\View\Element\Template', 'Magento\Core\Model\TemplateEngine\Plugin::XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS' ], - ['XML_PATH_DEFAULT_COUNTRY', 'Magento\Framework\Locale'], ['XML_PATH_DEFAULT_COUNTRY', 'Magento\Core\Helper\Data', 'Magento\Directory\Helper\Data::XML_PATH_DEFAULT_COUNTRY'], - ['XML_PATH_DEFAULT_LOCALE', 'Magento\Framework\Locale', 'Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE'], ['XML_PATH_DEFAULT_LOCALE', 'Magento\Core\Helper\Data', 'Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE'], - [ - 'XML_PATH_DEFAULT_TIMEZONE', - 'Magento\Framework\Locale', - 'Magento\Directory\Helper\Data::XML_PATH_DEFAULT_TIMEZONE' - ], [ 'XML_PATH_DEFAULT_TIMEZONE', 'Magento\Core\Helper\Data', diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index ffce52b8e4f2b438d4a4213c18a4c38fc59f91d7..50e8d13bcdb0bf2b36a009ea45bef00d894a28c2 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -1515,9 +1515,8 @@ return [ ['setDefaultLocale', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], ['getDefaultLocale', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], ['setLocale', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], - ['getLocale', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], - ['getLocaleCode', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], - ['setLocaleCode', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], + ['getLocale', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver::getLocale'], + ['setLocaleCode', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver::setLocale'], ['emulate', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], ['revert', 'Magento\Core\Model\Locale', 'Magento\Framework\Locale\Resolver'], ['getTimezone', 'Magento\Core\Model\Locale', 'Magento\Framework\Stdlib\DateTime\Timezone::getDefaultTimezone'], @@ -1532,7 +1531,7 @@ return [ 'Magento\Framework\Stdlib\DateTime\TimezoneInterface', 'Magento\Framework\Stdlib\DateTime\TimezoneInterface::scopeDate' ], - ['utcDate', 'Magento\Core\Model\Locale', 'Magento\Framework\Stdlib\DateTime\Timezone'], + ['utcDate', 'Magento\Core\Model\Locale'], ['storeTimeStamp', 'Magento\Core\Model\Locale', 'Magento\Framework\Stdlib\DateTime\Timezone::scopeTimeStamp'], ['formatDate', 'Magento\Core\Model\Locale', 'Magento\Framework\Stdlib\DateTime\Timezone'], ['getTranslation', 'Magento\Core\Model\Locale', 'Magento\Framework\Stdlib\DateTime\Timezone::_getTranslation'], @@ -2014,14 +2013,6 @@ return [ 'Magento\Framework\Cache\Backend\Decorator\AbstractDecorator', 'Magento\Framework\Cache\Backend\Decorator\AbstractDecorator::getCapabilities' ], - ['getLanguageTranslationList', 'Magento\Framework\LocaleInterface'], - ['getScriptTranslationList', 'Magento\Framework\LocaleInterface'], - ['getCountryTranslationList', 'Magento\Framework\LocaleInterface'], - ['getTerritoryTranslationList', 'Magento\Framework\LocaleInterface'], - ['getLanguageTranslation', 'Magento\Framework\LocaleInterface'], - ['getScriptTranslation', 'Magento\Framework\LocaleInterface'], - ['getCountryTranslation', 'Magento\Framework\LocaleInterface'], - ['getTerritoryTranslation', 'Magento\Framework\LocaleInterface'], [ 'getNoteNotify', 'Magento\Sales\Block\Adminhtml\Order\Create\Comment', @@ -2116,4 +2107,21 @@ return [ ], ['getProductEntityTypeId', 'Magento\Reports\Model\Resource\Product\Collection'], ['setProductEntityTypeId', 'Magento\Reports\Model\Resource\Product\Collection'], + ['bindLocale', 'Magento\Backend\Model\Observer'], + ['getLocaleLists', 'Magento\Dhl\Model\Resource\Setup', 'getLocaleResolver'], + ['getTranslationList', 'Magento\Framework\Locale\Lists', '\ResourceBundle'], + ['getCountryTranslationList', 'Magento\Framework\Locale\Lists', '\ResourceBundle'], + ['getTranslationList', 'Magento\Framework\Locale\ListsInterface', '\ResourceBundle'], + ['getCountryTranslationList', 'Magento\Framework\Locale\ListsInterface', '\ResourceBundle'], + ['setLocaleCode', 'Magento\Framework\Locale\ResolverInterface', 'setLocale'], + ['getLocaleCode', 'Magento\Framework\Locale\ResolverInterface', 'getLocale'], + ['setLocaleCode', 'Magento\Framework\Locale\Resolver', 'setLocale'], + ['getLocaleCode', 'Magento\Framework\Locale\Resolver', 'getLocale'], + ['_getTranslation', 'Magento\Framework\Stdlib\DateTime\Timezone', '\ResourceBundle'], + ['formatTime', 'Magento\Framework\Stdlib\DateTime\TimezoneInterface', 'formatDateTime'], + ['utcDate', 'Magento\Framework\Stdlib\DateTime\TimezoneInterface'], + ['formatTime', 'Magento\Framework\Stdlib\DateTime\Timezone', 'formatDateTime'], + ['utcDate', 'Magento\Framework\Stdlib\DateTime\Timezone'], + ['getLocaleCode', 'Magento\Framework\View\Asset\File\FallbackContext', 'getLocale'], + ['getLocaleCode', 'Magento\Paypal\Model\Api\AbstractApi', 'getLocale'], ]; diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_properties.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_properties.php index 55ec59a37848975a517bca7974d73b9340441934..f9b9c49a8b91ce39248c27cf08d31f416d28dacd 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_properties.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_properties.php @@ -118,7 +118,6 @@ return [ ['_fileIo', '\Magento\Theme\Model\Uploader\Service', '_filesystem'], ['_streamFactory', '\Magento\MediaStorage\Model\File\Storage\Config', '_filesystem'], ['_streamFactory', '\Magento\MediaStorage\Model\File\Storage\Synchronization', '_filesystem'], - ['_allowedFormats', '\Magento\Core\Helper\Data', '\Magento\Framework\Locale'], ['types', '\Magento\Core\Model\Theme'], ['_collectionFactory', '\Magento\Install\Controller\Action', 'themeProvider'], ['_collectionFactory', '\Magento\Theme\Model\Config\Customization', 'themeProvider'], @@ -392,4 +391,22 @@ return [ ['_controllerModule', 'Magento\Framework\App\Request\Http', 'controllerModule'], ['_aliases', 'Magento\Framework\App\Request\Http', 'Magento\Framework\HTTP\PhpEnvironment\Request::aliases'], ['_route', 'Magento\Framework\App\Request\Http', 'route'], + ['_localeLists', 'Magento\Backend\Block\Dashboard\Graph'], + ['backendSession', 'Magento\Backend\Model\Observer'], + ['_locale', 'Magento\CurrencySymbol\Model\System\Currencysymbol', 'localeResolver'], + ['_localeLists', 'Magento\Dhl\Model\Resource\Setup', 'localeResolver'], + ['_locale', 'Magento\Directory\Block\Currency', 'localeResolver'], + ['_locale', 'Magento\GoogleAdwords\Model\Config\Source\Language'], + ['_localeLists', 'Magento\Payment\Model\Config', 'localeResolver'], + ['zendLocale', 'Magento\Setup\Model\Lists', 'localeResolver'], + ['_locale', 'Magento\Framework\Data\Form\Filter\Date', 'localeResolver'], + ['_locale', 'Magento\Framework\Locale\Lists', 'localeResolver'], + ['_defaultLocale', 'Magento\Framework\Locale\Resolver', 'defaultLocale'], + ['_scopeType', 'Magento\Framework\Locale\Resolver', 'scopeType'], + ['_locale', 'Magento\Framework\Locale\Resolver', 'locale'], + ['_localeCode', 'Magento\Framework\Locale\Resolver', 'locale'], + ['_scopeConfig', 'Magento\Framework\Locale\Resolver', 'scopeConfig'], + ['_cache', 'Magento\Framework\Locale\Resolver'], + ['_localeFactory', 'Magento\Framework\Locale\Resolver'], + ['_emulatedLocales', 'Magento\Framework\Locale\Resolver', 'emulatedLocales'], ]; diff --git a/dev/tools/Magento/Tools/View/Deployer.php b/dev/tools/Magento/Tools/View/Deployer.php index d53dffac074590daeff91d8ef59238d359f0bb05..fafd45319ff081370c89c805a89bcc870ca235b0 100644 --- a/dev/tools/Magento/Tools/View/Deployer.php +++ b/dev/tools/Magento/Tools/View/Deployer.php @@ -125,7 +125,7 @@ class Deployer $this->count++; } $this->logger->logMessage("\nSuccessful: {$this->count} files modified\n---\n"); - $version = $this->dateTime->toTimestamp(true); + $version = (new \DateTime())->getTimestamp(); $this->logger->logMessage("New version of deployed files: {$version}"); if (!$this->isDryRun) { $this->versionStorage->save($version); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php index 7156b798695de0bf2418b8aef6d2cbb3dfbd9ad6..94a8dcbcb22a93738bba019ae1e4c9d4e168cbe6 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/View/Deployment/VersionTest.php @@ -26,17 +26,11 @@ class VersionTest extends \PHPUnit_Framework_TestCase */ private $versionStorage; - /** - * @var \Magento\Framework\Stdlib\DateTime|\PHPUnit_Framework_MockObject_MockObject - */ - private $dateTime; - protected function setUp() { $this->appState = $this->getMock('Magento\Framework\App\State', [], [], '', false); $this->versionStorage = $this->getMock('Magento\Framework\App\View\Deployment\Version\StorageInterface'); - $this->dateTime = $this->getMock('Magento\Framework\Stdlib\DateTime'); - $this->object = new Version($this->appState, $this->versionStorage, $this->dateTime); + $this->object = new Version($this->appState, $this->versionStorage); } public function testGetValueDeveloperMode() @@ -46,8 +40,7 @@ class VersionTest extends \PHPUnit_Framework_TestCase ->method('getMode') ->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER)); $this->versionStorage->expects($this->never())->method($this->anything()); - $this->dateTime->expects($this->once())->method('toTimestamp')->will($this->returnValue('123')); - $this->assertEquals('123', $this->object->getValue()); + $this->assertEquals(time(), $this->object->getValue()); $this->object->getValue(); // Ensure computation occurs only once and result is cached in memory } @@ -63,7 +56,6 @@ class VersionTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue($appMode)); $this->versionStorage->expects($this->once())->method('load')->will($this->returnValue('123')); $this->versionStorage->expects($this->never())->method('save'); - $this->dateTime->expects($this->never())->method('toTimestamp'); $this->assertEquals('123', $this->object->getValue()); $this->object->getValue(); // Ensure caching in memory } @@ -88,9 +80,8 @@ class VersionTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('load') ->will($this->throwException($storageException)); - $this->dateTime->expects($this->once())->method('toTimestamp')->will($this->returnValue('123')); - $this->versionStorage->expects($this->once())->method('save')->with('123'); - $this->assertEquals('123', $this->object->getValue()); + $this->versionStorage->expects($this->once())->method('save')->with(time()); + $this->assertEquals(time(), $this->object->getValue()); $this->object->getValue(); // Ensure caching in memory } } diff --git a/lib/internal/Magento/Framework/App/View/Deployment/Version.php b/lib/internal/Magento/Framework/App/View/Deployment/Version.php index 6e93bf046ee16ed25858ba51f2b0e7a21155626e..5220021fcdb19341dd6996aca8290c9682c7a154 100644 --- a/lib/internal/Magento/Framework/App/View/Deployment/Version.php +++ b/lib/internal/Magento/Framework/App/View/Deployment/Version.php @@ -21,9 +21,6 @@ class Version */ private $versionStorage; - /** @var \Magento\Framework\Stdlib\DateTime */ - private $dateTime; - /** * @var string */ @@ -32,16 +29,13 @@ class Version /** * @param \Magento\Framework\App\State $appState * @param Version\StorageInterface $versionStorage - * @param \Magento\Framework\Stdlib\DateTime $dateTime */ public function __construct( \Magento\Framework\App\State $appState, - \Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage, - \Magento\Framework\Stdlib\DateTime $dateTime + \Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage ) { $this->appState = $appState; $this->versionStorage = $versionStorage; - $this->dateTime = $dateTime; } /** @@ -70,13 +64,13 @@ class Version try { $result = $this->versionStorage->load(); } catch (\UnexpectedValueException $e) { - $result = $this->dateTime->toTimestamp(true); + $result = (new \DateTime())->getTimestamp(); $this->versionStorage->save($result); } break; case \Magento\Framework\App\State::MODE_DEVELOPER: - $result = $this->dateTime->toTimestamp(true); + $result = (new \DateTime())->getTimestamp(); break; default: diff --git a/lib/internal/Magento/Framework/Cache/FrontendInterface.php b/lib/internal/Magento/Framework/Cache/FrontendInterface.php index 6d4eb0368bca9f1efbe876ee051c97bb792677ed..ccc69600622a7bb240ab28acb40b935e9f79c93f 100644 --- a/lib/internal/Magento/Framework/Cache/FrontendInterface.php +++ b/lib/internal/Magento/Framework/Cache/FrontendInterface.php @@ -63,7 +63,7 @@ interface FrontendInterface public function getBackend(); /** - * Retrieve frontend instance compatible with \Zend_Locale_Data::setCache() to be used as a workaround + * Retrieve frontend instance compatible with Zend Locale Data setCache() to be used as a workaround * * @return \Zend_Cache_Core */ diff --git a/lib/internal/Magento/Framework/Cache/Test/Unit/Frontend/Decorator/BareTest.php b/lib/internal/Magento/Framework/Cache/Test/Unit/Frontend/Decorator/BareTest.php index 2ce8b438c03259ebab16b3f65be5696a072f3f2a..74af6064ceebc6cf6b4cf23be5f085f78c166ceb 100644 --- a/lib/internal/Magento/Framework/Cache/Test/Unit/Frontend/Decorator/BareTest.php +++ b/lib/internal/Magento/Framework/Cache/Test/Unit/Frontend/Decorator/BareTest.php @@ -35,7 +35,7 @@ class BareTest extends \PHPUnit_Framework_TestCase ['remove', ['record_id'], true], ['clean', [\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['tag']], true], ['getBackend', [], $this->getMock('Zend_Cache_Backend')], - ['getLowLevelFrontend', [], $this->getMock('Zend_Cache_Core')] + ['getLowLevelFrontend', [], $this->getMock('Zend_Cache_Core')], ]; } } diff --git a/lib/internal/Magento/Framework/CurrencyInterface.php b/lib/internal/Magento/Framework/CurrencyInterface.php index c24e91713c7f5da821f93f218b5e7be65d45457b..d9b211eb6fd9c43c8c45e743a2472878c6595996 100644 --- a/lib/internal/Magento/Framework/CurrencyInterface.php +++ b/lib/internal/Magento/Framework/CurrencyInterface.php @@ -32,7 +32,7 @@ interface CurrencyInterface * when no symbol is available it returns the currency shortname (f.e. FIM for Finnian Mark) * * @param string $currency (Optional) Currency name - * @param string|\Magento\Framework\Locale $locale (Optional) Locale to display informations + * @param string $locale (Optional) Locale to display informations * @return string */ public function getSymbol($currency = null, $locale = null); @@ -41,7 +41,7 @@ interface CurrencyInterface * Returns the actual or details of other currency shortnames * * @param string $currency OPTIONAL Currency's name - * @param string|\Magento\Framework\Locale $locale OPTIONAL The locale + * @param string $locale OPTIONAL The locale * @return string */ public function getShortName($currency = null, $locale = null); @@ -50,7 +50,7 @@ interface CurrencyInterface * Returns the actual or details of other currency names * * @param string $currency (Optional) Currency's short name - * @param string|\Magento\Framework\Locale $locale (Optional) The locale + * @param string $locale (Optional) The locale * @return string */ public function getName($currency = null, $locale = null); @@ -123,7 +123,7 @@ interface CurrencyInterface * Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist * 'xx_YY' will be set to 'root' because 'xx' does not exist * - * @param string|\Magento\Framework\Locale $locale (Optional) Locale for parsing input + * @param string $locale (Optional) Locale for parsing input * @throws \Zend_Currency_Exception When the given locale does not exist * @return $this */ @@ -243,7 +243,7 @@ interface CurrencyInterface /** * Sets a new exchange service * - * @param string|\Magento\Framework\CurrencyInterface_CurrencyInterface $service Service class + * @param string|\Magento\Framework\Locale\CurrencyInterface $service Service class * @return \Magento\Framework\CurrencyInterface */ public function setService($service); diff --git a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php index 2c2014ab1f6121ba83b98c7f3a3cb8c73e997267..84ab04e316702c3f3575d9b6bff71bf5db92aff6 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php +++ b/lib/internal/Magento/Framework/DB/Adapter/AdapterInterface.php @@ -666,7 +666,7 @@ interface AdapterInterface /** * Format Date to internal database date format * - * @param int|string|\Magento\Framework\Stdlib\DateTime\DateInterface $date + * @param int|string|\DateTime $date * @param boolean $includeTime * @return \Zend_Db_Expr */ diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index c8de592f1e52fafb694b6d561ad471a1162c1e13..64f38d98cfcaca8932ee42ebb185448812f0026d 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -275,7 +275,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface /** * Convert date to DB format * - * @param int|string|\Magento\Framework\Stdlib\DateTime\DateInterface $date + * @param int|string|\DateTime $date * @return \Zend_Db_Expr */ public function convertDate($date) @@ -286,7 +286,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface /** * Convert date and time to DB format * - * @param int|string|\Magento\Framework\Stdlib\DateTime\DateInterface $datetime + * @param int|string|\DateTime $datetime * @return \Zend_Db_Expr */ public function convertDateTime($datetime) @@ -1337,6 +1337,10 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface $value = new \Zend_Db_Expr('NULL'); } + if ($value instanceof \DateTimeInterface) { + $value = $value->format('Y-m-d H:i:s'); + } + return parent::quoteInto($text, $value, $type, $count); } @@ -2624,7 +2628,7 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface /** * Format Date to internal database date format * - * @param int|string|\Magento\Framework\Stdlib\DateTime\DateInterface $date + * @param int|string|\DateTime $date * @param bool $includeTime * @return \Zend_Db_Expr */ diff --git a/lib/internal/Magento/Framework/Data/Form/Element/Date.php b/lib/internal/Magento/Framework/Data/Form/Element/Date.php index 3ee7b9d5f31ca384b6a4411bbc886301a441c36e..c0121b36c626d722aa382a23dcb05ecc4424051e 100644 --- a/lib/internal/Magento/Framework/Data/Form/Element/Date.php +++ b/lib/internal/Magento/Framework/Data/Form/Element/Date.php @@ -13,24 +13,32 @@ namespace Magento\Framework\Data\Form\Element; use Magento\Framework\Escaper; use Magento\Framework\Stdlib\DateTime; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; class Date extends AbstractElement { /** - * @var \Magento\Framework\Stdlib\DateTime\Date + * @var \DateTime */ protected $_value; + /** + * @var TimezoneInterface + */ + protected $localeDate; + /** * @param Factory $factoryElement * @param CollectionFactory $factoryCollection * @param Escaper $escaper + * @param TimezoneInterface $localeDate * @param array $data */ public function __construct( Factory $factoryElement, CollectionFactory $factoryCollection, Escaper $escaper, + TimezoneInterface $localeDate, $data = [] ) { parent::__construct($factoryElement, $factoryCollection, $escaper, $data); @@ -39,6 +47,7 @@ class Date extends AbstractElement if (isset($data['value'])) { $this->setValue($data['value']); } + $this->localeDate = $localeDate; } /** @@ -60,44 +69,27 @@ class Date extends AbstractElement /** * Set date value - * If \Magento\Framework\Stdlib\DateTime\Date instance is provided instead of value, other params will be ignored. - * Format and locale must be compatible with \Magento\Framework\Stdlib\DateTime\Date * * @param mixed $value - * @param string $format - * @param string $locale * @return $this */ - public function setValue($value, $format = null, $locale = null) + public function setValue($value) { if (empty($value)) { $this->_value = ''; return $this; } - if ($value instanceof \Magento\Framework\Stdlib\DateTime\DateInterface) { + if ($value instanceof \DateTimeInterface) { $this->_value = $value; return $this; } if (preg_match('/^[0-9]+$/', $value)) { - $this->_value = new \Magento\Framework\Stdlib\DateTime\Date($this->_toTimestamp($value)); - //$this->_value = new \Magento\Framework\Stdlib\DateTime\Date((int)value); + $this->_value = (new \DateTime())->setTimestamp($this->_toTimestamp($value)); return $this; } - // last check, if input format was set - if (null === $format) { - $format = DateTime::DATETIME_INTERNAL_FORMAT; - if ($this->getInputFormat()) { - $format = $this->getInputFormat(); - } - } - // last check, if locale was set - if (null === $locale) { - if (!($locale = $this->getLocale())) { - $locale = null; - } - } + try { - $this->_value = new \Magento\Framework\Stdlib\DateTime\Date($value, $format, $locale); + $this->_value = new \DateTime($value); } catch (\Exception $e) { $this->_value = ''; } @@ -108,7 +100,7 @@ class Date extends AbstractElement * Get date value as string. * Format can be specified, or it will be taken from $this->getFormat() * - * @param string $format (compatible with \Magento\Framework\Stdlib\DateTime\Date + * @param string $format (compatible with \DateTime) * @return string */ public function getValue($format = null) @@ -121,13 +113,13 @@ class Date extends AbstractElement $format .= ($format && $this->getTimeFormat()) ? ' ' : ''; $format .= $this->getTimeFormat() ? $this->getTimeFormat() : ''; } - return $this->_value->toString($format); + return $this->localeDate->formatDateTime($this->_value, null, null, null, null, $format); } /** * Get value instance, if any * - * @return \Magento\Framework\Stdlib\DateTime\Date + * @return \DateTime */ public function getValueInstance() { @@ -140,8 +132,8 @@ class Date extends AbstractElement /** * Output the input field and assign calendar instance to it. * In order to output the date: - * - the value must be instantiated (\Magento\Framework\Stdlib\DateTime\Date) - * - output format must be set (compatible with \Magento\Framework\Stdlib\DateTime\Date) + * - the value must be instantiated (\DateTime) + * - output format must be set (compatible with \DateTime) * * @throws \Exception * @return string diff --git a/lib/internal/Magento/Framework/Data/Form/Filter/Date.php b/lib/internal/Magento/Framework/Data/Form/Filter/Date.php index c51e0797c1013bdc57b11877f764f5d4b71d8324..41c7d05c7adbd1bbe5056cef1107b76cfbdb3c41 100644 --- a/lib/internal/Magento/Framework/Data/Form/Filter/Date.php +++ b/lib/internal/Magento/Framework/Data/Form/Filter/Date.php @@ -11,6 +11,8 @@ */ namespace Magento\Framework\Data\Form\Filter; +use Magento\Framework\Stdlib\DateTime; + class Date implements \Magento\Framework\Data\Form\Filter\FilterInterface { /** @@ -23,23 +25,23 @@ class Date implements \Magento\Framework\Data\Form\Filter\FilterInterface /** * Local * - * @var \Zend_Locale + * @var \Magento\Framework\Locale\ResolverInterface */ - protected $_locale; + protected $localeResolver; /** * Initialize filter * - * @param string $format \Magento\Framework\Stdlib\DateTime\Date input/output format - * @param \Zend_Locale $locale + * @param string $format \DateTime input/output format + * @param \Magento\Framework\Locale\ResolverInterface $localeResolver */ - public function __construct($format = null, $locale = null) + public function __construct($format = null, $localeResolver = null) { if (is_null($format)) { - $format = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT; + $format = DateTime::DATE_INTERNAL_FORMAT; } $this->_dateFormat = $format; - $this->_locale = $locale; + $this->localeResolver = $localeResolver; } /** @@ -51,10 +53,10 @@ class Date implements \Magento\Framework\Data\Form\Filter\FilterInterface public function inputFilter($value) { $filterInput = new \Zend_Filter_LocalizedToNormalized( - ['date_format' => $this->_dateFormat, 'locale' => $this->_locale] + ['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()] ); $filterInternal = new \Zend_Filter_NormalizedToLocalized( - ['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale] + ['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()] ); $value = $filterInput->filter($value); @@ -71,10 +73,10 @@ class Date implements \Magento\Framework\Data\Form\Filter\FilterInterface public function outputFilter($value) { $filterInput = new \Zend_Filter_LocalizedToNormalized( - ['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->_locale] + ['date_format' => DateTime::DATE_INTERNAL_FORMAT, 'locale' => $this->localeResolver->getLocale()] ); $filterInternal = new \Zend_Filter_NormalizedToLocalized( - ['date_format' => $this->_dateFormat, 'locale' => $this->_locale] + ['date_format' => $this->_dateFormat, 'locale' => $this->localeResolver->getLocale()] ); $value = $filterInput->filter($value); diff --git a/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/DateTest.php b/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/DateTest.php index d7ea652eb90e1eb70be845c1be564816f9319173..b111c94f7623d978674d449d786736af447cb5cd 100644 --- a/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/DateTest.php +++ b/lib/internal/Magento/Framework/Data/Test/Unit/Form/Element/DateTest.php @@ -33,6 +33,11 @@ class DateTest extends \PHPUnit_Framework_TestCase */ protected $escaperMock; + /** + * @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeDateMock; + protected function setUp() { $this->factoryMock = $this->getMock('Magento\Framework\Data\Form\Element\Factory', [], [], '', false); @@ -44,10 +49,18 @@ class DateTest extends \PHPUnit_Framework_TestCase false ); $this->escaperMock = $this->getMock('Magento\Framework\Escaper', [], [], '', false); + $this->localeDateMock = $this->getMock( + '\Magento\Framework\Stdlib\DateTime\TimezoneInterface', + [], + [], + '', + false + ); $this->model = new Date( $this->factoryMock, $this->collectionFactoryMock, - $this->escaperMock + $this->escaperMock, + $this->localeDateMock ); } diff --git a/lib/internal/Magento/Framework/Locale.php b/lib/internal/Magento/Framework/Locale.php deleted file mode 100644 index 598ddc3d23872bf6c9d554faa6b311b6c60ec151..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Locale.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework; - -class Locale extends \Zend_Locale implements \Magento\Framework\LocaleInterface -{ - /** - * {@inheritdoc} - */ - public function __construct($locale = null) - { - parent::__construct($locale); - } -} diff --git a/lib/internal/Magento/Framework/Locale/Bundle/CurrencyBundle.php b/lib/internal/Magento/Framework/Locale/Bundle/CurrencyBundle.php new file mode 100644 index 0000000000000000000000000000000000000000..ba080397b5bce5ac1527ac60b81f31b99d05235f --- /dev/null +++ b/lib/internal/Magento/Framework/Locale/Bundle/CurrencyBundle.php @@ -0,0 +1,14 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Locale\Bundle; + +class CurrencyBundle extends DataBundle +{ + /** + * @var string + */ + protected $path = 'ICUDATA-curr'; +} diff --git a/lib/internal/Magento/Framework/Locale/Bundle/DataBundle.php b/lib/internal/Magento/Framework/Locale/Bundle/DataBundle.php new file mode 100644 index 0000000000000000000000000000000000000000..35d70f78512ad7b11f0f3ae696c2ce2f9fb9c363 --- /dev/null +++ b/lib/internal/Magento/Framework/Locale/Bundle/DataBundle.php @@ -0,0 +1,58 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Locale\Bundle; + +class DataBundle +{ + /** + * @var string + */ + protected $path = 'ICUDATA'; + + /** + * @var \ResourceBundle[][] + */ + protected static $bundles = []; + + /** + * Get resource bundle for the locale + * + * @param string $locale + * @return \ResourceBundle + */ + public function get($locale) + { + $locale = $this->cleanLocale($locale); + $class = get_class($this); + if (!isset(static::$bundles[$class][$locale])) { + $bundle = new \ResourceBundle($locale, $this->path); + if (!$bundle && $this->path != 'ICUDATA') { + $bundle = new \ResourceBundle($locale, 'ICUDATA'); + } + static::$bundles[$class][$locale] = $bundle; + } + return static::$bundles[$class][$locale]; + } + + /** + * Clean locale leaving only language and script + * + * @param string $locale + * @return string + */ + protected function cleanLocale($locale) + { + $localeParts = \Locale::parseLocale($locale); + $cleanLocaleParts = []; + if (isset($localeParts['language'])) { + $cleanLocaleParts['language'] = $localeParts['language']; + } + if (isset($localeParts['script'])) { + $cleanLocaleParts['script'] = $localeParts['script']; + } + return \Locale::composeLocale($cleanLocaleParts); + } +} diff --git a/lib/internal/Magento/Framework/Locale/Bundle/LanguageBundle.php b/lib/internal/Magento/Framework/Locale/Bundle/LanguageBundle.php new file mode 100644 index 0000000000000000000000000000000000000000..c9a760484fe620f7d9ef0e186eefdc9214b8730a --- /dev/null +++ b/lib/internal/Magento/Framework/Locale/Bundle/LanguageBundle.php @@ -0,0 +1,14 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Locale\Bundle; + +class LanguageBundle extends DataBundle +{ + /** + * @var string + */ + protected $path = 'ICUDATA-lang'; +} diff --git a/lib/internal/Magento/Framework/Locale/Bundle/RegionBundle.php b/lib/internal/Magento/Framework/Locale/Bundle/RegionBundle.php new file mode 100644 index 0000000000000000000000000000000000000000..e3a76b1be4ce8dcad03457b91dfb18f09b7a32c4 --- /dev/null +++ b/lib/internal/Magento/Framework/Locale/Bundle/RegionBundle.php @@ -0,0 +1,14 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Locale\Bundle; + +class RegionBundle extends DataBundle +{ + /** + * @var string + */ + protected $path = 'ICUDATA-region'; +} diff --git a/lib/internal/Magento/Framework/Locale/Bundle/TimezoneBundle.php b/lib/internal/Magento/Framework/Locale/Bundle/TimezoneBundle.php new file mode 100644 index 0000000000000000000000000000000000000000..875ebe42ad3a36a5ca9c27f22e324f906a5e1566 --- /dev/null +++ b/lib/internal/Magento/Framework/Locale/Bundle/TimezoneBundle.php @@ -0,0 +1,14 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Locale\Bundle; + +class TimezoneBundle extends DataBundle +{ + /** + * @var string + */ + protected $path = 'ICUDATA-zone'; +} diff --git a/lib/internal/Magento/Framework/Locale/Config.php b/lib/internal/Magento/Framework/Locale/Config.php index 93f619f8b5f12ce2c7829b80a82bbff1b0524edf..7f935c0b75413748932c7256532ba5dc07aaa86f 100644 --- a/lib/internal/Magento/Framework/Locale/Config.php +++ b/lib/internal/Magento/Framework/Locale/Config.php @@ -19,11 +19,11 @@ class Config implements \Magento\Framework\Locale\ConfigInterface 'ar_KW', /*Arabic (Kuwait)*/ 'ar_MA', /*Arabic (Morocco)*/ 'ar_SA', /*Arabic (Saudi Arabia)*/ - 'az_AZ', /*Azerbaijani (Azerbaijan)*/ + 'az_Latn_AZ', /*Azerbaijani (Azerbaijan)*/ 'be_BY', /*Belarusian (Belarus)*/ 'bg_BG', /*Bulgarian (Bulgaria)*/ 'bn_BD', /*Bengali (Bangladesh)*/ - 'bs_BA', /*Bosnian (Bosnia)*/ + 'bs_Latn_BA', /*Bosnian (Bosnia)*/ 'ca_ES', /*Catalan (Catalonia)*/ 'cs_CZ', /*Czech (Czech Republic)*/ 'cy_GB', /*Welsh (United Kingdom)*/ @@ -44,7 +44,7 @@ class Config implements \Magento\Framework\Locale\ConfigInterface 'es_CR', /*Spanish (Costa Rica)*/ 'es_ES', /*Spanish (Spain)*/ 'es_MX', /*Spanish (Mexico)*/ - 'es_EU', /*Basque (Basque)*/ + 'eu_ES', /*Basque (Basque)*/ 'es_PE', /*Spanish (Peru)*/ 'et_EE', /*Estonian (Estonia)*/ 'fa_IR', /*Persian (Iran)*/ @@ -69,8 +69,8 @@ class Config implements \Magento\Framework\Locale\ConfigInterface 'lt_LT', /*Lithuanian (Lithuania)*/ 'lv_LV', /*Latvian (Latvia)*/ 'mk_MK', /*Macedonian (Macedonia)*/ - 'mn_MN', /*Mongolian (Mongolia)*/ - 'ms_MY', /*Malaysian (Malaysia)*/ + 'mn_Cyrl_MN', /*Mongolian (Mongolia)*/ + 'ms_Latn_MY', /*Malaysian (Malaysia)*/ 'nl_NL', /*Dutch (Netherlands)*/ 'nb_NO', /*Norwegian BokmГ_l (Norway)*/ 'nn_NO', /*Norwegian Nynorsk (Norway)*/ @@ -82,16 +82,16 @@ class Config implements \Magento\Framework\Locale\ConfigInterface 'sk_SK', /*Slovak (Slovakia)*/ 'sl_SI', /*Slovenian (Slovenia)*/ 'sq_AL', /*Albanian (Albania)*/ - 'sr_RS', /*Serbian (Serbia)*/ + 'sr_Cyrl_RS', /*Serbian (Serbia)*/ 'sv_SE', /*Swedish (Sweden)*/ 'sw_KE', /*Swahili (Kenya)*/ 'th_TH', /*Thai (Thailand)*/ 'tr_TR', /*Turkish (Turkey)*/ 'uk_UA', /*Ukrainian (Ukraine)*/ 'vi_VN', /*Vietnamese (Vietnam)*/ - 'zh_CN', /*Chinese (China)*/ - 'zh_HK', /*Chinese (Hong Kong SAR)*/ - 'zh_TW', /*Chinese (Taiwan)*/ + 'zh_Hans_CN', /*Chinese (China)*/ + 'zh_Hant_HK', /*Chinese (Hong Kong SAR)*/ + 'zh_Hant_TW', /*Chinese (Taiwan)*/ 'es_CL', /*Spanich (Chile)*/ 'lo_LA', /*Laotian*/ 'es_VE', /*Spanish (Venezuela)*/ diff --git a/lib/internal/Magento/Framework/Locale/Currency.php b/lib/internal/Magento/Framework/Locale/Currency.php index 475c84831757212a62ac0784d19de408f1a93a45..5d3c5a9ec9b7e961d870e4a458bc4b3fa69b5b89 100644 --- a/lib/internal/Magento/Framework/Locale/Currency.php +++ b/lib/internal/Magento/Framework/Locale/Currency.php @@ -63,7 +63,7 @@ class Currency implements \Magento\Framework\Locale\CurrencyInterface public function getCurrency($currency) { \Magento\Framework\Profiler::start('locale/currency'); - if (!isset(self::$_currencyCache[$this->_localeResolver->getLocaleCode()][$currency])) { + if (!isset(self::$_currencyCache[$this->_localeResolver->getLocale()][$currency])) { $options = []; try { $currencyObject = $this->_currencyFactory->create( @@ -85,9 +85,9 @@ class Currency implements \Magento\Framework\Locale\CurrencyInterface ); $currencyObject->setFormat($options->toArray()); - self::$_currencyCache[$this->_localeResolver->getLocaleCode()][$currency] = $currencyObject; + self::$_currencyCache[$this->_localeResolver->getLocale()][$currency] = $currencyObject; } \Magento\Framework\Profiler::stop('locale/currency'); - return self::$_currencyCache[$this->_localeResolver->getLocaleCode()][$currency]; + return self::$_currencyCache[$this->_localeResolver->getLocale()][$currency]; } } diff --git a/lib/internal/Magento/Framework/Locale/Format.php b/lib/internal/Magento/Framework/Locale/Format.php index 0e19bb4039d361074c2377fb0d3ec9062fefa741..5e167880ecb8bdb6b2d1892a2efdfb7f75826832 100644 --- a/lib/internal/Magento/Framework/Locale/Format.php +++ b/lib/internal/Magento/Framework/Locale/Format.php @@ -5,6 +5,8 @@ */ namespace Magento\Framework\Locale; +use Magento\Framework\Locale\Bundle\DataBundle; + class Format implements \Magento\Framework\Locale\FormatInterface { /** @@ -83,8 +85,9 @@ class Format implements \Magento\Framework\Locale\FormatInterface */ public function getPriceFormat() { - $format = \Zend_Locale_Data::getContent($this->_localeResolver->getLocaleCode(), 'currencynumber'); - $symbols = \Zend_Locale_Data::getList($this->_localeResolver->getLocaleCode(), 'symbols'); + $numberElements = (new DataBundle())->get($this->_localeResolver->getLocale())['NumberElements']; + $format = $numberElements['latn']['patterns']['currencyFormat']; + $symbols = $numberElements['latn']['symbols']; $pos = strpos($format, ';'); if ($pos !== false) { diff --git a/lib/internal/Magento/Framework/Locale/Lists.php b/lib/internal/Magento/Framework/Locale/Lists.php index 168355d54c45dd75d54bc0f701d90155b6639026..dfe3a005a922ce333a9ac6016e7cb826ac724877 100644 --- a/lib/internal/Magento/Framework/Locale/Lists.php +++ b/lib/internal/Magento/Framework/Locale/Lists.php @@ -8,13 +8,13 @@ namespace Magento\Framework\Locale; -class Lists implements \Magento\Framework\Locale\ListsInterface -{ - /** - * @var \Magento\Framework\App\ScopeResolverInterface - */ - protected $_scopeResolver; +use Magento\Framework\Locale\Bundle\CurrencyBundle; +use Magento\Framework\Locale\Bundle\DataBundle; +use Magento\Framework\Locale\Bundle\LanguageBundle; +use Magento\Framework\Locale\Bundle\RegionBundle; +class Lists implements ListsInterface +{ /** * @var \Magento\Framework\Locale\ConfigInterface */ @@ -23,25 +23,21 @@ class Lists implements \Magento\Framework\Locale\ListsInterface /** * @var \Magento\Framework\Locale\ResolverInterface */ - protected $_localeResolver; + protected $localeResolver; /** - * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver - * @param \Magento\Framework\Locale\ConfigInterface $config * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param string $locale */ public function __construct( - \Magento\Framework\App\ScopeResolverInterface $scopeResolver, \Magento\Framework\Locale\ConfigInterface $config, \Magento\Framework\Locale\ResolverInterface $localeResolver, $locale = null ) { - $this->_scopeResolver = $scopeResolver; $this->_config = $config; - $this->_localeResolver = $localeResolver; + $this->localeResolver = $localeResolver; if ($locale !== null) { - $this->_localeResolver->setLocale($locale); + $this->localeResolver->setLocale($locale); } } @@ -70,57 +66,32 @@ class Lists implements \Magento\Framework\Locale\ListsInterface */ protected function _getOptionLocales($translatedName = false) { - $options = []; - $locales = $this->_localeResolver->getLocale()->getLocaleList(); - $languages = $this->_localeResolver->getLocale()->getTranslationList( - 'language', - $this->_localeResolver->getLocale() - ); - $countries = $this->_localeResolver->getLocale()->getTranslationList( - 'territory', - $this->_localeResolver->getLocale(), - 2 - ); - - //Zend locale codes for internal allowed locale codes - $allowed = $this->_config->getAllowedLocales(); - $allowedAliases = []; - foreach ($allowed as $code) { - $allowedAliases[\Zend_Locale::getAlias($code)] = $code; - } + $currentLocale = $this->localeResolver->getLocale(); + $locales = \ResourceBundle::getLocales(null); + $languages = (new LanguageBundle())->get($currentLocale)['Languages']; + $countries = (new RegionBundle())->get($currentLocale)['Countries']; - //Process translating to internal locale codes from Zend locale codes - $processedLocales = []; - foreach ($locales as $code => $active) { - if (array_key_exists($code, $allowedAliases)) { - $processedLocales[$allowedAliases[$code]] = $active; - } else { - $processedLocales[$code] = $active; + $options = []; + $allowedLocales = $this->_config->getAllowedLocales(); + foreach ($locales as $locale) { + if (!in_array($locale, $allowedLocales)) { + continue; } - } - - foreach (array_keys($processedLocales) as $code) { - if (strstr($code, '_')) { - if (!in_array($code, $allowed)) { - continue; - } - $data = explode('_', $code); - if (!isset($languages[$data[0]]) || !isset($countries[$data[1]])) { - continue; - } - if ($translatedName) { - $label = ucwords( - $this->_localeResolver->getLocale()->getTranslation($data[0], 'language', $code) - ) . ' (' . $this->_localeResolver->getLocale()->getTranslation( - $data[1], - 'country', - $code - ) . ') / ' . $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; - } else { - $label = $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; - } - $options[] = ['value' => $code, 'label' => $label]; + $language = \Locale::getPrimaryLanguage($locale); + $country = \Locale::getRegion($locale); + if (!$languages[$language] || !$countries[$country]) { + continue; + } + if ($translatedName) { + $label = ucwords(\Locale::getDisplayLanguage($locale, $locale)) + . ' (' . \Locale::getDisplayRegion($locale, $locale) . ') / ' + . $languages[$language] + . ' (' . $countries[$country] . ')'; + } else { + $label = $languages[$language] + . ' (' . $countries[$country] . ')'; } + $options[] = ['value' => $locale, 'label' => $label]; } return $this->_sortOptionArray($options); } @@ -131,11 +102,18 @@ class Lists implements \Magento\Framework\Locale\ListsInterface public function getOptionTimezones() { $options = []; - $zones = $this->getTranslationList('timezonetowindows'); - foreach ($zones as $windowsTimezones => $isoTimezones) { - $windowsTimezones = trim($windowsTimezones); - $options[] = ['label' => empty($windowsTimezones) ? $isoTimezones : $windowsTimezones . ' (' . $isoTimezones . ')', 'value' => $isoTimezones]; - } + $locale = $this->localeResolver->getLocale(); + $zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC); + foreach ($zones as $code) { + $options[] = [ + 'label' => \IntlTimeZone::createTimeZone($code)->getDisplayName( + false, + \IntlTimeZone::DISPLAY_LONG, + $locale + ) . ' (' . $code . ')', + 'value' => $code + ]; + } return $this->_sortOptionArray($options); } @@ -145,9 +123,12 @@ class Lists implements \Magento\Framework\Locale\ListsInterface public function getOptionWeekdays($preserveCodes = false, $ucFirstCode = false) { $options = []; - $days = $this->getTranslationList('days'); - $days = $preserveCodes ? $days['format']['wide'] : array_values($days['format']['wide']); + $days = (new DataBundle())->get( + $this->localeResolver->getLocale() + )['calendar']['gregorian']['dayNames']['format']['wide']; + $englishDays = (new DataBundle())->get('en_US')['calendar']['gregorian']['dayNames']['format']['abbreviated']; foreach ($days as $code => $name) { + $code = $preserveCodes ? $englishDays[$code] : $code; $options[] = ['label' => $name, 'value' => $ucFirstCode ? ucfirst($code) : $code]; } return $options; @@ -159,8 +140,7 @@ class Lists implements \Magento\Framework\Locale\ListsInterface public function getOptionCountries() { $options = []; - $countries = $this->getCountryTranslationList(); - + $countries = (new RegionBundle())->get($this->localeResolver->getLocale())['Countries']; foreach ($countries as $code => $name) { $options[] = ['label' => $name, 'value' => $code]; } @@ -172,16 +152,14 @@ class Lists implements \Magento\Framework\Locale\ListsInterface */ public function getOptionCurrencies() { - $currencies = $this->getTranslationList('currencytoname'); + $currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies']; $options = []; $allowed = $this->_config->getAllowedCurrencies(); - - foreach ($currencies as $name => $code) { + foreach ($currencies as $code => $data) { if (!in_array($code, $allowed)) { continue; } - - $options[] = ['label' => $name, 'value' => $code]; + $options[] = ['label' => $data[1], 'value' => $code]; } return $this->_sortOptionArray($options); } @@ -191,10 +169,10 @@ class Lists implements \Magento\Framework\Locale\ListsInterface */ public function getOptionAllCurrencies() { - $currencies = $this->getTranslationList('currencytoname'); + $currencies = (new CurrencyBundle())->get($this->localeResolver->getLocale())['Currencies']; $options = []; - foreach ($currencies as $name => $code) { - $options[] = ['label' => $name, 'value' => $code]; + foreach ($currencies as $code => $data) { + $options[] = ['label' => $data[1], 'value' => $code]; } return $this->_sortOptionArray($options); } @@ -217,33 +195,11 @@ class Lists implements \Magento\Framework\Locale\ListsInterface return $option; } - /** - * @inheritdoc - */ - public function getTranslationList($path = null, $value = null) - { - return $this->_localeResolver->getLocale()->getTranslationList( - $path, - $this->_localeResolver->getLocale(), - $value - ); - } - /** * @inheritdoc */ public function getCountryTranslation($value) { - $locale = $this->_localeResolver->getLocale(); - return $locale->getTranslation($value, 'country', $locale); - } - - /** - * @inheritdoc - */ - public function getCountryTranslationList() - { - $locale = $this->_localeResolver->getLocale(); - return $locale->getTranslationList('territory', $locale, 2); + return (new RegionBundle())->get($this->localeResolver->getLocale())['Countries'][$value]; } } diff --git a/lib/internal/Magento/Framework/Locale/ListsInterface.php b/lib/internal/Magento/Framework/Locale/ListsInterface.php index 8e5be89f79c3b53934e2b571ea76dea40995f339..881033567d8811e4bf9ac319308cc58fe7e2353b 100644 --- a/lib/internal/Magento/Framework/Locale/ListsInterface.php +++ b/lib/internal/Magento/Framework/Locale/ListsInterface.php @@ -59,29 +59,11 @@ interface ListsInterface */ public function getOptionAllCurrencies(); - /** - * Returns localized informations as array, supported are several - * types of information. - * For detailed information about the types look into the documentation - * - * @param string $path (Optional) Type of information to return - * @param string $value (Optional) Value for detail list - * @return array Array with the wished information in the given language - */ - public function getTranslationList($path = null, $value = null); - /** * Returns the localized country name * * @param $value string Name to get detailed information about - * @return array + * @return string */ public function getCountryTranslation($value); - - /** - * Returns an array with the name of all countries translated to the given language - * - * @return array - */ - public function getCountryTranslationList(); } diff --git a/lib/internal/Magento/Framework/Locale/Resolver.php b/lib/internal/Magento/Framework/Locale/Resolver.php index 8ced31491159204674ba2752e8f3cd0d9e68ca5c..b78be470920ec0638dd4a8a786d13b97470277f3 100644 --- a/lib/internal/Magento/Framework/Locale/Resolver.php +++ b/lib/internal/Magento/Framework/Locale/Resolver.php @@ -5,79 +5,58 @@ */ namespace Magento\Framework\Locale; -class Resolver implements \Magento\Framework\Locale\ResolverInterface +use Magento\Framework\App\Config\ScopeConfigInterface; + +class Resolver implements ResolverInterface { /** * Default locale code * * @var string */ - protected $_defaultLocale; + protected $defaultLocale; /** * Scope type * * @var string */ - protected $_scopeType; - - /** - * Locale object - * - * @var \Magento\Framework\LocaleInterface - */ - protected $_locale; + protected $scopeType; /** * Locale code * * @var string */ - protected $_localeCode; + protected $locale; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface + * @var ScopeConfigInterface */ - protected $_scopeConfig; - - /** - * @var \Magento\Framework\App\CacheInterface - */ - protected $_cache; + protected $scopeConfig; /** * Emulated locales stack * * @var array */ - protected $_emulatedLocales = []; - - /** - * @var \Magento\Framework\LocaleFactory - */ - protected $_localeFactory; + protected $emulatedLocales = []; /** - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Framework\App\CacheInterface $cache - * @param \Magento\Framework\LocaleFactory $localeFactory + * @param ScopeConfigInterface $scopeConfig * @param string $defaultLocalePath * @param string $scopeType * @param mixed $locale */ public function __construct( - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\App\CacheInterface $cache, - \Magento\Framework\LocaleFactory $localeFactory, + ScopeConfigInterface $scopeConfig, $defaultLocalePath, $scopeType, $locale = null ) { - $this->_cache = $cache; - $this->_scopeConfig = $scopeConfig; - $this->_localeFactory = $localeFactory; - $this->_defaultLocalePath = $defaultLocalePath; - $this->_scopeType = $scopeType; + $this->scopeConfig = $scopeConfig; + $this->defaultLocalePath = $defaultLocalePath; + $this->scopeType = $scopeType; $this->setLocale($locale); } @@ -86,7 +65,7 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface */ public function getDefaultLocalePath() { - return $this->_defaultLocalePath; + return $this->defaultLocalePath; } /** @@ -94,7 +73,7 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface */ public function setDefaultLocale($locale) { - $this->_defaultLocale = $locale; + $this->defaultLocale = $locale; return $this; } @@ -103,14 +82,14 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface */ public function getDefaultLocale() { - if (!$this->_defaultLocale) { - $locale = $this->_scopeConfig->getValue($this->getDefaultLocalePath(), $this->_scopeType); + if (!$this->defaultLocale) { + $locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType); if (!$locale) { - $locale = \Magento\Framework\Locale\ResolverInterface::DEFAULT_LOCALE; + $locale = ResolverInterface::DEFAULT_LOCALE; } - $this->_defaultLocale = $locale; + $this->defaultLocale = $locale; } - return $this->_defaultLocale; + return $this->defaultLocale; } /** @@ -119,9 +98,9 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface public function setLocale($locale = null) { if ($locale !== null && is_string($locale)) { - $this->_localeCode = $locale; + $this->locale = $locale; } else { - $this->_localeCode = $this->getDefaultLocale(); + $this->locale = $this->getDefaultLocale(); } return $this; } @@ -131,35 +110,10 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface */ public function getLocale() { - if (!$this->_locale) { - \Zend_Locale_Data::setCache($this->_cache->getFrontend()->getLowLevelFrontend()); - $this->_locale = $this->_localeFactory->create(['locale' => $this->getLocaleCode()]); - } elseif ($this->_locale->__toString() != $this->_localeCode) { - $this->setLocale($this->_localeCode); - } - - return $this->_locale; - } - - /** - * {@inheritdoc} - */ - public function getLocaleCode() - { - if ($this->_localeCode === null) { + if ($this->locale === null) { $this->setLocale(); } - return $this->_localeCode; - } - - /** - * {@inheritdoc} - */ - public function setLocaleCode($code) - { - $this->_localeCode = $code; - $this->_locale = null; - return $this; + return $this->locale; } /** @@ -169,20 +123,15 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface { $result = null; if ($scopeId) { - $this->_emulatedLocales[] = clone $this->getLocale(); - $this->_locale = $this->_localeFactory->create( - [ - 'locale' => $this->_scopeConfig->getValue( - $this->getDefaultLocalePath(), - $this->_scopeType, - $scopeId - ), - ] + $this->emulatedLocales[] = $this->getLocale(); + $this->locale = $this->scopeConfig->getValue( + $this->getDefaultLocalePath(), + $this->scopeType, + $scopeId ); - $this->_localeCode = $this->_locale->toString(); - $result = $this->_localeCode; + $result = $this->locale; } else { - $this->_emulatedLocales[] = false; + $this->emulatedLocales[] = false; } return $result; } @@ -193,11 +142,10 @@ class Resolver implements \Magento\Framework\Locale\ResolverInterface public function revert() { $result = null; - $locale = array_pop($this->_emulatedLocales); - if ($locale) { - $this->_locale = $locale; - $this->_localeCode = $this->_locale->toString(); - $result = $this->_localeCode; + $localeCode = array_pop($this->emulatedLocales); + if ($localeCode) { + $this->locale = $localeCode; + $result = $this->locale; } return $result; } diff --git a/lib/internal/Magento/Framework/Locale/ResolverInterface.php b/lib/internal/Magento/Framework/Locale/ResolverInterface.php index f74837274b537f7983e948b2bf3acc209ef74b72..08add444266f073aaa354935b6857be2c7edd34f 100644 --- a/lib/internal/Magento/Framework/Locale/ResolverInterface.php +++ b/lib/internal/Magento/Framework/Locale/ResolverInterface.php @@ -23,7 +23,7 @@ interface ResolverInterface * Set default locale code * * @param string $locale - * @return \Magento\Framework\Locale\ResolverInterface + * @return self */ public function setDefaultLocale($locale); @@ -38,31 +38,16 @@ interface ResolverInterface * Set locale * * @param string $locale - * @return \Magento\Framework\Locale\ResolverInterface + * @return self */ public function setLocale($locale = null); /** - * Retrieve locale object - * - * @return \Magento\Framework\LocaleInterface - */ - public function getLocale(); - - /** - * Retrieve locale code + * Retrieve locale * * @return string */ - public function getLocaleCode(); - - /** - * Specify current locale code - * - * @param string $code - * @return \Magento\Framework\Locale\ResolverInterface - */ - public function setLocaleCode($code); + public function getLocale(); /** * Push current locale to stack and replace with locale from specified scope diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/ConfigTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/ConfigTest.php index b88a3804748b3fa5a01cc8a96d25cc2a2fab0161..cdaecc81056df651b70f8a027950571a6a282486 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/ConfigTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/ConfigTest.php @@ -11,14 +11,14 @@ namespace Magento\Framework\Locale\Test\Unit; class ConfigTest extends \PHPUnit_Framework_TestCase { private static $allAllowedLocales = [ - 'af_ZA', 'ar_DZ', 'ar_EG', 'ar_KW', 'ar_MA', 'ar_SA', 'az_AZ', 'be_BY', 'bg_BG', 'bn_BD', - 'bs_BA', 'ca_ES', 'cs_CZ', 'cy_GB', 'da_DK', 'de_AT', 'de_CH', 'de_DE', 'el_GR', 'en_AU', + 'af_ZA', 'ar_DZ', 'ar_EG', 'ar_KW', 'ar_MA', 'ar_SA', 'az_Latn_AZ', 'be_BY', 'bg_BG', 'bn_BD', + 'bs_Latn_BA', 'ca_ES', 'cs_CZ', 'cy_GB', 'da_DK', 'de_AT', 'de_CH', 'de_DE', 'el_GR', 'en_AU', 'en_CA', 'en_GB', 'en_NZ', 'en_US', 'es_AR', 'es_CO', 'es_PA', 'gl_ES', 'es_CR', 'es_ES', - 'es_MX', 'es_EU', 'es_PE', 'et_EE', 'fa_IR', 'fi_FI', 'fil_PH', 'fr_CA', 'fr_FR', 'gu_IN', + 'es_MX', 'eu_ES', 'es_PE', 'et_EE', 'fa_IR', 'fi_FI', 'fil_PH', 'fr_CA', 'fr_FR', 'gu_IN', 'he_IL', 'hi_IN', 'hr_HR', 'hu_HU', 'id_ID', 'is_IS', 'it_CH', 'it_IT', 'ja_JP', 'ka_GE', - 'km_KH', 'ko_KR', 'lo_LA', 'lt_LT', 'lv_LV', 'mk_MK', 'mn_MN', 'ms_MY', 'nl_NL', 'nb_NO', - 'nn_NO', 'pl_PL', 'pt_BR', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sq_AL', 'sr_RS', - 'sv_SE', 'sw_KE', 'th_TH', 'tr_TR', 'uk_UA', 'vi_VN', 'zh_CN', 'zh_HK', 'zh_TW', 'es_CL', + 'km_KH', 'ko_KR', 'lo_LA', 'lt_LT', 'lv_LV', 'mk_MK', 'mn_Cyrl_MN', 'ms_Latn_MY', 'nl_NL', 'nb_NO', + 'nn_NO', 'pl_PL', 'pt_BR', 'pt_PT', 'ro_RO', 'ru_RU', 'sk_SK', 'sl_SI', 'sq_AL', 'sr_Cyrl_RS', + 'sv_SE', 'sw_KE', 'th_TH', 'tr_TR', 'uk_UA', 'vi_VN', 'zh_Hans_CN', 'zh_Hant_HK', 'zh_Hant_TW', 'es_CL', 'lo_LA', 'es_VE', 'en_IE', ]; diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php index 4eb11f3b81578c9b74cca667f3b386f709d694db..01552d3a972294bd649141074cc91f985829743b 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/CurrencyTest.php @@ -185,7 +185,7 @@ class CurrencyTest extends \PHPUnit_Framework_TestCase ->method('dispatch'); $this->mockLocaleResolver - ->expects($this->exactly(2)) + ->expects($this->exactly(5)) ->method('getLocale'); $retrievedCurrencyObject = $this->testCurrencyObject diff --git a/lib/internal/Magento/Framework/Locale/Test/Unit/ListsTest.php b/lib/internal/Magento/Framework/Locale/Test/Unit/ListsTest.php index 35fb6ef8a58e6e55add147f63dafb20d68e75726..5d36dd09ef17fd392ed31d1b6e34f044cf41bd85 100644 --- a/lib/internal/Magento/Framework/Locale/Test/Unit/ListsTest.php +++ b/lib/internal/Magento/Framework/Locale/Test/Unit/ListsTest.php @@ -13,11 +13,6 @@ class ListsTest extends \PHPUnit_Framework_TestCase */ protected $listsModel; - /** - * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\ScopeResolverInterface - */ - protected $mockScopeResolver; - /** * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ConfigInterface */ @@ -30,164 +25,77 @@ class ListsTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->mockScopeResolver = $this->getMockBuilder('\Magento\Framework\App\ScopeResolverInterface') - ->disableOriginalConstructor() - ->getMock(); $this->mockConfig = $this->getMockBuilder('\Magento\Framework\Locale\ConfigInterface') ->disableOriginalConstructor() ->getMock(); $this->mockLocaleResolver = $this->getMockBuilder('\Magento\Framework\Locale\ResolverInterface') ->disableOriginalConstructor() ->getMock(); - $locale = "some_locale"; - $this->mockLocaleResolver->expects($this->atLeastOnce()) - ->method('setLocale') - ->with($locale); + $this->mockLocaleResolver->expects($this->once()) + ->method('getLocale') + ->will($this->returnValue('en_US')); $this->listsModel = new \Magento\Framework\Locale\Lists( - $this->mockScopeResolver, $this->mockConfig, - $this->mockLocaleResolver, - $locale + $this->mockLocaleResolver ); } - public function testGetCountryTranslationList() - { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->once()) - ->method('getLocale') - ->will($this->returnValue($locale)); - - // clearly english results - $expectedResults = [ - 'AD' => 'Andorra', - 'ZZ' => 'Unknown Region', - 'VC' => 'St. Vincent & Grenadines', - 'PM' => 'Saint Pierre and Miquelon', - ]; - - $countryTranslationList = $this->listsModel->getCountryTranslationList(); - foreach ($expectedResults as $key => $value) { - $this->assertArrayHasKey($key, $countryTranslationList); - $this->assertEquals($value, $countryTranslationList[$key]); - } - } - public function testGetCountryTranslation() { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->once()) - ->method('getLocale') - ->will($this->returnValue($locale)); - - $this->assertFalse($this->listsModel->getCountryTranslation(null)); - } - - public function testGetTranslationList() - { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->exactly(2)) - ->method('getLocale') - ->will($this->returnValue($locale)); - - $path = 'territory'; - $value = 2; - - // clearly english results - $expectedResults = [ - 'AD' => 'Andorra', - 'ZZ' => 'Unknown Region', - 'VC' => 'St. Vincent & Grenadines', - 'PM' => 'Saint Pierre and Miquelon', - ]; - - $countryTranslationList = $this->listsModel->getTranslationList($path, $value); - foreach ($expectedResults as $key => $value) { - $this->assertArrayHasKey($key, $countryTranslationList); - $this->assertEquals($value, $countryTranslationList[$key]); - } + $this->assertNull($this->listsModel->getCountryTranslation(null)); } public function testGetOptionAllCurrencies() { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->exactly(2)) - ->method('getLocale') - ->will($this->returnValue($locale)); - - // clearly English results - $expectedResults = [ - ['value' => 'BAM', 'label' => 'Bosnia-Herzegovina Convertible Mark'], - ['value' => 'TTD', 'label' => 'Trinidad and Tobago Dollar'], - ['value' => 'USN', 'label' => 'US Dollar (Next day)'], - ['value' => 'USS', 'label' => 'US Dollar (Same day)'], - ]; + $expectedResults = ['USD', 'EUR', 'GBP', 'UAH']; $currencyList = $this->listsModel->getOptionAllCurrencies(); foreach ($expectedResults as $value) { - $this->assertContains($value, $currencyList); + $found = false; + foreach ($currencyList as $item) { + $found = $found || ($value == $item['value']); + } + $this->assertTrue($found); } } public function testGetOptionCurrencies() { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->exactly(2)) - ->method('getLocale') - ->will($this->returnValue($locale)); - - $allowedCurrencies = ['USD', 'GBP', 'EUR']; + $allowedCurrencies = ['USD', 'EUR', 'GBP', 'UAH']; $this->mockConfig->expects($this->once()) ->method('getAllowedCurrencies') ->will($this->returnValue($allowedCurrencies)); - $expectedArray = [ - ['value' => 'GBP', 'label' => 'British Pound Sterling'], - ['value' => 'EUR', 'label' => 'Euro'], - ['value' => 'USD', 'label' => 'US Dollar'], - ]; + $expectedResults = ['USD', 'EUR', 'GBP', 'UAH']; - $this->assertSame($expectedArray, $this->listsModel->getOptionCurrencies()); + $currencyList = $this->listsModel->getOptionCurrencies(); + foreach ($expectedResults as $value) { + $found = false; + foreach ($currencyList as $item) { + $found = $found || ($value == $item['value']); + } + $this->assertTrue($found); + } } public function testGetOptionCountries() { - $locale = new \Magento\Framework\Locale('en'); + $expectedResults = ['US', 'GB', 'DE', 'UA']; - $this->mockLocaleResolver->expects($this->once()) - ->method('getLocale') - ->will($this->returnValue($locale)); - - // clearly English results - $expectedResults = [ - ['value' => 'AG', 'label' => 'Antigua and Barbuda'], - ['value' => 'BA', 'label' => 'Bosnia and Herzegovina'], - ['value' => 'CC', 'label' => 'Cocos (Keeling) Islands'], - ['value' => 'GS', 'label' => 'South Georgia & South Sandwich Islands'], - ['value' => 'PM', 'label' => 'Saint Pierre and Miquelon'], - ]; - - $optionCountries = $this->listsModel->getOptionCountries(); + $list = $this->listsModel->getOptionCountries(); foreach ($expectedResults as $value) { - $this->assertContains($value, $optionCountries); + $found = false; + foreach ($list as $item) { + $found = $found || ($value == $item['value']); + } + $this->assertTrue($found); } } public function testGetOptionsWeekdays() { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->exactly(2)) - ->method('getLocale') - ->will($this->returnValue($locale)); - $expectedArray = [ ['label' => 'Sunday', 'value' => 'Sun'], ['label' => 'Monday', 'value' => 'Mon'], @@ -203,26 +111,15 @@ class ListsTest extends \PHPUnit_Framework_TestCase public function testGetOptionTimezones() { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->exactly(2)) - ->method('getLocale') - ->will($this->returnValue($locale)); - - $expectedResults = [ - ['value' => 'Australia/Darwin', 'label' => 'AUS Central Standard Time (Australia/Darwin)'], - ['value' => 'Asia/Jerusalem', 'label' => 'Israel Standard Time (Asia/Jerusalem)'], - ['value' => 'Asia/Yakutsk', 'label' => 'Yakutsk Standard Time (Asia/Yakutsk)'], - ]; + $expectedResults = ['Australia/Darwin', 'America/Los_Angeles', 'Asia/Jerusalem']; - $timeZones = $this->listsModel->getOptionTimezones(); + $list = $this->listsModel->getOptionTimezones(); foreach ($expectedResults as $value) { - $this->assertContains($value, $timeZones); - } - - $timeZoneList = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC); - foreach ($timeZones as $timeZone) { - $this->assertContains($timeZone['value'], $timeZoneList); + $found = false; + foreach ($list as $item) { + $found = $found || ($value == $item['value']); + } + $this->assertTrue($found); } } @@ -230,44 +127,42 @@ class ListsTest extends \PHPUnit_Framework_TestCase { $this->setupForOptionLocales(); - $this->assertEquals( - [ - ['value' => 'az_AZ', 'label' => 'Azerbaijani (Azerbaijan)'], - ['value' => 'en_US', 'label' => 'English (United States)'], - ], - $this->listsModel->getOptionLocales() - ); + $expectedResults = ['en_US', 'uk_UA', 'de_DE']; + + $list = $this->listsModel->getOptionLocales(); + foreach ($expectedResults as $value) { + $found = false; + foreach ($list as $item) { + $found = $found || ($value == $item['value']); + } + $this->assertTrue($found); + } } public function testGetTranslatedOptionLocales() { $this->setupForOptionLocales(); - $this->assertEquals( - [ - ['value' => 'az_AZ', 'label' => 'Azərbaycan (Azərbaycan) / Azerbaijani (Azerbaijan)'], - ['value' => 'en_US', 'label' => 'English (United States) / English (United States)'], - ], - $this->listsModel->getTranslatedOptionLocales() - ); + $expectedResults = ['en_US', 'uk_UA', 'de_DE']; + + $list = $this->listsModel->getOptionLocales(); + foreach ($expectedResults as $value) { + $found = false; + foreach ($list as $item) { + $found = $found || ($value == $item['value']); + } + $this->assertTrue($found); + } } /** - * @return \Magento\Framework\LocaleInterface + * Setup for option locales */ protected function setupForOptionLocales() { - $locale = new \Magento\Framework\Locale('en'); - - $this->mockLocaleResolver->expects($this->any()) - ->method('getLocale') - ->will($this->returnValue($locale)); - - $allowedLocales = ['en_US', 'az_AZ']; + $allowedLocales = ['en_US', 'uk_UA', 'de_DE']; $this->mockConfig->expects($this->once()) ->method('getAllowedLocales') ->will($this->returnValue($allowedLocales)); - - return $locale; } } diff --git a/lib/internal/Magento/Framework/LocaleFactory.php b/lib/internal/Magento/Framework/LocaleFactory.php deleted file mode 100644 index 6e89eaaacfd24bad6c896a4ec975fb7e0c326c59..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/LocaleFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework; - -class LocaleFactory -{ - /** - * @var \Magento\Framework\ObjectManagerInterface - */ - protected $_objectManager = null; - - /** - * @var string - */ - protected $_instanceName = null; - - /** - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param string $instanceName - */ - public function __construct( - \Magento\Framework\ObjectManagerInterface $objectManager, - $instanceName = 'Magento\Framework\LocaleInterface' - ) { - $this->_objectManager = $objectManager; - $this->_instanceName = $instanceName; - } - - /** - * Create class instance with specified parameters - * - * @param array $data - * @return \Magento\Framework\LocaleInterface - */ - public function create(array $data = []) - { - return $this->_objectManager->create($this->_instanceName, $data); - } -} diff --git a/lib/internal/Magento/Framework/LocaleInterface.php b/lib/internal/Magento/Framework/LocaleInterface.php deleted file mode 100644 index 83aeccfb6d7e0425ad48eab29fd2ab87c6866c3b..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/LocaleInterface.php +++ /dev/null @@ -1,242 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework; - -interface LocaleInterface -{ - /** - * Serialization Interface - * - * @return string - */ - public function serialize(); - - /** - * Returns a string representation of the object - * - * @return string - */ - public function toString(); - - /** - * Returns a string representation of the object - * Alias for toString - * - * @return string - */ - public function __toString(); - - /** - * Return the default locale - * - * @return array Returns an array of all locale string - */ - public static function getDefault(); - - /** - * Sets a new default locale which will be used when no locale can be detected - * If provided you can set a quality between 0 and 1 (or 2 and 100) - * which represents the percent of quality the browser - * requested within HTTP - * - * @param string|\Magento\Framework\LocaleInterface $locale Locale to set - * @param float|int $quality The quality to set from 0 to 1 - * @return void - */ - public static function setDefault($locale, $quality = 1); - - /** - * Expects the Systems standard locale - * - * For Windows: - * f.e.: LC_COLLATE=C;LC_CTYPE=German_Austria.1252;LC_MONETARY=C - * would be recognised as de_AT - * - * @return array - */ - public static function getEnvironment(); - - /** - * Return an array of all accepted languages of the client - * Expects RFC compilant Header !! - * - * The notation can be : - * de,en-UK-US;q=0.5,fr-FR;q=0.2 - * - * @return array - list of accepted languages including quality - */ - public static function getBrowser(); - - /** - * Sets a new locale - * - * @param string|\Magento\Framework\LocaleInterface $locale (Optional) New locale to set - * @return void - */ - public function setLocale($locale = null); - - /** - * Returns the language part of the locale - * - * @return string - */ - public function getLanguage(); - - /** - * Returns the region part of the locale if available - * - * @return string|false - Regionstring - */ - public function getRegion(); - - /** - * Return the accepted charset of the client - * - * @return string - */ - public static function getHttpCharset(); - - /** - * Returns true if both locales are equal - * - * @param \Zend_Locale $object Locale to check for equality - * @return boolean - */ - public function equals(\Zend_Locale $object); - - /** - * Returns localized informations as array, supported are several - * types of informations. - * For detailed information about the types look into the documentation - * - * @param string $path (Optional) Type of information to return - * @param string|\Magento\Framework\LocaleInterface $locale (Optional) Locale - * |Language for which this informations should be returned - * @param string $value (Optional) Value for detail list - * @return array Array with the wished information in the given language - */ - public static function getTranslationList($path = null, $locale = null, $value = null); - - /** - * Returns a localized information string, supported are several types of informations. - * For detailed information about the types look into the documentation - * - * @param string $value Name to get detailed information about - * @param string $path (Optional) Type of information to return - * @param string|\Magento\Framework\LocaleInterface $locale (Optional) Locale - * |Language for which this informations should be returned - * @return string|false The wished information in the given language - */ - public static function getTranslation($value = null, $path = null, $locale = null); - - /** - * Returns an array with translated yes strings - * - * @param string|\Magento\Framework\LocaleInterface $locale (Optional) - * Locale for language translation (defaults to $this locale) - * @return array - */ - public static function getQuestion($locale = null); - - /** - * Checks if a locale identifier is a real locale or not - * Examples: - * "en_XX" refers to "en", which returns true - * "XX_yy" refers to "root", which returns false - * - * @param string|\Magento\Framework\LocaleInterface $locale Locale to check for - * @param boolean $strict (Optional) If true, no rerouting will be done when checking - * @param boolean $compatible (DEPRECATED) Only for internal usage, brakes compatibility mode - * @return boolean If the locale is known dependend on the settings - */ - public static function isLocale($locale, $strict = false, $compatible = true); - - /** - * Finds the proper locale based on the input - * Checks if it exists, degrades it when necessary - * Detects registry locale and when all fails tries to detect a automatic locale - * Returns the found locale as string - * - * @param string $locale - * @throws \Zend_Locale_Exception When the given locale is no locale or the autodetection fails - * @return string - */ - public static function findLocale($locale = null); - - /** - * Returns the expected locale for a given territory - * - * @param string $territory Territory for which the locale is being searched - * @return string|null Locale string or null when no locale has been found - */ - public static function getLocaleToTerritory($territory); - - /** - * Returns a list of all known locales where the locale is the key - * Only real locales are returned, the internal locales 'root', 'auto', 'browser' - * and 'environment' are suppressed - * - * @return array List of all Locales - */ - public static function getLocaleList(); - - /** - * Returns the set cache - * - * @return \Zend_Cache_Core The set cache - */ - public static function getCache(); - - /** - * Sets a cache - * - * @param \Zend_Cache_Core $cache Cache to set - * @return void - */ - public static function setCache(\Zend_Cache_Core $cache); - - /** - * Returns true when a cache is set - * - * @return boolean - */ - public static function hasCache(); - - /** - * Removes any set cache - * - * @return void - */ - public static function removeCache(); - - /** - * Clears all set cache data - * - * @param string $tag Tag to clear when the default tag name is not used - * @return void - */ - public static function clearCache($tag = null); - - /** - * Disables the set cache - * - * @param boolean $flag True disables any set cache, default is false - * @return void - */ - public static function disableCache($flag); - - /** - * Search the locale automatically and return all used locales - * ordered by quality - * - * Standard Searchorder is Browser, Environment, Default - * - * @param null $order - * @internal param string $searchorder (Optional) Searchorder - * @return array Returns an array of all detected locales - */ - public static function getOrder($order = null); -} diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php index b90ebd276ebb2e8867456e11726383fd06a39378..e777d9c51fcbf28f00be4981f63dcc9a14199633 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/Setup/MigrationTest.php @@ -85,7 +85,7 @@ class MigrationTest extends \PHPUnit_Framework_TestCase 'base_dir' => 'not_used', 'path_to_map_file' => 'not_used', 'connection' => $adapterMock, - 'core_helper' => $this->getMock('Magento\Core\Helper\Data', [], [], '', false, false), + 'core_helper' => $this->getMock('Magento\Framework\Json\Helper\Data', [], [], '', false, false), 'aliases_map' => $aliasesMap ]; } diff --git a/lib/internal/Magento/Framework/Mview/View/StateInterface.php b/lib/internal/Magento/Framework/Mview/View/StateInterface.php index 637607aa0cd77bdf94cb388bdd343e760b665955..a2f87c539395afd8a003139395bfba3528d1ba43 100644 --- a/lib/internal/Magento/Framework/Mview/View/StateInterface.php +++ b/lib/internal/Magento/Framework/Mview/View/StateInterface.php @@ -113,7 +113,7 @@ interface StateInterface /** * Set state updated time * - * @param string|int|\Magento\Framework\Stdlib\DateTime\DateInterface $updated + * @param string|int|\DateTime $updated * @return \Magento\Framework\Mview\View\StateInterface */ public function setUpdated($updated); diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime.php index fdaf1d302f4f21265add52f24bf33b08060abb92..fcb268be94313cd381145ff4821f2831a6fd70b4 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime.php @@ -12,7 +12,7 @@ namespace Magento\Framework\Stdlib; class DateTime { /**#@+ - * Date format, used as default. Compatible with \Zend_Date + * Date format, used as default. Compatible with \DateTime */ const DATETIME_INTERNAL_FORMAT = 'yyyy-MM-dd HH:mm:ss'; @@ -34,69 +34,28 @@ class DateTime */ const YEAR_MAX_VALUE = 10000; - /** - * Convert date to UNIX timestamp - * Returns current UNIX timestamp if date is true - * - * @param \Magento\Framework\Stdlib\DateTime\DateInterface|bool $date - * @return int - */ - public function toTimestamp($date) - { - if ($date instanceof \Magento\Framework\Stdlib\DateTime\DateInterface) { - return $date->getTimestamp(); - } - - if ($date === true) { - return time(); - } - - return strtotime($date); - } - - /** - * Retrieve current date in internal format - * - * @param boolean $withoutTime day only flag - * @return string - */ - public function now($withoutTime = false) - { - $format = $withoutTime ? self::DATE_PHP_FORMAT : self::DATETIME_PHP_FORMAT; - return date($format); - } - /** * Format date to internal format * - * @param string|\Zend_Date|bool|null $date + * @param string|\DateTime|bool|null $date * @param boolean $includeTime * @return string|null */ public function formatDate($date, $includeTime = true) { - if ($date === true) { - return $this->now(!$includeTime); - } - - if ($date instanceof \Magento\Framework\Stdlib\DateTime\DateInterface) { - if ($includeTime) { - return $date->toString(self::DATETIME_INTERNAL_FORMAT); - } else { - return $date->toString(self::DATE_INTERNAL_FORMAT); - } - } - - if (empty($date)) { + if ($date instanceof \DateTime) { + $format = $includeTime ? self::DATETIME_PHP_FORMAT : self::DATE_PHP_FORMAT; + return $date->format($format); + } elseif (empty($date)) { return null; - } - - if (!is_numeric($date)) { - $date = $this->toTimestamp($date); + } elseif ($date === true) { + $date = (new \DateTime())->getTimestamp(); + } elseif (!is_numeric($date)) { + $date = (new \DateTime($date))->getTimestamp(); } $format = $includeTime ? self::DATETIME_PHP_FORMAT : self::DATE_PHP_FORMAT; - return date($format, $date); + return (new \DateTime())->setTimestamp($date)->format($format); } /** diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Date.php deleted file mode 100644 index 30cd835f4a87678676b72035b642c52782af93dd..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Date.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Stdlib\DateTime; - -class Date extends \Zend_Date implements \Magento\Framework\Stdlib\DateTime\DateInterface -{ - /** - * Generates the standard date object, could be a unix timestamp, localized date, - * string, integer, array and so on. Also parts of dates or time are supported - * Always set the default timezone: http://php.net/date_default_timezone_set - * For example, in your bootstrap: date_default_timezone_set('America/Los_Angeles'); - * For detailed instructions please look in the docu. - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface|array $date OPTIONAL Date value or value - * of date part to set, depending on $part. If null the actual time is set - * @param string $part OPTIONAL Defines the input format of $date - * @param string|\Magento\Framework\Stdlib\DateTime\DateInterface $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - * @throws Zend_Date_Exception - */ - public function __construct($date = null, $part = null, $locale = null) - { - parent::__construct($date, $part, $locale); - } -} diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/DateFactory.php b/lib/internal/Magento/Framework/Stdlib/DateTime/DateFactory.php deleted file mode 100644 index 0513b72f55687cbf7cc760fb19d93f19ceae9e28..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/DateFactory.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Stdlib\DateTime; - -class DateFactory -{ - /** - * @var \Magento\Framework\ObjectManagerInterface - */ - protected $_objectManager = null; - - /** - * @var string - */ - protected $_instanceName = null; - - /** - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param string $instanceName - */ - public function __construct( - \Magento\Framework\ObjectManagerInterface $objectManager, - $instanceName = 'Magento\Framework\Stdlib\DateTime\DateInterface' - ) { - $this->_objectManager = $objectManager; - $this->_instanceName = $instanceName; - } - - /** - * Create class instance with specified parameters - * - * @param array $data - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function create(array $data = []) - { - return $this->_objectManager->create($this->_instanceName, $data); - } -} diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/DateInterface.php b/lib/internal/Magento/Framework/Stdlib/DateTime/DateInterface.php deleted file mode 100644 index 369139a054ad4457108ae647b9d15933e0d772b8..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/DateInterface.php +++ /dev/null @@ -1,1284 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -// @codingStandardsIgnoreFile - -namespace Magento\Framework\Stdlib\DateTime; - -interface DateInterface -{ - /** - * Sets class wide options, if no option was given, the actual set options will be returned - * - * @param array $options \Options to set - * @throws \Zend_Date_Exception - * @return array of options if no option was given - */ - public static function setOptions(array $options = []); - - /** - * Returns this object's internal UNIX timestamp (equivalent to \Zend_Date::TIMESTAMP). - * If the timestamp is too large for integers, then the return value will be a string. - * This function does not return the timestamp as an object. - * Use clone() or copyPart() instead. - * - * @return integer|string UNIX timestamp - */ - public function getTimestamp(); - - /** - * Sets a new timestamp - * - * @param integer|string|array|\Magento\Framework\Stdlib\DateTime\DateInterface $timestamp Timestamp to set - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setTimestamp($timestamp); - - /** - * Adds a timestamp - * - * @param integer|string|array|\Magento\Framework\Stdlib\DateTime\DateInterface $timestamp Timestamp to add - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addTimestamp($timestamp); - - /** - * Subtracts a timestamp - * - * @param integer|string|array|\Magento\Framework\Stdlib\DateTime\DateInterface $timestamp Timestamp to sub - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subTimestamp($timestamp); - - /** - * Compares two timestamps, returning the difference as integer - * - * @param integer|string|array|\Magento\Framework\Stdlib\DateTime\DateInterface $timestamp Timestamp to compare - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareTimestamp($timestamp); - - /** - * Returns a string representation of the object - * Supported format tokens are: - * G - era, y - year, Y - ISO year, M - month, w - week of year, D - day of year, d - day of month - * E - day of week, e - number of weekday (1-7), h - hour 1-12, H - hour 0-23, m - minute, s - second - * A - milliseconds of day, z - timezone, Z - timezone offset, S - fractional second, a - period of day - * - * Additionally format tokens but non ISO conform are: - * SS - day suffix, eee - php number of weekday(0-6), ddd - number of days per month - * l - Leap year, B - swatch internet time, I - daylight saving time, X - timezone offset in seconds - * r - RFC2822 format, U - unix timestamp - * - * Not supported ISO tokens are - * u - extended year, Q - quarter, q - quarter, L - stand alone month, W - week of month - * F - day of week of month, g - modified julian, c - stand alone weekday, k - hour 0-11, K - hour 1-24 - * v - wall zone - * - * @param string $format OPTIONAL Rule for formatting output. If null the default date format is used - * @param string $type OPTIONAL Type for the format string which overrides the standard setting - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return string - */ - public function toString($format = null, $type = null, $locale = null); - - /** - * Returns a string representation of the date which is equal with the timestamp - * - * @return string - */ - public function __toString(); - - /** - * Returns a integer representation of the object - * But returns false when the given part is no value f.e. Month-Name - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $part OPTIONAL Defines the date or datepart to return as integer - * @return integer|false - */ - public function toValue($part = null); - - /** - * Returns an array representation of the object - * - * @return array - */ - public function toArray(); - - /** - * Returns a representation of a date or datepart - * This could be for example a localized monthname, the time without date, - * the era or only the fractional seconds. There are about 50 different supported date parts. - * For a complete list of supported datepart values look into the docu - * - * @param string $part OPTIONAL Part of the date to return, if null the timestamp is returned - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return string date or datepart - */ - public function get($part = null, $locale = null); - - /** - * Counts the exact year number - * < 70 - 2000 added, >70 < 100 - 1900, others just returned - * - * @param integer $value year number - * @return integer Number of year - */ - public static function getFullYear($value); - - /** - * Sets the given date as new date or a given datepart as new datepart returning the new datepart - * This could be for example a localized dayname, the date without time, - * the month or only the seconds. There are about 50 different supported date parts. - * For a complete list of supported datepart values look into the docu - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to set - * @param string $part OPTIONAL Part of the date to set, if null the timestamp is set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return $this Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function set($date, $part = null, $locale = null); - - /** - * Adds a date or datepart to the existing date, by extracting $part from $date, - * and modifying this object by adding that part. The $part is then extracted from - * this object and returned as an integer or numeric string (for large values, or $part's - * corresponding to pre-defined formatted date strings). - * This could be for example a ISO 8601 date, the hour the monthname or only the minute. - * There are about 50 different supported date parts. - * For a complete list of supported datepart values look into the docu. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to add - * @param string $part OPTIONAL Part of the date to add, if null the timestamp is added - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return $this Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function add($date, $part = \Zend_Date::TIMESTAMP, $locale = null); - - /** - * Subtracts a date from another date. - * This could be for example a RFC2822 date, the time, - * the year or only the timestamp. There are about 50 different supported date parts. - * For a complete list of supported datepart values look into the docu - * Be aware: Adding -2 Months is not equal to Subtracting 2 Months !!! - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to subtract - * @param string $part OPTIONAL Part of the date to sub, if null the timestamp is subtracted - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return $this Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function sub($date, $part = \Zend_Date::TIMESTAMP, $locale = null); - - /** - * Compares a date or datepart with the existing one. - * Returns -1 if earlier, 0 if equal and 1 if later. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to compare with the date object - * @param string $part OPTIONAL Part of the date to compare, if null the timestamp is subtracted - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compare($date, $part = \Zend_Date::TIMESTAMP, $locale = null); - - /** - * Returns a new instance of \Magento\Framework\Stdlib\DateTime\DateInterface with the selected part copied. - * To make an exact copy, use PHP's clone keyword. - * For a complete list of supported date part values look into the docu. - * If a date part is copied, all other date parts are set to standard values. - * For example: If only YEAR is copied, the returned date object is equal to - * 01-01-YEAR 00:00:00 (01-01-1970 00:00:00 is equal to timestamp 0) - * If only HOUR is copied, the returned date object is equal to - * 01-01-1970 HOUR:00:00 (so $this contains a timestamp equal to a timestamp of 0 plus HOUR). - * - * @param string $part Part of the date to compare, if null the timestamp is subtracted - * @param string|\Zend_Locale $locale OPTIONAL New object's locale. No adjustments to timezone are made. - * @return \Magento\Framework\Stdlib\DateTime\DateInterface New clone with requested part - */ - public function copyPart($part, $locale = null); - - /** - * Internal function, returns the offset of a given timezone - * - * @param string $zone - * @return integer - */ - public function getTimezoneFromString($zone); - - /** - * Returns true when both date objects or date parts are equal. - * For example: - * 15.May.2000 <-> 15.June.2000 Equals only for Day or Year... all other will return false - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to equal with - * @param string $part OPTIONAL Part of the date to compare, if null the timestamp is used - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return boolean - * @throws \Zend_Date_Exception - */ - public function equals($date, $part = \Zend_Date::TIMESTAMP, $locale = null); - - /** - * Returns if the given date or datepart is earlier - * For example: - * 15.May.2000 <-> 13.June.1999 will return true for day, year and date, but not for month - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to compare with - * @param string $part OPTIONAL Part of the date to compare, if null the timestamp is used - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return boolean - * @throws \Zend_Date_Exception - */ - public function isEarlier($date, $part = null, $locale = null); - - /** - * Returns if the given date or datepart is later - * For example: - * 15.May.2000 <-> 13.June.1999 will return true for month but false for day, year and date - * Returns if the given date is later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date or datepart to compare with - * @param string $part OPTIONAL Part of the date to compare, if null the timestamp is used - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return boolean - * @throws \Zend_Date_Exception - */ - public function isLater($date, $part = null, $locale = null); - - /** - * Returns only the time of the date as new \Magento\Framework\Stdlib\DateTime\Date object - * For example: - * 15.May.2000 10:11:23 will return a dateobject equal to 01.Jan.1970 10:11:23 - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getTime($locale = null); - - /** - * Sets a new time for the date object. Format defines how to parse the time string. - * Also a complete date can be given, but only the time is used for setting. - * For example: dd.MMMM.yyTHH:mm' and 'ss sec'-> 10.May.07T25:11 and 44 sec => 1h11min44sec + 1 day - * Returned is the new date object and the existing date is left as it was before - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $time Time to set - * @param string $format OPTIONAL Timeformat for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setTime($time, $format = null, $locale = null); - - /** - * Adds a time to the existing date. Format defines how to parse the time string. - * If only parts are given the other parts are set to 0. - * If no format is given, the standardformat of this locale is used. - * For example: HH:mm:ss -> 10 -> +10 hours - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $time Time to add - * @param string $format OPTIONAL Timeformat for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addTime($time, $format = null, $locale = null); - - /** - * Subtracts a time from the existing date. Format defines how to parse the time string. - * If only parts are given the other parts are set to 0. - * If no format is given, the standardformat of this locale is used. - * For example: HH:mm:ss -> 10 -> -10 hours - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $time Time to sub - * @param string $format OPTIONAL Timeformat for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid inteface - * @throws \Zend_Date_Exception - */ - public function subTime($time, $format = null, $locale = null); - - /** - * Compares the time from the existing date. Format defines how to parse the time string. - * If only parts are given the other parts are set to default. - * If no format us given, the standardformat of this locale is used. - * For example: HH:mm:ss -> 10 -> 10 hours - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $time Time to compare - * @param string $format OPTIONAL Timeformat for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareTime($time, $format = null, $locale = null); - - /** - * Returns a clone of $this, with the time part set to 00:00:00. - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getDate($locale = null); - - /** - * Sets a new date for the date object. Format defines how to parse the date string. - * Also a complete date with time can be given, but only the date is used for setting. - * For example: MMMM.yy HH:mm-> May.07 22:11 => 01.May.07 00:00 - * Returned is the new date object and the existing time is left as it was before - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date to set - * @param string $format OPTIONAL Date format for parsing - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setDate($date, $format = null, $locale = null); - - /** - * Adds a date to the existing date object. Format defines how to parse the date string. - * If only parts are given the other parts are set to 0. - * If no format is given, the standardformat of this locale is used. - * For example: MM.dd.YYYY -> 10 -> +10 months - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date to add - * @param string $format OPTIONAL Date format for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addDate($date, $format = null, $locale = null); - - /** - * Subtracts a date from the existing date object. Format defines how to parse the date string. - * If only parts are given the other parts are set to 0. - * If no format is given, the standardformat of this locale is used. - * For example: MM.dd.YYYY -> 10 -> -10 months - * Be aware: Subtracting 2 months is not equal to Adding -2 months !!! - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date to sub - * @param string $format OPTIONAL Date format for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subDate($date, $format = null, $locale = null); - - /** - * Compares the date from the existing date object, ignoring the time. - * Format defines how to parse the date string. - * If only parts are given the other parts are set to 0. - * If no format is given, the standardformat of this locale is used. - * For example: 10.01.2000 => 10.02.1999 -> false - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date to compare - * @param string $format OPTIONAL Date format for parsing input - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareDate($date, $format = null, $locale = null); - - /** - * Returns the full ISO 8601 date from the date object. - * Always the complete ISO 8601 specifiction is used. If an other ISO date is needed - * (ISO 8601 defines several formats) use toString() instead. - * This function does not return the ISO date as object. Use copy() instead. - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return string - */ - public function getIso($locale = null); - - /** - * Sets a new date for the date object. Not given parts are set to default. - * Only supported ISO 8601 formats are accepted. - * For example: 050901 -> 01.Sept.2005 00:00:00, 20050201T10:00:30 -> 01.Feb.2005 10h00m30s - * Returned is the new date object - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date ISO Date to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setIso($date, $locale = null); - - /** - * Adds a ISO date to the date object. Not given parts are set to default. - * Only supported ISO 8601 formats are accepted. - * For example: 050901 -> + 01.Sept.2005 00:00:00, 10:00:00 -> +10h - * Returned is the new date object - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date ISO Date to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addIso($date, $locale = null); - - /** - * Subtracts a ISO date from the date object. Not given parts are set to default. - * Only supported ISO 8601 formats are accepted. - * For example: 050901 -> - 01.Sept.2005 00:00:00, 10:00:00 -> -10h - * Returned is the new date object - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date ISO Date to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subIso($date, $locale = null); - - /** - * Compares a ISO date with the date object. Not given parts are set to default. - * Only supported ISO 8601 formats are accepted. - * For example: 050901 -> - 01.Sept.2005 00:00:00, 10:00:00 -> -10h - * Returns if equal, earlier or later - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date ISO Date to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareIso($date, $locale = null); - - /** - * Returns a RFC 822 compilant datestring from the date object. - * This function does not return the RFC date as object. Use copy() instead. - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return string - */ - public function getArpa($locale = null); - - /** - * Sets a RFC 822 date as new date for the date object. - * Only RFC 822 compilant date strings are accepted. - * For example: Sat, 14 Feb 09 00:31:30 +0100 - * Returned is the new date object - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date RFC 822 to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setArpa($date, $locale = null); - - /** - * Adds a RFC 822 date to the date object. - * ARPA messages are used in emails or HTTP Headers. - * Only RFC 822 compilant date strings are accepted. - * For example: Sat, 14 Feb 09 00:31:30 +0100 - * Returned is the new date object - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date RFC 822 Date to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addArpa($date, $locale = null); - - /** - * Subtracts a RFC 822 date from the date object. - * ARPA messages are used in emails or HTTP Headers. - * Only RFC 822 compilant date strings are accepted. - * For example: Sat, 14 Feb 09 00:31:30 +0100 - * Returned is the new date object - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date RFC 822 Date to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subArpa($date, $locale = null); - - /** - * Compares a RFC 822 compilant date with the date object. - * ARPA messages are used in emails or HTTP Headers. - * Only RFC 822 compilant date strings are accepted. - * For example: Sat, 14 Feb 09 00:31:30 +0100 - * Returns if equal, earlier or later - * - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface $date RFC 822 Date to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareArpa($date, $locale = null); - - /** - * Returns the time of sunrise for this date and a given location as new date object - * For a list of cities and correct locations use the class \Zend_Date_Cities - * - * @param $location array - location of sunrise - * ['horizon'] -> civil, nautic, astronomical, effective (default) - * ['longitude'] -> longitude of location - * ['latitude'] -> latitude of location - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - * @throws \Zend_Date_Exception - */ - public function getSunrise($location); - - /** - * Returns the time of sunset for this date and a given location as new date object - * For a list of cities and correct locations use the class \Zend_Date_Cities - * - * @param $location array - location of sunset - * ['horizon'] -> civil, nautic, astronomical, effective (default) - * ['longitude'] -> longitude of location - * ['latitude'] -> latitude of location - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - * @throws \Zend_Date_Exception - */ - public function getSunset($location); - - /** - * Returns an array with the sunset and sunrise dates for all horizon types - * For a list of cities and correct locations use the class \Zend_Date_Cities - * - * @param $location array - location of suninfo - * ['horizon'] -> civil, nautic, astronomical, effective (default) - * ['longitude'] -> longitude of location - * ['latitude'] -> latitude of location - * @return array - [sunset|sunrise][effective|civil|nautic|astronomic] - * @throws \Zend_Date_Exception - */ - public function getSunInfo($location); - - /** - * Check a given year for leap year. - * - * @param integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $year Year to check - * @return boolean - */ - public static function checkLeapYear($year); - - /** - * Returns true, if the year is a leap year. - * - * @return boolean - */ - public function isLeapYear(); - - /** - * Returns if the set date is todays date - * - * @return boolean - */ - public function isToday(); - - /** - * Returns if the set date is yesterdays date - * - * @return boolean - */ - public function isYesterday(); - - /** - * Returns if the set date is tomorrows date - * - * @return boolean - */ - public function isTomorrow(); - - /** - * Returns the actual date as new date object - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public static function now($locale = null); - - /** - * Returns only the year from the date object as new object. - * For example: 10.May.2000 10:30:00 -> 01.Jan.2000 00:00:00 - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getYear($locale = null); - - /** - * Sets a new year - * If the year is between 0 and 69, 2000 will be set (2000-2069) - * If the year if between 70 and 99, 1999 will be set (1970-1999) - * 3 or 4 digit years are set as expected. If you need to set year 0-99 - * use set() instead. - * Returned is the new date object - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Year to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setYear($year, $locale = null); - - /** - * Adds the year to the existing date object - * If the year is between 0 and 69, 2000 will be added (2000-2069) - * If the year if between 70 and 99, 1999 will be added (1970-1999) - * 3 or 4 digit years are added as expected. If you need to add years from 0-99 - * use add() instead. - * Returned is the new date object - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Year to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addYear($year, $locale = null); - - /** - * Subs the year from the existing date object - * If the year is between 0 and 69, 2000 will be subtracted (2000-2069) - * If the year if between 70 and 99, 1999 will be subtracted (1970-1999) - * 3 or 4 digit years are subtracted as expected. If you need to subtract years from 0-99 - * use sub() instead. - * Returned is the new date object - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Year to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subYear($year, $locale = null); - - /** - * Compares the year with the existing date object, ignoring other date parts. - * For example: 10.03.2000 -> 15.02.2000 -> true - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $year Year to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareYear($year, $locale = null); - - /** - * Returns only the month from the date object as new object. - * For example: 10.May.2000 10:30:00 -> 01.May.1970 00:00:00 - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Zend_Date - */ - public function getMonth($locale = null); - - /** - * Sets a new month - * The month can be a number or a string. Setting months lower than 0 and greater then 12 - * will result in adding or subtracting the relevant year. (12 months equal one year) - * If a localized monthname is given it will be parsed with the default locale or the optional - * set locale. - * Returned is the new date object - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Month to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setMonth($month, $locale = null); - - /** - * Adds months to the existing date object. - * The month can be a number or a string. Adding months lower than 0 and greater then 12 - * will result in adding or subtracting the relevant year. (12 months equal one year) - * If a localized monthname is given it will be parsed with the default locale or the optional - * set locale. - * Returned is the new date object - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Month to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addMonth($month, $locale = null); - - /** - * Subtracts months from the existing date object. - * The month can be a number or a string. Subtracting months lower than 0 and greater then 12 - * will result in adding or subtracting the relevant year. (12 months equal one year) - * If a localized monthname is given it will be parsed with the default locale or the optional - * set locale. - * Returned is the new date object - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Month to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subMonth($month, $locale = null); - - /** - * Compares the month with the existing date object, ignoring other date parts. - * For example: 10.03.2000 -> 15.03.1950 -> true - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Month to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareMonth($month, $locale = null); - - /** - * Returns the day as new date object - * Example: 20.May.1986 -> 20.Jan.1970 00:00:00 - * - * @param $locale string|\Zend_Locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getDay($locale = null); - - /** - * Sets a new day - * The day can be a number or a string. Setting days lower then 0 or greater than the number of this months days - * will result in adding or subtracting the relevant month. - * If a localized dayname is given it will be parsed with the default locale or the optional - * set locale. - * Returned is the new date object - * Example: setDay('Montag', 'de_AT'); will set the monday of this week as day. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Day to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setDay($day, $locale = null); - - /** - * Adds days to the existing date object. - * The day can be a number or a string. Adding days lower then 0 or greater than the number of this months days - * will result in adding or subtracting the relevant month. - * If a localized dayname is given it will be parsed with the default locale or the optional - * set locale. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Day to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addDay($day, $locale = null); - - /** - * Subtracts days from the existing date object. - * The day can be a number or a string. Subtracting days lower then 0 or greater than the number of this months days - * will result in adding or subtracting the relevant month. - * If a localized dayname is given it will be parsed with the default locale or the optional - * set locale. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Day to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subDay($day, $locale = null); - - /** - * Compares the day with the existing date object, ignoring other date parts. - * For example: 'Monday', 'en' -> 08.Jan.2007 -> 0 - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $day Day to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareDay($day, $locale = null); - - /** - * Returns the weekday as new date object - * Weekday is always from 1-7 - * Example: 09-Jan-2007 -> 2 = Tuesday -> 02-Jan-1970 (when 02.01.1970 is also Tuesday) - * - * @param $locale string|\Zend_Locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getWeekday($locale = null); - - /** - * Sets a new weekday - * The weekday can be a number or a string. If a localized weekday name is given, - * then it will be parsed as a date in $locale (defaults to the same locale as $this). - * Returned is the new date object. - * Example: setWeekday(3); will set the wednesday of this week as day. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Weekday to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setWeekday($weekday, $locale = null); - - /** - * Adds weekdays to the existing date object. - * The weekday can be a number or a string. - * If a localized dayname is given it will be parsed with the default locale or the optional - * set locale. - * Returned is the new date object - * Example: addWeekday(3); will add the difference of days from the beginning of the month until - * wednesday. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Weekday to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addWeekday($weekday, $locale = null); - - /** - * Subtracts weekdays from the existing date object. - * The weekday can be a number or a string. - * If a localized dayname is given it will be parsed with the default locale or the optional - * set locale. - * Returned is the new date object - * Example: subWeekday(3); will subtract the difference of days from the beginning of the month until - * wednesday. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $month Weekday to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subWeekday($weekday, $locale = null); - - /** - * Compares the weekday with the existing date object, ignoring other date parts. - * For example: 'Monday', 'en' -> 08.Jan.2007 -> 0 - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $weekday Weekday to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareWeekday($weekday, $locale = null); - - /** - * Returns the day of year as new date object - * Example: 02.Feb.1986 10:00:00 -> 02.Feb.1970 00:00:00 - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getDayOfYear($locale = null); - - /** - * Sets a new day of year - * The day of year is always a number. - * Returned is the new date object - * Example: 04.May.2004 -> setDayOfYear(10) -> 10.Jan.2004 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $day Day of Year to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setDayOfYear($day, $locale = null); - - /** - * Adds a day of year to the existing date object. - * The day of year is always a number. - * Returned is the new date object - * Example: addDayOfYear(10); will add 10 days to the existing date object. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $day Day of Year to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addDayOfYear($day, $locale = null); - - /** - * Subtracts a day of year from the existing date object. - * The day of year is always a number. - * Returned is the new date object - * Example: subDayOfYear(10); will subtract 10 days from the existing date object. - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $day Day of Year to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subDayOfYear($day, $locale = null); - - /** - * Compares the day of year with the existing date object. - * For example: compareDayOfYear(33) -> 02.Feb.2007 -> 0 - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $day Day of Year to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareDayOfYear($day, $locale = null); - - /** - * Returns the hour as new date object - * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 10:00:00 - * - * @param $locale string|\Zend_Locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getHour($locale = null); - - /** - * Sets a new hour - * The hour is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> setHour(7); -> 04.May.1993 07:07:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $hour Hour to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setHour($hour, $locale = null); - - /** - * Adds hours to the existing date object. - * The hour is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> addHour(12); -> 05.May.1993 01:07:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $hour Hour to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addHour($hour, $locale = null); - - /** - * Subtracts hours from the existing date object. - * The hour is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> subHour(6); -> 05.May.1993 07:07:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $hour Hour to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subHour($hour, $locale = null); - - /** - * Compares the hour with the existing date object. - * For example: 10:30:25 -> compareHour(10) -> 0 - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $hour Hour to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareHour($hour, $locale = null); - - /** - * Returns the minute as new date object - * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 00:30:00 - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getMinute($locale = null); - - /** - * Sets a new minute - * The minute is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> setMinute(29); -> 04.May.1993 13:29:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $minute Minute to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setMinute($minute, $locale = null); - - /** - * Adds minutes to the existing date object. - * The minute is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> addMinute(65); -> 04.May.1993 13:12:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $minute Minute to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addMinute($minute, $locale = null); - - /** - * Subtracts minutes from the existing date object. - * The minute is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> subMinute(9); -> 04.May.1993 12:58:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $minute Minute to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subMinute($minute, $locale = null); - - /** - * Compares the minute with the existing date object. - * For example: 10:30:25 -> compareMinute(30) -> 0 - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $minute Hour to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareMinute($minute, $locale = null); - - /** - * Returns the second as new date object - * Example: 02.Feb.1986 10:30:25 -> 01.Jan.1970 00:00:25 - * - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getSecond($locale = null); - - /** - * Sets new seconds to the existing date object. - * The second is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> setSecond(100); -> 04.May.1993 13:08:40 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $second Second to set - * @param string|\Zend_Locale $locale (Optional) Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setSecond($second, $locale = null); - - /** - * Adds seconds to the existing date object. - * The second is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> addSecond(65); -> 04.May.1993 13:08:30 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $second Second to add - * @param string|\Zend_Locale $locale (Optional) Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addSecond($second, $locale = null); - - /** - * Subtracts seconds from the existing date object. - * The second is always a number. - * Returned is the new date object - * Example: 04.May.1993 13:07:25 -> subSecond(10); -> 04.May.1993 13:07:15 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $second Second to sub - * @param string|\Zend_Locale $locale (Optional) Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subSecond($second, $locale = null); - - /** - * Compares the second with the existing date object. - * For example: 10:30:25 -> compareSecond(25) -> 0 - * Returns if equal, earlier or later - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $second Second to compare - * @param string|\Zend_Locale $locale (Optional) Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - * @throws \Zend_Date_Exception - */ - public function compareSecond($second, $locale = null); - - /** - * Returns the precision for fractional seconds - * - * @return integer - */ - public function getFractionalPrecision(); - - /** - * Sets a new precision for fractional seconds - * - * @param integer $precision Precision for the fractional datepart 3 = milliseconds - * @throws \Zend_Date_Exception - * @return $this Provides fluid interface - */ - public function setFractionalPrecision($precision); - - /** - * Returns the milliseconds of the date object - * - * @return string - */ - public function getMilliSecond(); - - /** - * Sets new milliseconds for the date object - * Example: setMilliSecond(550, 2) -> equals +5 Sec +50 MilliSec - * - * @param integer|\Magento\Framework\Stdlib\DateTime\DateInterface $milli (Optional) Millisecond to set, when null the actual millisecond is set - * @param integer $precision (Optional) Fraction precision of the given milliseconds - * @return $this Provides fluid interface - */ - public function setMilliSecond($milli = null, $precision = null); - - /** - * Adds milliseconds to the date object - * - * @param integer|\Magento\Framework\Stdlib\DateTime\DateInterface $milli (Optional) Millisecond to add, when null the actual millisecond is added - * @param integer $precision (Optional) Fractional precision for the given milliseconds - * @return $this Provides fluid interface - */ - public function addMilliSecond($milli = null, $precision = null); - - /** - * Subtracts a millisecond - * - * @param integer|\Magento\Framework\Stdlib\DateTime\DateInterface $milli (Optional) Millisecond to sub, when null the actual millisecond is subtracted - * @param integer $precision (Optional) Fractional precision for the given milliseconds - * @return $this Provides fluid interface - */ - public function subMilliSecond($milli = null, $precision = null); - - /** - * Compares only the millisecond part, returning the difference - * - * @param integer|\Magento\Framework\Stdlib\DateTime\DateInterface $milli OPTIONAL Millisecond to compare, when null the actual millisecond is compared - * @param integer $precision OPTIONAL Fractional precision for the given milliseconds - * @throws \Zend_Date_Exception On invalid input - * @return integer 0 = equal, 1 = later, -1 = earlier - */ - public function compareMilliSecond($milli = null, $precision = null); - - /** - * Returns the week as new date object using monday as beginning of the week - * Example: 12.Jan.2007 -> 08.Jan.1970 00:00:00 - * - * @param $locale string|\Zend_Locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function getWeek($locale = null); - - /** - * Sets a new week. The week is always a number. The day of week is not changed. - * Returned is the new date object - * Example: 09.Jan.2007 13:07:25 -> setWeek(1); -> 02.Jan.2007 13:07:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $week Week to set - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function setWeek($week, $locale = null); - - /** - * Adds a week. The week is always a number. The day of week is not changed. - * Returned is the new date object - * Example: 09.Jan.2007 13:07:25 -> addWeek(1); -> 16.Jan.2007 13:07:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $week Week to add - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function addWeek($week, $locale = null); - - /** - * Subtracts a week. The week is always a number. The day of week is not changed. - * Returned is the new date object - * Example: 09.Jan.2007 13:07:25 -> subWeek(1); -> 02.Jan.2007 13:07:25 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $week Week to sub - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return \Magento\Framework\Stdlib\DateTime\DateInterface Provides fluid interface - * @throws \Zend_Date_Exception - */ - public function subWeek($week, $locale = null); - - /** - * Compares only the week part, returning the difference - * Returned is the new date object - * Returns if equal, earlier or later - * Example: 09.Jan.2007 13:07:25 -> compareWeek(2); -> 0 - * - * @param string|integer|array|\Magento\Framework\Stdlib\DateTime\DateInterface $week Week to compare - * @param string|\Zend_Locale $locale OPTIONAL Locale for parsing input - * @return integer 0 = equal, 1 = later, -1 = earlier - */ - public function compareWeek($week, $locale = null); - - /** - * Sets a new standard locale for the date object. - * This locale will be used for all functions - * Returned is the really set locale. - * Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist - * 'xx_YY' will be set to 'root' because 'xx' does not exist - * - * @param string|\Zend_Locale $locale (Optional) Locale for parsing input - * @throws \Zend_Date_Exception When the given locale does not exist - * @return $this Provides fluent interface - */ - public function setLocale($locale = null); - - /** - * Returns the actual set locale - * - * @return string - */ - public function getLocale(); - - /** - * Checks if the given date is a real date or datepart. - * Returns false if a expected datepart is missing or a datepart exceeds its possible border. - * But the check will only be done for the expected dateparts which are given by format. - * If no format is given the standard dateformat for the actual locale is used. - * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY' - * - * @param string|array|\Magento\Framework\Stdlib\DateTime\DateInterface $date Date to parse for correctness - * @param string $format (Optional) Format for parsing the date string - * @param string|\Zend_Locale $locale (Optional) Locale for parsing date parts - * @return boolean True when all date parts are correct - */ - public static function isDate($date, $format = null, $locale = null); - - /** - * Sets a new timezone for calculation of $this object's gmt offset. - * For a list of supported timezones look here: http://php.net/timezones - * If no timezone can be detected or the given timezone is wrong UTC will be set. - * - * @param string $zone OPTIONAL timezone for date calculation; defaults to date_default_timezone_get() - * @return \Zend_Date_DateObject Provides fluent interface - * @throws \Zend_Date_Exception - */ - public function setTimezone($zone = null); - - /** - * Return the timezone of $this object. - * The timezone is initially set when the object is instantiated. - * - * @return string actual set timezone string - */ - public function getTimezone(); - - /** - * Return the offset to GMT of $this object's timezone. - * The offset to GMT is initially set when the object is instantiated using the currently, - * in effect, default timezone for PHP functions. - * - * @return integer seconds difference between GMT timezone and timezone when object was instantiated - */ - public function getGmtOffset(); -} diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/DateTime.php index 6c9a15d46a0139fd900af6dc7815c302d67203cc..dc36a0755122edb792c32922c37ff1f8acddf4ee 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/DateTime.php @@ -114,7 +114,7 @@ class DateTime return false; } $date = $this->_localeDate->date($result); - $timestamp = $date->get(\Zend_Date::TIMESTAMP) - $date->get(\Zend_Date::TIMEZONE_SECS); + $timestamp = $date->getTimestamp() - $date->getTimezone()->getOffset($date); unset($date); return $timestamp; } @@ -136,7 +136,7 @@ class DateTime $result = strtotime($input); } $date = $this->_localeDate->date($result); - $timestamp = $date->get(\Zend_Date::TIMESTAMP) + $date->get(\Zend_Date::TIMEZONE_SECS); + $timestamp = $date->getTimestamp() + $date->getTimezone()->getOffset($date); unset($date); return $timestamp; } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php index 383b279eecd37cb279878efa2db64502bcb4692e..73ee29770c2e4879f74318f0915c245f303adcf5 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php @@ -37,7 +37,7 @@ class Date implements \Zend_Filter_Interface { $this->_localeDate = $localeDate; $this->_localToNormalFilter = new \Zend_Filter_LocalizedToNormalized( - ['date_format' => $this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_SHORT)] + ['date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)] ); $this->_normalToLocalFilter = new \Zend_Filter_NormalizedToLocalized( ['date_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT] diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php index 5d248a9233b8494d660e9501b49e5314bbd3e869..14b7b171b84ac0cfdc5aa15489a02c181150d701 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Filter/DateTime.php @@ -18,7 +18,7 @@ class DateTime extends Date $this->_localToNormalFilter = new \Zend_Filter_LocalizedToNormalized( [ 'date_format' => $this->_localeDate->getDateTimeFormat( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT ), ] ); diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php index f8e49a7ccbdb0058dee19b6bc180110e3dd622a1..2bd6553b4fb725a8b848497acf89c92e646f6c50 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php @@ -14,10 +14,10 @@ class Timezone implements TimezoneInterface * @var array */ protected $_allowedFormats = [ - TimezoneInterface::FORMAT_TYPE_FULL, - TimezoneInterface::FORMAT_TYPE_LONG, - TimezoneInterface::FORMAT_TYPE_MEDIUM, - TimezoneInterface::FORMAT_TYPE_SHORT, + \IntlDateFormatter::FULL, + \IntlDateFormatter::LONG, + \IntlDateFormatter::MEDIUM, + \IntlDateFormatter::SHORT, ]; /** @@ -35,11 +35,6 @@ class Timezone implements TimezoneInterface */ protected $_dateTime; - /** - * @var DateFactory - */ - protected $_dateFactory; - /** * @var string */ @@ -54,7 +49,6 @@ class Timezone implements TimezoneInterface * @param \Magento\Framework\App\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\Stdlib\DateTime $dateTime - * @param DateFactory $dateFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param string $scopeType * @param string $defaultTimezonePath @@ -63,7 +57,6 @@ class Timezone implements TimezoneInterface \Magento\Framework\App\ScopeResolverInterface $scopeResolver, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Stdlib\DateTime $dateTime, - DateFactory $dateFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $scopeType, $defaultTimezonePath @@ -71,7 +64,6 @@ class Timezone implements TimezoneInterface $this->_scopeResolver = $scopeResolver; $this->_localeResolver = $localeResolver; $this->_dateTime = $dateTime; - $this->_dateFactory = $dateFactory; $this->_defaultTimezonePath = $defaultTimezonePath; $this->_scopeConfig = $scopeConfig; $this->_scopeType = $scopeType; @@ -90,7 +82,7 @@ class Timezone implements TimezoneInterface */ public function getDefaultTimezone() { - return TimezoneInterface::DEFAULT_TIMEZONE; + return 'UTC'; } /** @@ -104,9 +96,13 @@ class Timezone implements TimezoneInterface /** * {@inheritdoc} */ - public function getDateFormat($type = null) + public function getDateFormat($type = \IntlDateFormatter::SHORT) { - return $this->_getTranslation($type, 'date'); + return (new \IntlDateFormatter( + $this->_localeResolver->getLocale(), + $type, + \IntlDateFormatter::NONE + ))->getPattern(); } /** @@ -116,17 +112,21 @@ class Timezone implements TimezoneInterface { return preg_replace( '/(?<!y)yy(?!y)/', - 'yyyy', - $this->_getTranslation(TimezoneInterface::FORMAT_TYPE_SHORT, 'date') + 'Y', + $this->getDateFormat() ); } /** * {@inheritdoc} */ - public function getTimeFormat($type = null) + public function getTimeFormat($type = \IntlDateFormatter::SHORT) { - return $this->_getTranslation($type, 'time'); + return (new \IntlDateFormatter( + $this->_localeResolver->getLocale(), + \IntlDateFormatter::NONE, + $type + ))->getPattern(); } /** @@ -139,26 +139,29 @@ class Timezone implements TimezoneInterface /** * {@inheritdoc} + * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function date($date = null, $part = null, $locale = null, $useTimezone = true) + public function date($date = null, $locale = null, $useTimezone = true) { - if (is_null($locale)) { - $locale = $this->_localeResolver->getLocale(); - } + $locale = $locale ?: $this->_localeResolver->getLocale(); + $timezone = $useTimezone + ? $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType) + : 'UTC'; if (empty($date)) { - // $date may be false, but \Magento\Framework\Stdlib\DateTime\DateInterface uses strict compare - $date = null; - } - $date = $this->_dateFactory->create(['date' => $date, 'part' => $part, 'locale' => $locale]); - if ($useTimezone) { - $timezone = $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType); - if ($timezone) { - $date->setTimezone($timezone); - } + return new \DateTime('now', new \DateTimeZone($timezone)); + } elseif ($date instanceof \DateTime) { + return $date->setTimezone(new \DateTimeZone($timezone)); + } elseif (!is_numeric($date)) { + $formatter = new \IntlDateFormatter( + $locale, + \IntlDateFormatter::SHORT, + \IntlDateFormatter::SHORT, + $timezone + ); + $date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp(); } - - return $date; + return (new \DateTime(null, new \DateTimeZone($timezone)))->setTimestamp($date); } /** @@ -167,12 +170,9 @@ class Timezone implements TimezoneInterface public function scopeDate($scope = null, $date = null, $includeTime = false) { $timezone = $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope); - $date = $this->_dateFactory->create( - ['date' => $date, 'part' => null, 'locale' => $this->_localeResolver->getLocale()] - ); - $date->setTimezone($timezone); + $date = new \DateTime(is_numeric($date) ? '@' . $date : $date, new \DateTimeZone($timezone)); if (!$includeTime) { - $date->setHour(0)->setMinute(0)->setSecond(0); + $date->setTime(0, 0, 0); } return $date; } @@ -180,64 +180,15 @@ class Timezone implements TimezoneInterface /** * {@inheritdoc} */ - public function formatDate($date = null, $format = TimezoneInterface::FORMAT_TYPE_SHORT, $showTime = false) + public function formatDate($date = null, $format = \IntlDateFormatter::SHORT, $showTime = false) { - if (!in_array($format, $this->_allowedFormats, true)) { - return $date; - } - if (!$date instanceof DateInterface && $date && !strtotime($date)) { - return ''; - } - if (is_null($date)) { - $date = $this->date(gmdate('U'), null, null); - } elseif (!$date instanceof DateInterface) { - $date = $this->date(strtotime($date), null, null); - } + $formatTime = $showTime ? $format : \IntlDateFormatter::NONE; - if ($showTime) { - $format = $this->getDateTimeFormat($format); - } else { - $format = $this->getDateFormat($format); + if (!($date instanceof \DateTime)) { + $date = new \DateTime($date); } - return $date->toString($format); - } - - /** - * {@inheritdoc} - */ - public function formatTime($time = null, $format = TimezoneInterface::FORMAT_TYPE_SHORT, $showDate = false) - { - if (!in_array($format, $this->_allowedFormats, true)) { - return $time; - } - - if (is_null($time)) { - $date = $this->date(time()); - } elseif ($time instanceof DateInterface) { - $date = $time; - } else { - $date = $this->date(strtotime($time)); - } - - if ($showDate) { - $format = $this->getDateTimeFormat($format); - } else { - $format = $this->getTimeFormat($format); - } - - return $date->toString($format); - } - - /** - * {@inheritdoc} - */ - public function utcDate($scope, $date, $includeTime = false, $format = null) - { - $dateObj = $this->scopeDate($scope, $date, $includeTime); - $dateObj->set($date, $format); - $dateObj->setTimezone(TimezoneInterface::DEFAULT_TIMEZONE); - return $dateObj; + return $this->formatDateTime($date, $format, $formatTime); } /** @@ -246,11 +197,7 @@ class Timezone implements TimezoneInterface public function scopeTimeStamp($scope = null) { $timezone = $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope); - $currentTimezone = @date_default_timezone_get(); - @date_default_timezone_set($timezone); - $date = date('Y-m-d H:i:s'); - @date_default_timezone_set($currentTimezone); - return strtotime($date); + return (new \DateTime('now', new \DateTimeZone($timezone ?: 'UTC')))->getTimestamp(); } /** @@ -280,15 +227,30 @@ class Timezone implements TimezoneInterface } /** - * Returns a localized information string, supported are several types of information. - * For detailed information about the types look into the documentation - * - * @param string $value Name to get detailed information about - * @param string $path (Optional) Type of information to return - * @return string|false The wished information in the given language + * @param \DateTimeInterface $date + * @param int $dateType + * @param int $timeType + * @param null $locale + * @param null $timezone + * @param string|null $pattern + * @return mixed */ - protected function _getTranslation($value = null, $path = null) - { - return $this->_localeResolver->getLocale()->getTranslation($value, $path, $this->_localeResolver->getLocale()); + public function formatDateTime( + \DateTimeInterface $date, + $dateType = \IntlDateFormatter::SHORT, + $timeType = \IntlDateFormatter::SHORT, + $locale = null, + $timezone = null, + $pattern = null + ) { + $formatter = new \IntlDateFormatter( + $locale ?: $this->_localeResolver->getLocale(), + $dateType, + $timeType, + $timezone ?: $date->getTimezone(), + null, + $pattern + ); + return $formatter->format($date); } } diff --git a/lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php b/lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php index 725f64ec64034ff9aaaf72d033d9e98f3005d2b6..48bbbc73796dba44f8d925ac6e56a61641363d80 100644 --- a/lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php +++ b/lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php @@ -10,22 +10,6 @@ namespace Magento\Framework\Stdlib\DateTime; interface TimezoneInterface { - /** - * Default timezone - */ - const DEFAULT_TIMEZONE = 'UTC'; - - /** - * Date and time format codes - */ - const FORMAT_TYPE_FULL = 'full'; - - const FORMAT_TYPE_LONG = 'long'; - - const FORMAT_TYPE_MEDIUM = 'medium'; - - const FORMAT_TYPE_SHORT = 'short'; - /** * Return path to default timezone * @@ -43,10 +27,10 @@ interface TimezoneInterface /** * Retrieve ISO date format * - * @param string $type + * @param int $type * @return string */ - public function getDateFormat($type = null); + public function getDateFormat($type = \IntlDateFormatter::SHORT); /** * Retrieve short date format with 4-digit year @@ -72,39 +56,25 @@ interface TimezoneInterface public function getDateTimeFormat($type); /** - * Create \Magento\Framework\Stdlib\DateTime\DateInterface object for current locale + * Create \DateTime object for current locale * * @param mixed $date - * @param string $part - * @param string|Zend_Locale $locale + * @param string $locale * @param bool $useTimezone - * @return \Magento\Framework\Stdlib\DateTime\DateInterface + * @return \DateTime */ - public function date($date = null, $part = null, $locale = null, $useTimezone = true); + public function date($date = null, $locale = null, $useTimezone = true); /** - * Create \Magento\Framework\Stdlib\DateTime\DateInterface object with date converted to scope timezone and scope Locale + * Create \DateTime object with date converted to scope timezone and scope Locale * * @param mixed $scope Information about scope - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface|array|null $date date in UTC + * @param string|integer|\DateTime|array|null $date date in UTC * @param boolean $includeTime flag for including time to date - * @return \Magento\Framework\Stdlib\DateTime\DateInterface + * @return \DateTime */ public function scopeDate($scope = null, $date = null, $includeTime = false); - /** - * Create \Magento\Framework\Stdlib\DateTime\DateInterface object with date converted from scope's timezone - * to UTC time zone. Date can be passed in format of scope's locale - * or in format which was passed as parameter. - * - * @param mixed $scope Information about scope - * @param string|integer|\Magento\Framework\Stdlib\DateTime\DateInterface|array|null $date date in scope's timezone - * @param boolean $includeTime flag for including time to date - * @param null|string $format - * @return \Magento\Framework\Stdlib\DateTime\DateInterface - */ - public function utcDate($scope, $date, $includeTime = false, $format = null); - /** * Get scope timestamp * Timestamp will be built with scope timezone settings @@ -117,31 +87,17 @@ interface TimezoneInterface /** * Format date using current locale options and time zone. * - * @param \Magento\Framework\Stdlib\DateTime\DateInterface|null $date - * @param string $format + * @param \DateTime|null $date + * @param int $format * @param bool $showTime * @return string */ public function formatDate( $date = null, - $format = \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, + $format = \IntlDateFormatter::SHORT, $showTime = false ); - /** - * Format time using current locale options - * - * @param \Magento\Framework\Stdlib\DateTime\DateInterface|null $time - * @param string $format - * @param bool $showDate - * @return string - */ - public function formatTime( - $time = null, - $format = \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, - $showDate = false - ); - /** * Gets the scope config timezone * @@ -158,4 +114,22 @@ interface TimezoneInterface * @return bool */ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null); + + /** + * @param \DateTimeInterface $date + * @param int $dateType + * @param int $timeType + * @param null $locale + * @param null $timezone + * @param string|null $pattern + * @return mixed + */ + public function formatDateTime( + \DateTimeInterface $date, + $dateType = \IntlDateFormatter::SHORT, + $timeType = \IntlDateFormatter::SHORT, + $locale = null, + $timezone = null, + $pattern = null + ); } diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php deleted file mode 100644 index b68610ddeb7f129750a1cfe9e49f878f0c0edebe..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/DateTimeTest.php +++ /dev/null @@ -1,118 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Stdlib\Test\Unit\DateTime; - -class DateTimeTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Magento\Framework\Stdlib\DateTime\DateTime */ - protected $dateTime; - - /** @var \Magento\Framework\Stdlib\DateTime\Date */ - protected $date; - - /** @var \Magento\Framework\Stdlib\DateTime\Timezone|\PHPUnit_Framework_MockObject_MockObject */ - protected $localeDate; - - protected function setUp() - { - require_once __DIR__ . '/../_files/gmdate_mock.php'; - $this->date = new \Magento\Framework\Stdlib\DateTime\Date(1403832149); - - $this->localeDate = $this->getMock( - 'Magento\Framework\Stdlib\DateTime\Timezone', - ['getConfigTimezone', 'date'], - [], - '', - false - ); - $this->localeDate->expects($this->any())->method('getConfigTimezone') - ->will($this->returnValue('America/Los_Angeles')); - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->dateTime = $objectManager->getObject( - 'Magento\Framework\Stdlib\DateTime\DateTime', - ['localeDate' => $this->localeDate] - ); - } - - public function testCalculateOffset() - { - if (date('I')) { - $this->assertSame(-25200, $this->dateTime->calculateOffset()); - } else { - $this->assertSame(-28800, $this->dateTime->calculateOffset()); - } - $curZone = @date_default_timezone_get(); - date_default_timezone_set('Europe/Kiev'); - if (date('I')) { - $this->assertSame(10800, $this->dateTime->calculateOffset('Europe/Kiev')); - } else { - $this->assertSame(7200, $this->dateTime->calculateOffset('Europe/Kiev')); - } - date_default_timezone_set($curZone); - } - - public function testGmtDate() - { - $time = 1403858418; - $this->localeDate->expects($this->any())->method('date')->with($time) - ->will($this->returnValue($this->date)); - $this->assertSame(false, $this->dateTime->gmtDate(null, 'tro-lo-lo')); - $this->assertSame('2014-06-27', $this->dateTime->gmtDate('Y-m-d', $time)); - } - - public function testDate() - { - $time = 1403858418; - $this->localeDate->expects($this->any())->method('date')->with($time) - ->will($this->returnValue($this->date)); - $this->assertSame('2014-06-26', $this->dateTime->date('Y-m-d', $time)); - $this->assertSame('2014-06-26 11:22:29', $this->dateTime->date(null, $time)); - } - - public function testGmtTimestamp() - { - $time = time(); - $this->localeDate->expects($this->at(0))->method('date')->with($time) - ->will($this->returnValue($this->date)); - $this->localeDate->expects($this->at(1))->method('date')->with(strtotime("10 September 2000")) - ->will($this->returnValue($this->date)); - - $this->assertSame(1403857349, $this->dateTime->gmtTimestamp($time)); - $this->assertSame(1403857349, $this->dateTime->gmtTimestamp("10 September 2000")); - $this->assertSame(false, $this->dateTime->gmtTimestamp("la-la-la")); - $this->assertSame(1404377188, $this->dateTime->gmtTimestamp()); - } - - public function testTimestamp() - { - $time = time(); - $this->localeDate->expects($this->at(0))->method('date')->with(1404377188) - ->will($this->returnValue($this->date)); - $this->localeDate->expects($this->at(1))->method('date')->with($time) - ->will($this->returnValue($this->date)); - $this->localeDate->expects($this->at(2))->method('date')->with(strtotime("10 September 2000")) - ->will($this->returnValue($this->date)); - - $this->assertSame(1403806949, $this->dateTime->timestamp()); - $this->assertSame(1403806949, $this->dateTime->timestamp($time)); - $this->assertSame(1403806949, $this->dateTime->timestamp("10 September 2000")); - } - - public function testGetGmtOffset() - { - if (date('I')) { - $this->assertSame(-25200, $this->dateTime->getGmtOffset('seconds')); - $this->assertSame(-25200, $this->dateTime->getGmtOffset('seconds11')); - $this->assertSame(-420, $this->dateTime->getGmtOffset('minutes')); - $this->assertSame(-7, $this->dateTime->getGmtOffset('hours')); - } else { - $this->assertSame(-28800, $this->dateTime->getGmtOffset('seconds')); - $this->assertSame(-28800, $this->dateTime->getGmtOffset('seconds11')); - $this->assertSame(-480, $this->dateTime->getGmtOffset('minutes')); - $this->assertSame(-8, $this->dateTime->getGmtOffset('hours')); - } - } -} diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php index b11a27c2d214f0d1873655aebec102f28b53c5f5..1620d3e73e945c04e86496124d06112e9a63ef5c 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTest.php @@ -17,7 +17,7 @@ class DateTest extends \PHPUnit_Framework_TestCase )->method( 'getDateFormat' )->with( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT )->will( $this->returnValue('MM-dd-yyyy') ); diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php index beca4b126d13a165aa832bcbc1bde6f33d81da34..5cd2f61d67dc54d353f02167562fd7ccfe1ca647 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/Filter/DateTimeTest.php @@ -17,7 +17,7 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase )->method( 'getDateTimeFormat' )->with( - \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT + \IntlDateFormatter::SHORT )->will( $this->returnValue('HH:mm:ss MM-dd-yyyy') ); diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php deleted file mode 100644 index 818f80c660948be3817f3ee6cec5285424b4a59c..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php +++ /dev/null @@ -1,181 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\Stdlib\Test\Unit\DateTime; - -use Magento\Directory\Helper\Data; - -class TimezoneTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Magento\Framework\Stdlib\DateTime\Timezone */ - protected $timezone; - - /** @var \Magento\Backend\Model\Locale\Resolver\Interceptor|\PHPUnit_Framework_MockObject_MockObject */ - protected $localeResolver; - - /** @var \Magento\Framework\Stdlib\DateTime\DateFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $dateFactory; - - /** @var \Magento\Framework\App\Config|\PHPUnit_Framework_MockObject_MockObject */ - protected $scopeConfig; - - /** @var \Magento\Framework\Locale|\PHPUnit_Framework_MockObject_MockObject */ - protected $locale; - - /** @var \Magento\Framework\Stdlib\DateTime|\PHPUnit_Framework_MockObject_MockObject */ - protected $dateTime; - - /** @var \Magento\Store\Model\Resolver\Store|\PHPUnit_Framework_MockObject_MockObject */ - protected $scopeResolver; - - protected function setUp() - { - $this->locale = $this->getMock('Magento\Framework\Locale', ['getTranslation', 'toString'], [], '', false); - $this->dateTime = $this->getMock('Magento\Framework\Stdlib\DateTime', ['isEmptyDate'], [], '', false); - $this->scopeConfig = $this->getMock('Magento\Framework\App\Config', ['getValue'], [], '', false); - $this->localeResolver = $this->getMock('Magento\Backend\Model\Locale\Resolver', ['getLocale'], [], '', false); - $this->dateFactory = $this->getMock('Magento\Framework\Stdlib\DateTime\DateFactory', ['create'], [], '', false); - $this->scopeResolver = $this->getMock('Magento\Store\Model\Resolver\Store', ['getScope'], [], '', false); - - $this->localeResolver->expects($this->any())->method('getLocale')->will($this->returnValue($this->locale)); - $this->scopeConfig->expects($this->any()) - ->method('getValue') - ->with(Data::XML_PATH_DEFAULT_TIMEZONE, 'store') - ->will($this->returnValue('America/Los_Angeles')); - $this->locale->expects($this->any())->method('toString')->will($this->returnValue('en_US')); - - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $this->timezone = $objectManager->getObject( - 'Magento\Framework\Stdlib\DateTime\Timezone', - [ - 'scopeResolver' => $this->scopeResolver, - 'localeResolver' => $this->localeResolver, - 'dateTime' => $this->dateTime, - 'dateFactory' => $this->dateFactory, - 'scopeConfig' => $this->scopeConfig, - 'scopeType' => 'store', - 'defaultTimezonePath' => Data::XML_PATH_DEFAULT_TIMEZONE - ] - ); - } - - public function testGetDateFormatWithLongYear() - { - $this->markTestIncomplete('MAGETWO-26166'); - $this->locale->staticExpects($this->once())->method('getTranslation')->with('short', 'date') - ->will($this->returnValue('M/d/yy')); - $this->assertSame('M/d/yyyy', $this->timezone->getDateFormatWithLongYear()); - } - - public function testDate() - { - $this->dateFactory->expects($this->any())->method('create') - ->with(['date' => null, 'part' => null, 'locale' => $this->locale]) - ->will($this->returnValue(new \Magento\Framework\Stdlib\DateTime\Date(null, null, $this->locale))); - $date = $this->timezone->date(); - $this->assertSame('America/Los_Angeles', $date->getTimezone()); - } - - public function testFormatDate() - { - $time = date('M j, Y'); - $date1 = new \Magento\Framework\Stdlib\DateTime\Date(1347260400, null, $this->locale); - $date2 = new \Magento\Framework\Stdlib\DateTime\Date(strtotime($time), null, $this->locale); - - $this->dateFactory->expects($this->at(0))->method('create') - ->will($this->returnValue($date1)); - $this->dateFactory->expects($this->at(1))->method('create') - ->will($this->returnValue($date1)); - $this->dateFactory->expects($this->at(2))->method('create') - ->will($this->returnValue($date2)); - $this->dateFactory->expects($this->exactly(3))->method('create'); - - $this->markTestIncomplete('MAGETWO-26166'); - $this->locale->staticExpects($this->at(0))->method('getTranslation') - ->with('medium', 'date', $this->locale) - ->will($this->returnValue('MMM d, y')); - $this->locale->staticExpects($this->at(1))->method('getTranslation') - ->with('medium', 'time', $this->locale) - ->will($this->returnValue('h:mm:ss a')); - $this->locale->staticExpects($this->at(2))->method('getTranslation') - ->with('medium', 'date', $this->locale) - ->will($this->returnValue('MMM d, y')); - $this->locale->staticExpects($this->at(3))->method('getTranslation') - ->with('medium', 'date', $this->locale) - ->will($this->returnValue('MMM d, y')); - $this->locale->staticExpects($this->exactly(4))->method('getTranslation'); - - $this->assertSame( - 'Sep 10, 2012 12:00:00 AM', - $this->timezone->formatDate("10 September 2012", 'medium', true) - ); - $this->assertSame( - 'Sep 10, 2012', - $this->timezone->formatDate("10 September 2012", 'medium') - ); - $this->assertSame( - $time, - $this->timezone->formatDate(null, 'medium') - ); - $this->assertSame('date', $this->timezone->formatDate('date', 'wrong')); - $this->assertSame('', $this->timezone->formatDate('date')); - } - - public function testFormatTime() - { - $time = date('M j, Y g:m:s A'); - $date1 = new \Magento\Framework\Stdlib\DateTime\Date(1347260470, null, $this->locale); - $date2 = new \Magento\Framework\Stdlib\DateTime\Date(strtotime($time), null, $this->locale); - - $this->dateFactory->expects($this->at(0))->method('create') - ->with(['date' => 1347260470, 'part' => null, 'locale' => $this->locale]) - ->will($this->returnValue($date1)); - $this->dateFactory->expects($this->at(1))->method('create')->will($this->returnValue($date2)); - $this->dateFactory->expects($this->exactly(2))->method('create'); - - $this->markTestIncomplete('MAGETWO-26166'); - $this->locale->staticExpects($this->at(0))->method('getTranslation') - ->with('medium', 'time', $this->locale) - ->will($this->returnValue('h:mm:ss a')); - $this->locale->staticExpects($this->at(1))->method('getTranslation') - ->with('medium', 'time', $this->locale) - ->will($this->returnValue('h:mm:ss a')); - $this->locale->staticExpects($this->at(2))->method('getTranslation') - ->with('medium', 'date', $this->locale) - ->will($this->returnValue('MMM d, y')); - $this->locale->staticExpects($this->at(3))->method('getTranslation') - ->with('medium', 'time', $this->locale) - ->will($this->returnValue('h:mm:ss a')); - $this->locale->staticExpects($this->exactly(4))->method('getTranslation'); - - $this->assertSame('10 September 2012', $this->timezone->formatTime('10 September 2012', 'wrong_type')); - $this->assertSame('12:01:10 AM', $this->timezone->formatTime('September 10, 2012 12:01:10 AM', 'medium')); - $this->assertSame('12:01:10 AM', $this->timezone->formatTime($date1, 'medium')); - $this->assertSame($time, $this->timezone->formatTime(null, 'medium', true)); - } - - public function testUtcDate() - { - $this->dateFactory->expects($this->any())->method('create') - ->with(['date' => 1347260470, 'part' => null, 'locale' => $this->locale]) - ->will($this->returnValue(new \Magento\Framework\Stdlib\DateTime\Date(1347260470, null, $this->locale))); - - $date = $this->timezone->utcDate(Data::XML_PATH_DEFAULT_TIMEZONE, 1347260470); - $this->assertSame('UTC', $date->getTimezone()); - } - - public function testIsScopeDateInInterval() - { - $scope = $this->getMock('Magento\Framework\App\ScopeInterface', ['getCode', 'getId']); - $this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValue($scope)); - $this->dateTime->expects($this->at(0))->method('isEmptyDate')->will($this->returnValue(false)); - $this->dateTime->expects($this->at(1))->method('isEmptyDate')->will($this->returnValue(false)); - $this->dateTime->expects($this->at(2))->method('isEmptyDate')->will($this->returnValue(true)); - $this->dateTime->expects($this->at(3))->method('isEmptyDate')->will($this->returnValue(true)); - - $this->assertFalse($this->timezone->isScopeDateInInterval('store')); - $this->assertTrue($this->timezone->isScopeDateInInterval('store', null, '10 September 2036')); - } -} diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTimeTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTimeTest.php deleted file mode 100644 index bcad771f8db8df8f07aa345745103d13afdcb5d4..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTimeTest.php +++ /dev/null @@ -1,111 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -/** - * \Magento\Framework\Stdlib\DateTime test case - */ -namespace Magento\Framework\Stdlib\Test\Unit; - -class DateTimeTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var \Magento\Framework\Stdlib\DateTime - */ - protected $_dateTime; - - protected function setUp() - { - $this->_dateTime = new \Magento\Framework\Stdlib\DateTime(); - } - - public function testToTimestamp() - { - $date = new \Magento\Framework\Stdlib\DateTime\Date(); - $dateTime = new \Magento\Framework\Stdlib\DateTime(); - $this->assertEquals($date->getTimestamp(), $dateTime->toTimestamp($date)); - - $this->assertEquals(time(), $dateTime->toTimestamp(true)); - - $date = '2012-07-19 16:52'; - $this->assertEquals(strtotime($date), $dateTime->toTimestamp($date)); - } - - public function testNow() - { - $this->assertEquals(date(\Magento\Framework\Stdlib\DateTime::DATE_PHP_FORMAT), $this->_dateTime->now(true)); - $this->assertEquals( - date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT), - $this->_dateTime->now(false) - ); - } - - /** - * @dataProvider formatDateDataProvider - * - * expectedFormat is to be in the Y-m-d type format for the date you are expecting, - * expectedResult is if a specific date is expected. - */ - public function testFormatDate($date, $includeTime, $expectedFormat, $expectedResult = null) - { - $dateTime = new \Magento\Framework\Stdlib\DateTime(); - $actual = $dateTime->formatDate($date, $includeTime); - if ($expectedFormat != '') { - $expectedResult = date($expectedFormat); - } else { - if ($expectedResult === null) { - $expectedResult = ''; - } - } - $this->assertEquals($expectedResult, $actual); - } - - /** - * @return array - */ - public function formatDateDataProvider() - { - // Take care when calling date here as it can be called much earlier than when testFormatDate - // executes thus causing a discrepancy in the actual vs expected time. See MAGETWO-10296 - $date = new \Magento\Framework\Stdlib\DateTime\Date(); - return [ - 'null' => [null, false, ''], - 'null including Time' => [null, true, ''], - 'Bool true' => [true, false, 'Y-m-d'], - 'Bool true including Time' => [true, true, 'Y-m-d H:i:s'], - 'Bool false' => [false, false, ''], - 'Bool false including Time' => [false, true, ''], - 'Zend Date' => [$date, false, date('Y-m-d', $date->getTimestamp())], - 'Zend Date including Time' => [$date, true, date('Y-m-d H:i:s', $date->getTimestamp())] - ]; - } - - /** - * @param string $date - * @param bool $expected - * - * @dataProvider isEmptyDateDataProvider - */ - public function testIsEmptyDate($date, $expected) - { - $actual = $this->_dateTime->isEmptyDate($date); - $this->assertEquals($actual, $expected); - } - - /** - * @return array - */ - public function isEmptyDateDataProvider() - { - return [ - ['', true], - [' ', true], - ['0000-00-00', true], - ['0000-00-00 00:00:00', true], - ['2000-10-10', false], - ['2000-10-10 10:10:10', false] - ]; - } -} diff --git a/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php b/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php index fca377e04d86651e5192e806c4f401e134326429..2b5801c531335135f480cd1d2032c827c875e97b 100644 --- a/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php +++ b/lib/internal/Magento/Framework/Test/Unit/TranslateTest.php @@ -224,13 +224,13 @@ class TranslateTest extends \PHPUnit_Framework_TestCase public function testGetLocale() { - $this->locale->expects($this->once())->method('getLocaleCode')->will($this->returnValue('en_US')); + $this->locale->expects($this->once())->method('getLocale')->will($this->returnValue('en_US')); $this->assertEquals('en_US', $this->translate->getLocale()); - $this->locale->expects($this->never())->method('getLocaleCode'); + $this->locale->expects($this->never())->method('getLocale'); $this->assertEquals('en_US', $this->translate->getLocale()); - $this->locale->expects($this->never())->method('getLocaleCode'); + $this->locale->expects($this->never())->method('getLocale'); $this->translate->setLocale('en_GB'); $this->assertEquals('en_GB', $this->translate->getLocale()); } @@ -238,7 +238,7 @@ class TranslateTest extends \PHPUnit_Framework_TestCase public function testSetLocale() { $this->translate->setLocale('en_GB'); - $this->locale->expects($this->never())->method('getLocaleCode'); + $this->locale->expects($this->never())->method('getLocale'); $this->assertEquals('en_GB', $this->translate->getLocale()); } @@ -270,7 +270,7 @@ class TranslateTest extends \PHPUnit_Framework_TestCase */ protected function expectsSetConfig($themeId, $localeCode = 'en_US') { - $this->locale->expects($this->any())->method('getLocaleCode')->will($this->returnValue($localeCode)); + $this->locale->expects($this->any())->method('getLocale')->will($this->returnValue($localeCode)); $scope = new \Magento\Framework\Object(['code' => 'frontendCode', 'id' => 1]); $scopeAdmin = new \Magento\Framework\Object(['code' => 'adminCode', 'id' => 0]); $this->scopeResolver->expects($this->any()) diff --git a/lib/internal/Magento/Framework/Translate.php b/lib/internal/Magento/Framework/Translate.php index 285dc1940289257695077fbfbbe6a744c3385443..5cf4c5a87940f9f540cb21b037600ee7432dd777 100644 --- a/lib/internal/Magento/Framework/Translate.php +++ b/lib/internal/Magento/Framework/Translate.php @@ -373,7 +373,7 @@ class Translate implements \Magento\Framework\TranslateInterface public function getLocale() { if (null === $this->_localeCode) { - $this->_localeCode = $this->_locale->getLocaleCode(); + $this->_localeCode = $this->_locale->getLocale(); } return $this->_localeCode; } diff --git a/lib/internal/Magento/Framework/Translate/AbstractAdapter.php b/lib/internal/Magento/Framework/Translate/AbstractAdapter.php index d059728f61532b288f7861df2298730d945ccc1d..ebee9ba111b3a38f3d91932a94c5283200a59a83 100644 --- a/lib/internal/Magento/Framework/Translate/AbstractAdapter.php +++ b/lib/internal/Magento/Framework/Translate/AbstractAdapter.php @@ -16,7 +16,7 @@ abstract class AbstractAdapter extends \Zend_Translate_Adapter implements Adapte * * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param mixed $data - * @param string|\Zend_Locale $locale + * @param string $locale * @param array $options (optional) * @return array */ @@ -45,7 +45,7 @@ abstract class AbstractAdapter extends \Zend_Translate_Adapter implements Adapte * Stub for setLocale functionality * * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @param string|\Zend_Locale $locale + * @param string $locale * @return $this */ public function setLocale($locale) diff --git a/lib/internal/Magento/Framework/View/Asset/Bundle.php b/lib/internal/Magento/Framework/View/Asset/Bundle.php index 81a8d7735875774140bda849ee381118659aa64b..4f9d0e68ef62b1c980a519a38a071340c5150fa2 100644 --- a/lib/internal/Magento/Framework/View/Asset/Bundle.php +++ b/lib/internal/Magento/Framework/View/Asset/Bundle.php @@ -99,7 +99,7 @@ class Bundle { /** @var FallbackContext $context */ $context = $asset->getContext(); - return $context->getAreaCode() . ':' . $context->getThemePath() . ':' . $context->getLocaleCode(); + return $context->getAreaCode() . ':' . $context->getThemePath() . ':' . $context->getLocale(); } /** diff --git a/lib/internal/Magento/Framework/View/Asset/File/FallbackContext.php b/lib/internal/Magento/Framework/View/Asset/File/FallbackContext.php index 171d4fc93bfc588348fa98e7c5a6ca0946847aa1..9fadcbb3a4d69e17ff97a4a4b63482d067b9521e 100644 --- a/lib/internal/Magento/Framework/View/Asset/File/FallbackContext.php +++ b/lib/internal/Magento/Framework/View/Asset/File/FallbackContext.php @@ -79,7 +79,7 @@ class FallbackContext extends Context * * @return string */ - public function getLocaleCode() + public function getLocale() { return $this->locale; } diff --git a/lib/internal/Magento/Framework/View/Asset/Source.php b/lib/internal/Magento/Framework/View/Asset/Source.php index a1e5837842206e6d6190c2ec20a73481707b7295..747ab55ab07c3d4952587065da0fa6f47841d33a 100644 --- a/lib/internal/Magento/Framework/View/Asset/Source.php +++ b/lib/internal/Magento/Framework/View/Asset/Source.php @@ -205,7 +205,7 @@ class Source $sourceFile = $this->fallback->getFile( $context->getAreaCode(), $themeModel, - $context->getLocaleCode(), + $context->getLocale(), $asset->getFilePath(), $asset->getModule() ); diff --git a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php index 73f90325de211f2ba007a0eef0125ece92d531ad..31348d7cd6cb20f74338c7d795c3c6f22f846329 100644 --- a/lib/internal/Magento/Framework/View/Element/AbstractBlock.php +++ b/lib/internal/Magento/Framework/View/Element/AbstractBlock.php @@ -765,33 +765,43 @@ abstract class AbstractBlock extends \Magento\Framework\Object implements BlockI /** * Retrieve formatting date * - * @param \Zend_Date|string|null $date - * @param string $format + * @param \DateTime|string|null $date + * @param int $format * @param bool $showTime * @return string */ public function formatDate( $date = null, - $format = \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, + $format = \IntlDateFormatter::SHORT, $showTime = false ) { - return $this->_localeDate->formatDate($date, $format, $showTime); + $date = $date instanceof \DateTimeInterface ? $date : new \DateTime($date); + return $this->_localeDate->formatDateTime( + $date, + $format, + $showTime ? $format : \IntlDateFormatter::NONE + ); } /** * Retrieve formatting time * - * @param \Zend_Date|string|null $time - * @param string $format + * @param \DateTime|string|null $time + * @param int $format * @param bool $showDate * @return string */ public function formatTime( $time = null, - $format = \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT, + $format = \IntlDateFormatter::SHORT, $showDate = false ) { - return $this->_localeDate->formatTime($time, $format, $showDate); + $time = $time instanceof \DateTimeInterface ? $time : new \DateTime($time); + return $this->_localeDate->formatDateTime( + $time, + $showDate ? $format : \IntlDateFormatter::NONE, + $format + ); } /** diff --git a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php index b9b7b2e4a7dfca0502d3b79f5be96b41d410c529..c2351e2de84123c6fe0a5c74efb96794a056f808 100644 --- a/lib/internal/Magento/Framework/View/Element/Html/Calendar.php +++ b/lib/internal/Magento/Framework/View/Element/Html/Calendar.php @@ -5,7 +5,7 @@ */ namespace Magento\Framework\View\Element\Html; -use Magento\Framework\Stdlib\DateTime\TimezoneInterface; +use Magento\Framework\Locale\Bundle\DataBundle; /** * Calendar block for page header @@ -62,35 +62,39 @@ class Calendar extends \Magento\Framework\View\Element\Template */ protected function _toHtml() { - $localeCode = $this->_localeResolver->getLocaleCode(); + $localeData = (new DataBundle())->get($this->_localeResolver->getLocale()); // get days names - $days = \Zend_Locale_Data::getList($localeCode, 'days'); + $daysData = $localeData['calendar']['gregorian']['dayNames']; $this->assign( 'days', [ - 'wide' => $this->encoder->encode(array_values($days['format']['wide'])), - 'abbreviated' => $this->encoder->encode(array_values($days['format']['abbreviated'])) + 'wide' => $this->encoder->encode(array_values(iterator_to_array($daysData['format']['wide']))), + 'abbreviated' => $this->encoder->encode( + array_values(iterator_to_array($daysData['format']['abbreviated'])) + ), ] ); // get months names - $months = \Zend_Locale_Data::getList($localeCode, 'months'); + $monthsData = $localeData['calendar']['gregorian']['monthNames']; $this->assign( 'months', [ - 'wide' => $this->encoder->encode(array_values($months['format']['wide'])), - 'abbreviated' => $this->encoder->encode(array_values($months['format']['abbreviated'])) + 'wide' => $this->encoder->encode(array_values(iterator_to_array($monthsData['format']['wide']))), + 'abbreviated' => $this->encoder->encode( + array_values(iterator_to_array($monthsData['format']['abbreviated'])) + ), ] ); // get "today" and "week" words - $this->assign('today', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'relative', 0))); - $this->assign('week', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'field', 'week'))); + $this->assign('today', $this->encoder->encode($localeData['fields']['day']['relative']['0'])); + $this->assign('week', $this->encoder->encode($localeData['fields']['week']['dn'])); // get "am" & "pm" words - $this->assign('am', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'am'))); - $this->assign('pm', $this->encoder->encode(\Zend_Locale_Data::getContent($localeCode, 'pm'))); + $this->assign('am', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['0'])); + $this->assign('pm', $this->encoder->encode($localeData['calendar']['gregorian']['AmPmMarkers']['1'])); // get first day of week and weekend days $this->assign( @@ -114,23 +118,22 @@ class Calendar extends \Magento\Framework\View\Element\Template $this->assign( 'defaultFormat', $this->encoder->encode( - $this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_MEDIUM) + $this->_localeDate->getDateFormat(\IntlDateFormatter::MEDIUM) ) ); $this->assign( 'toolTipFormat', $this->encoder->encode( - $this->_localeDate->getDateFormat(TimezoneInterface::FORMAT_TYPE_LONG) + $this->_localeDate->getDateFormat(\IntlDateFormatter::LONG) ) ); // get days and months for en_US locale - calendar will parse exactly in this locale - $days = \Zend_Locale_Data::getList('en_US', 'days'); - $months = \Zend_Locale_Data::getList('en_US', 'months'); + $englishMonths = (new DataBundle())->get('en_US')['calendar']['gregorian']['monthNames']; $enUS = new \stdClass(); $enUS->m = new \stdClass(); - $enUS->m->wide = array_values($months['format']['wide']); - $enUS->m->abbr = array_values($months['format']['abbreviated']); + $enUS->m->wide = array_values(iterator_to_array($englishMonths['format']['wide'])); + $enUS->m->abbr = array_values(iterator_to_array($englishMonths['format']['abbreviated'])); $this->assign('enUS', $this->encoder->encode($enUS)); return parent::_toHtml(); @@ -164,7 +167,7 @@ class Calendar extends \Magento\Framework\View\Element\Template */ public function getYearRange() { - return (int)$this->_localeDate->date('Y')->__toString() - 100 - . ':' . $this->_localeDate->date('Y')->__toString(); + return (new \DateTime())->modify('- 100 years')->format('Y') + . ':' . (new \DateTime())->format('Y'); } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php index 03f7da3302ae9604e6bac54a5558df14c959cf0d..d995bb91d88eb13e490542792e1362580e3305fb 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Element/Html/CalendarTest.php @@ -47,19 +47,7 @@ class CalendarTest extends \PHPUnit_Framework_TestCase */ public function testGetYearRange() { - $testCurrentYear = 2123; - $date = $this->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateInterface') - ->getMock(); - - $date->expects($this->any()) - ->method('__toString') - ->will($this->returnValue($testCurrentYear)); - - $this->localeDate->expects($this->any()) - ->method('date') - ->with($this->equalTo('Y')) - ->will($this->returnValue($date)); - + $testCurrentYear = (new \DateTime())->format('Y'); $this->assertEquals((int)$testCurrentYear - 100 . ':' . $testCurrentYear, $this->block->getYearRange()); } } diff --git a/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php b/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php index 536bddd66f89f5303dc6090216b566c364f37dcf..06b78b7c35cd5edcad9fd870d6b2c9fb89a9a14a 100644 --- a/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php +++ b/lib/internal/Magento/Framework/Webapi/ErrorProcessor.php @@ -294,7 +294,9 @@ class ErrorProcessor if ($this->_appState->getMode() == State::MODE_DEVELOPER) { $this->renderErrorMessage($errorMessage); } else { - $this->renderErrorMessage(new Phrase('Server internal error. See details in report api/%1', $reportId)); + $this->renderErrorMessage( + new Phrase('Server internal error. See details in report api/%1', [$reportId]) + ); } } } diff --git a/lib/web/mage/calendar.js b/lib/web/mage/calendar.js index 8f800b68f4685f1f70ef3912b61a1e87286c2fd4..e445e62e05929be9f648a9e3f53092bf3917c4ac 100644 --- a/lib/web/mage/calendar.js +++ b/lib/web/mage/calendar.js @@ -117,6 +117,8 @@ date: { 'EEEE': 'DD', 'EEE': 'D', + 'EE': 'D', + 'E': 'D', 'D': 'o', 'MMMM': 'MM', 'MMM': 'M', @@ -124,6 +126,7 @@ 'M': 'mm', 'yyyy': 'yy', 'y': 'yy', + 'Y': 'yy', 'yy': 'yy' // Always long year format on frontend }, time: { diff --git a/setup/src/Magento/Setup/Model/Lists.php b/setup/src/Magento/Setup/Model/Lists.php index d97b9e4970f6ce305a68a899601837426f200f11..61a45c8d9cda31097470ae1064b86a3f800ef1cf 100644 --- a/setup/src/Magento/Setup/Model/Lists.php +++ b/setup/src/Magento/Setup/Model/Lists.php @@ -6,18 +6,14 @@ namespace Magento\Setup\Model; -use Zend_Locale; +use Magento\Framework\Locale\Bundle\CurrencyBundle; +use Magento\Framework\Locale\Bundle\LanguageBundle; +use Magento\Framework\Locale\Bundle\RegionBundle; use Magento\Framework\Locale\ConfigInterface; +use Magento\Framework\Locale\ResolverInterface; class Lists { - /** - * Zend locale object - * - * @var Zend_Locale - */ - protected $zendLocale; - /** * List of allowed locales * @@ -26,14 +22,10 @@ class Lists protected $allowedLocales; /** - * Constructor - * - * @param Zend_Locale $zendLocale * @param ConfigInterface $localeConfig */ - public function __construct(Zend_Locale $zendLocale, ConfigInterface $localeConfig) + public function __construct(ConfigInterface $localeConfig) { - $this->zendLocale = $zendLocale; $this->allowedLocales = $localeConfig->getAllowedLocales(); } @@ -44,10 +36,14 @@ class Lists */ public function getTimezoneList() { - $timeZone = $this->zendLocale->getTranslationList('TimezoneToWindows'); + $zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC); $list = []; - foreach ($timeZone as $windows => $iso) { - $list[$iso] = $windows . ' (' . $iso . ')'; + foreach ($zones as $code) { + $list[$code] = \IntlTimeZone::createTimeZone($code)->getDisplayName( + false, + \IntlTimeZone::DISPLAY_LONG, + ResolverInterface::DEFAULT_LOCALE + ) . ' (' . $code . ')'; } asort($list); return $list; @@ -60,10 +56,10 @@ class Lists */ public function getCurrencyList() { - $currencies = $this->zendLocale->getTranslationList('NameToCurrency'); + $currencies = (new CurrencyBundle())->get(ResolverInterface::DEFAULT_LOCALE)['Currencies']; $list = []; - foreach ($currencies as $code => $value) { - $list[$code] = $value . ' (' . $code . ')'; + foreach ($currencies as $code => $data) { + $list[$code] = $data[1] . ' (' . $code . ')'; } asort($list); return $list; @@ -76,27 +72,21 @@ class Lists */ public function getLocaleList() { - $languages = $this->zendLocale->getTranslationList('Language'); - $countries = $this->zendLocale->getTranslationList('Territory'); - $locales = $this->zendLocale->getLocaleList(); - - $allowedAliases = []; - foreach ($this->allowedLocales as $code) { - $allowedAliases[$this->zendLocale->getAlias($code)] = $code; - } + $languages = (new LanguageBundle())->get(ResolverInterface::DEFAULT_LOCALE)['Languages']; + $countries = (new RegionBundle())->get(ResolverInterface::DEFAULT_LOCALE)['Countries']; + $locales = \ResourceBundle::getLocales(null); $list = []; - foreach (array_keys($locales) as $code) { - if (array_key_exists($code, $allowedAliases)) { - $code = $allowedAliases[$code]; + foreach ($locales as $locale) { + if (!in_array($locale, $this->allowedLocales)) { + continue; } - if (strstr($code, '_')) { - $data = explode('_', $code); - if (!isset($languages[$data[0]]) || !isset($countries[$data[1]])) { - continue; - } - $list[$code] = $languages[$data[0]] . ' (' . $countries[$data[1]] . ')'; + $language = \Locale::getPrimaryLanguage($locale); + $country = \Locale::getRegion($locale); + if (!$languages[$language] || !$countries[$country]) { + continue; } + $list[$locale] = $languages[$language] . ' (' . $countries[$country] . ')'; } asort($list); return $list; diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ListsTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ListsTest.php index c2ad346340b8878ff61b6e137aa50bb946706612..ab782aa71e2e2009f220b6aa0337e7b42f3dee32 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ListsTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ListsTest.php @@ -15,105 +15,70 @@ class ListsTest extends \PHPUnit_Framework_TestCase /** * @var Lists */ - private $lists; + protected $lists; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Locale\ConfigInterface + */ + protected $mockConfig; + + /** + * @var array + */ + protected $expectedTimezones = [ + 'Australia/Darwin', + 'America/Los_Angeles', + 'Europe/Kiev', + 'Asia/Jerusalem', + ]; + + /** + * @var array + */ + protected $expectedCurrencies = [ + 'USD', + 'EUR', + 'UAH', + 'GBP', + ]; + + /** + * @var array + */ + protected $expectedLocales = [ + 'en_US', + 'en_GB', + 'uk_UA', + 'de_DE', + ]; public function setUp() { - $objectManager = new ObjectManager($this); - $this->lists = new Lists( - $objectManager->getObject('Zend_Locale'), - $objectManager->getObject('Magento\Framework\Locale\Config') - ); + $this->mockConfig = $this->getMockBuilder('\Magento\Framework\Locale\ConfigInterface') + ->disableOriginalConstructor() + ->getMock(); + $this->mockConfig->expects($this->any()) + ->method('getAllowedLocales') + ->willReturn($this->expectedLocales); + + $this->lists = new Lists($this->mockConfig); } public function testGetTimezoneList() { - $expected = [ - 'Australia/Darwin' => 'AUS Central Standard Time (Australia/Darwin)', - 'America/Regina' => 'Canada Central Standard Time (America/Regina)', - 'Europe/Kiev' => 'FLE Standard Time (Europe/Kiev)', - 'Africa/Windhoek' => 'Namibia Standard Time (Africa/Windhoek)', - 'Asia/Katmandu' => 'Nepal Standard Time (Asia/Katmandu)', - 'Etc/GMT+2' => 'UTC-02 (Etc/GMT+2)', - 'Pacific/Port_Moresby' => 'West Pacific Standard Time (Pacific/Port_Moresby)', - 'Asia/Yakutsk' => 'Yakutsk Standard Time (Asia/Yakutsk)', - ]; - - $this->assertTrue(array_intersect_assoc($expected, $this->lists->getTimezoneList()) == $expected); + $timezones = array_intersect($this->expectedTimezones, array_keys($this->lists->getTimezoneList())); + $this->assertEquals($this->expectedTimezones, $timezones); } public function testGetCurrencyList() { - $expected = [ - 'XUA' => 'ADB Unit of Account (XUA)', - 'AFA' => 'Afghan Afghani (1927–2002) (AFA)', - 'AZM' => 'Azerbaijani Manat (1993–2006) (AZM)', - 'AZN' => 'Azerbaijani Manat (AZN)', - 'BOB' => 'Bolivian Boliviano (BOB)', - 'CUC' => 'Cuban Convertible Peso (CUC)', - 'CUP' => 'Cuban Peso (CUP)', - 'CYP' => 'Cypriot Pound (CYP)', - 'CZK' => 'Czech Republic Koruna (CZK)', - 'CSK' => 'Czechoslovak Hard Koruna (CSK)', - 'DKK' => 'Danish Krone (DKK)', - 'ZRN' => 'Zairean New Zaire (1993–1998) (ZRN)', - 'ZRZ' => 'Zairean Zaire (1971–1993) (ZRZ)', - 'ZMK' => 'Zambian Kwacha (1968–2012) (ZMK)', - 'ZMW' => 'Zambian Kwacha (ZMW)', - 'ZWD' => 'Zimbabwean Dollar (1980–2008) (ZWD)', - ]; - $this->assertTrue(array_intersect_assoc($expected, $this->lists->getCurrencyList()) == $expected); + $currencies = array_intersect($this->expectedCurrencies, array_keys($this->lists->getCurrencyList())); + $this->assertEquals($this->expectedCurrencies, $currencies); } public function testGetLocaleList() { - $expected = [ - 'aa_DJ' => 'Afar (Djibouti)', - 'ar_ER' => 'Arabic (Eritrea)', - 'ar_TN' => 'Arabic (Tunisia)', - 'bn_BD' => 'Bengali (Bangladesh)', - 'bn_IN' => 'Bengali (India)', - 'byn_ER' => 'Blin (Eritrea)', - 'brx_IN' => 'Bodo (India)', - 'zh_CN' => 'Chinese (China)', - 'zh_HK' => 'Chinese (Hong Kong SAR China)', - 'nl_NL' => 'Dutch (Netherlands)', - 'nl_SX' => 'Dutch (Sint Maarten)', - 'en_BW' => 'English (Botswana)', - 'fr_BJ' => 'French (Benin)', - 'fr_BF' => 'French (Burkina Faso)', - 'ia_FR' => 'Interlingua (France)', - 'ga_IE' => 'Irish (Ireland)', - 'it_IT' => 'Italian (Italy)', - 'lag_TZ' => 'Langi (Tanzania)', - 'lo_LA' => 'Lao (Laos)', - 'lv_LV' => 'Latvian (Latvia)', - 'ln_AO' => 'Lingala (Angola)', - 'nso_ZA' => 'Northern Sotho (South Africa)', - 'pt_TL' => 'Portuguese (Timor-Leste)', - 'ro_MD' => 'Romanian (Moldova)', - 'ro_RO' => 'Romanian (Romania)', - 'rm_CH' => 'Romansh (Switzerland)', - 'rof_TZ' => 'Rombo (Tanzania)', - 'rn_BI' => 'Rundi (Burundi)', - 'ru_UA' => 'Russian (Ukraine)', - 'rwk_TZ' => 'Rwa (Tanzania)', - 'so_ET' => 'Somali (Ethiopia)', - 'es_ES' => 'Spanish (Spain)', - 'es_US' => 'Spanish (United States)', - 'teo_UG' => 'Teso (Uganda)', - 'th_TH' => 'Thai (Thailand)', - 'bo_CN' => 'Tibetan (China)', - 'fy_NL' => 'Western Frisian (Netherlands)', - 'wal_ET' => 'Wolaytta (Ethiopia)', - 'xh_ZA' => 'Xhosa (South Africa)', - 'yav_CM' => 'Yangben (Cameroon)', - 'yo_BJ' => 'Yoruba (Benin)', - 'yo_NG' => 'Yoruba (Nigeria)', - 'dje_NE' => 'Zarma (Niger)', - 'zu_ZA' => 'Zulu (South Africa)', - ]; - - $this->assertTrue(array_intersect_assoc($expected, $this->lists->getLocaleList()) == $expected); + $locales = array_intersect($this->expectedLocales, array_keys($this->lists->getLocaleList())); + $this->assertEquals($this->expectedLocales, $locales); } }