Skip to content

Commit a87cf5b

Browse files
author
He, Joan(johe)
committed
Merge pull request #174 from magento-extensibility/time-zone-pr
[Extensibility] MAGETWO-45241, MAGETWO-45240, MAGETWO-45251, MAGETWO-45237, MAGETWO-45274
2 parents 50c33e5 + 624469b commit a87cf5b

File tree

19 files changed

+356
-59
lines changed

19 files changed

+356
-59
lines changed

app/code/Magento/AdminNotification/Model/Feed.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ public function checkUpdate()
141141

142142
if ($feedXml && $feedXml->channel && $feedXml->channel->item) {
143143
foreach ($feedXml->channel->item as $item) {
144-
if ($installDate <= strtotime((string)$item->pubDate)) {
144+
$itemPublicationDate = strtotime((string)$item->pubDate);
145+
if ($installDate <= $itemPublicationDate) {
145146
$feedData[] = [
146147
'severity' => (int)$item->severity,
147-
'date_added' => $this->getDate((string)$item->pubDate),
148+
'date_added' => date('Y-m-d H:i:s', $itemPublicationDate),
148149
'title' => (string)$item->title,
149150
'description' => (string)$item->description,
150151
'url' => (string)$item->link,
@@ -161,17 +162,6 @@ public function checkUpdate()
161162
return $this;
162163
}
163164

164-
/**
165-
* Retrieve DB date from RSS date
166-
*
167-
* @param string $rssDate
168-
* @return string YYYY-MM-DD YY:HH:SS
169-
*/
170-
public function getDate($rssDate)
171-
{
172-
return gmdate('Y-m-d H:i:s', strtotime($rssDate));
173-
}
174-
175165
/**
176166
* Retrieve Update Frequency
177167
*

app/code/Magento/AdminNotification/Observer/PredispathAdminActionControllerObserver.php renamed to app/code/Magento/AdminNotification/Observer/PredispatchAdminActionControllerObserver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @author Magento Core Team <core@magentocommerce.com>
1414
*/
15-
class PredispathAdminActionControllerObserver implements ObserverInterface
15+
class PredispatchAdminActionControllerObserver implements ObserverInterface
1616
{
1717
/**
1818
* @var \Magento\AdminNotification\Model\FeedFactory

app/code/Magento/AdminNotification/etc/adminhtml/events.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
99
<event name="controller_action_predispatch">
10-
<observer name="adminnotification" instance="Magento\AdminNotification\Observer\PredispathAdminActionControllerObserver" />
10+
<observer name="adminnotification" instance="Magento\AdminNotification\Observer\PredispatchAdminActionControllerObserver" />
1111
</event>
1212
</config>

app/code/Magento/Backend/Block/Dashboard/Graph.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public function getChartUrl($directUrl = true)
387387
*/
388388
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
389389
if ($_label != '') {
390-
$period = new \DateTime($_label);
390+
$period = new \DateTime($_label, new \DateTimeZone($timezoneLocal));
391391
switch ($this->getDataHelper()->getParam('period')) {
392392
case '24h':
393393
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ public function setValue($value)
199199
*/
200200
protected function _convertDate($date)
201201
{
202-
$adminTimeZone = new \DateTimeZone(
203-
$this->_localeDate->getConfigTimezone()
204-
);
202+
$timezone = $this->getColumn()->getTimezone() !== false ? $this->_localeDate->getConfigTimezone() : 'UTC';
203+
$adminTimeZone = new \DateTimeZone($timezone);
205204
$formatter = new \IntlDateFormatter(
206205
$this->localeResolver->getLocale(),
207206
\IntlDateFormatter::SHORT,

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ protected function _convertDate($date)
6868
{
6969
if ($this->getColumn()->getFilterTime()) {
7070
try {
71-
$adminTimeZone = new \DateTimeZone(
72-
$this->_localeDate->getConfigTimezone()
73-
);
71+
$timezone = $this->getColumn()->getTimezone() !== false
72+
? $this->_localeDate->getConfigTimezone() : 'UTC';
73+
$adminTimeZone = new \DateTimeZone($timezone);
7474
$simpleRes = new \DateTime($date, $adminTimeZone);
7575
$simpleRes->setTimezone(new \DateTimeZone('UTC'));
7676
return $simpleRes;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter;
8+
9+
/**
10+
* Class DateTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
11+
*
12+
*/
13+
class DateTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/** @var \Magento\Backend\Block\Widget\Grid\Column\Filter\Date */
16+
protected $model;
17+
18+
/** @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject */
19+
protected $mathRandomMock;
20+
21+
/** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
22+
protected $localeResolverMock;
23+
24+
/** @var \Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface|\PHPUnit_Framework_MockObject_MockObject */
25+
protected $dateTimeFormatterMock;
26+
27+
/** @var \Magento\Backend\Block\Widget\Grid\Column|\PHPUnit_Framework_MockObject_MockObject */
28+
protected $columnMock;
29+
30+
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject */
31+
protected $localeDateMock;
32+
33+
protected function setUp()
34+
{
35+
$this->mathRandomMock = $this->getMockBuilder('Magento\Framework\Math\Random')
36+
->disableOriginalConstructor()
37+
->setMethods(['getUniqueHash'])
38+
->getMock();
39+
40+
$this->localeResolverMock = $this->getMockBuilder('Magento\Framework\Locale\ResolverInterface')
41+
->disableOriginalConstructor()
42+
->setMethods([])
43+
->getMock();
44+
45+
$this->dateTimeFormatterMock = $this
46+
->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface')
47+
->disableOriginalConstructor()
48+
->setMethods([])
49+
->getMock();
50+
51+
$this->columnMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Grid\Column')
52+
->disableOriginalConstructor()
53+
->setMethods(['getTimezone', 'getHtmlId', 'getId'])
54+
->getMock();
55+
56+
$this->localeDateMock = $this->getMockBuilder('\Magento\Framework\Stdlib\DateTime\TimezoneInterface')
57+
->disableOriginalConstructor()
58+
->setMethods([])
59+
->getMock();
60+
61+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
62+
$this->model = $objectManagerHelper->getObject(
63+
'Magento\Backend\Block\Widget\Grid\Column\Filter\Date',
64+
[
65+
'mathRandom' => $this->mathRandomMock,
66+
'localeResolver' => $this->localeResolverMock,
67+
'dateTimeFormatter' => $this->dateTimeFormatterMock,
68+
'localeDate' => $this->localeDateMock
69+
]
70+
);
71+
$this->model->setColumn($this->columnMock);
72+
}
73+
74+
public function testGetHtmlSuccessfulTimestamp()
75+
{
76+
$uniqueHash = 'H@$H';
77+
$id = 3;
78+
$format = 'mm/dd/yyyy';
79+
$yesterday = new \DateTime();
80+
$yesterday->add(\DateInterval::createFromDateString('yesterday'));
81+
$tomorrow = new \DateTime();
82+
$tomorrow->add(\DateInterval::createFromDateString('tomorrow'));
83+
$value = [
84+
'locale' => 'en_US',
85+
'from' => $yesterday->getTimestamp(),
86+
'to' => $tomorrow->getTimestamp()
87+
];
88+
89+
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
90+
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);
91+
$this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format);
92+
$this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false);
93+
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US');
94+
$this->model->setColumn($this->columnMock);
95+
$this->model->setValue($value);
96+
97+
$output = $this->model->getHtml();
98+
$this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output);
99+
$this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output);
100+
}
101+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Block\Widget\Grid\Column\Filter;
8+
9+
/**
10+
* Class DateTimeTest to test Magento\Backend\Block\Widget\Grid\Column\Filter\Date
11+
*
12+
*/
13+
class DatetimeTest extends \PHPUnit_Framework_TestCase
14+
{
15+
/** @var \Magento\Backend\Block\Widget\Grid\Column\Filter\Datetime */
16+
protected $model;
17+
18+
/** @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject */
19+
protected $mathRandomMock;
20+
21+
/** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject */
22+
protected $localeResolverMock;
23+
24+
/** @var \Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface|\PHPUnit_Framework_MockObject_MockObject */
25+
protected $dateTimeFormatterMock;
26+
27+
/** @var \Magento\Backend\Block\Widget\Grid\Column|\PHPUnit_Framework_MockObject_MockObject */
28+
protected $columnMock;
29+
30+
/** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject */
31+
protected $localeDateMock;
32+
33+
protected function setUp()
34+
{
35+
$this->mathRandomMock = $this->getMockBuilder('Magento\Framework\Math\Random')
36+
->disableOriginalConstructor()
37+
->setMethods(['getUniqueHash'])
38+
->getMock();
39+
40+
$this->localeResolverMock = $this->getMockBuilder('Magento\Framework\Locale\ResolverInterface')
41+
->disableOriginalConstructor()
42+
->setMethods([])
43+
->getMock();
44+
45+
$this->dateTimeFormatterMock = $this
46+
->getMockBuilder('Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface')
47+
->disableOriginalConstructor()
48+
->setMethods([])
49+
->getMock();
50+
51+
$this->columnMock = $this->getMockBuilder('Magento\Backend\Block\Widget\Grid\Column')
52+
->disableOriginalConstructor()
53+
->setMethods(['getTimezone', 'getHtmlId', 'getId'])
54+
->getMock();
55+
56+
$this->localeDateMock = $this->getMockBuilder('\Magento\Framework\Stdlib\DateTime\TimezoneInterface')
57+
->disableOriginalConstructor()
58+
->setMethods([])
59+
->getMock();
60+
61+
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
62+
$this->model = $objectManagerHelper->getObject(
63+
'Magento\Backend\Block\Widget\Grid\Column\Filter\Datetime',
64+
[
65+
'mathRandom' => $this->mathRandomMock,
66+
'localeResolver' => $this->localeResolverMock,
67+
'dateTimeFormatter' => $this->dateTimeFormatterMock,
68+
'localeDate' => $this->localeDateMock
69+
]
70+
);
71+
$this->model->setColumn($this->columnMock);
72+
}
73+
74+
public function testGetHtmlSuccessfulTimestamp()
75+
{
76+
$uniqueHash = 'H@$H';
77+
$id = 3;
78+
$format = 'mm/dd/yyyy';
79+
$yesterday = new \DateTime();
80+
$yesterday->add(\DateInterval::createFromDateString('yesterday'));
81+
$tomorrow = new \DateTime();
82+
$tomorrow->add(\DateInterval::createFromDateString('tomorrow'));
83+
$value = [
84+
'locale' => 'en_US',
85+
'from' => $yesterday->getTimestamp(),
86+
'to' => $tomorrow->getTimestamp()
87+
];
88+
89+
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
90+
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);
91+
$this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format);
92+
$this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false);
93+
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US');
94+
$this->model->setColumn($this->columnMock);
95+
$this->model->setValue($value);
96+
97+
$output = $this->model->getHtml();
98+
$this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output);
99+
$this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output);
100+
}
101+
}

app/code/Magento/Backend/view/adminhtml/layout/adminhtml_system_design_grid_block.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<argument name="align" xsi:type="string">left</argument>
5252
<argument name="width" xsi:type="string">100px</argument>
5353
<argument name="type" xsi:type="string">date</argument>
54+
<argument name="timezone" xsi:type="boolean">false</argument>
5455
<argument name="index" xsi:type="string">date_from</argument>
5556
</arguments>
5657
</block>
@@ -60,6 +61,7 @@
6061
<argument name="align" xsi:type="string">left</argument>
6162
<argument name="width" xsi:type="string">100px</argument>
6263
<argument name="type" xsi:type="string">date</argument>
64+
<argument name="timezone" xsi:type="boolean">false</argument>
6365
<argument name="index" xsi:type="string">date_to</argument>
6466
</arguments>
6567
</block>

app/code/Magento/Integration/Model/Oauth/Consumer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ protected function _construct()
8787
*/
8888
public function beforeSave()
8989
{
90-
$this->setUpdatedAt(time());
9190
$this->validate();
9291
parent::beforeSave();
9392
return $this;

app/code/Magento/User/Model/User.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@ class User extends AbstractModel implements StorageInterface, UserInterface
9393
*/
9494
protected $_encryptor;
9595

96-
/**
97-
* @var \Magento\Framework\Stdlib\DateTime
98-
*/
99-
protected $dateTime;
100-
10196
/**
10297
* @var \Magento\Framework\Mail\Template\TransportBuilder
10398
*/
@@ -122,7 +117,6 @@ class User extends AbstractModel implements StorageInterface, UserInterface
122117
* @param \Magento\Authorization\Model\RoleFactory $roleFactory
123118
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
124119
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
125-
* @param \Magento\Framework\Stdlib\DateTime $dateTime
126120
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
127121
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
128122
* @param UserValidationRules $validationRules
@@ -139,15 +133,13 @@ public function __construct(
139133
\Magento\Authorization\Model\RoleFactory $roleFactory,
140134
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
141135
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
142-
\Magento\Framework\Stdlib\DateTime $dateTime,
143136
\Magento\Store\Model\StoreManagerInterface $storeManager,
144137
UserValidationRules $validationRules,
145138
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
146139
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
147140
array $data = []
148141
) {
149142
$this->_encryptor = $encryptor;
150-
$this->dateTime = $dateTime;
151143
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
152144
$this->_userData = $userData;
153145
$this->_config = $config;
@@ -216,7 +208,6 @@ public function __wakeup()
216208
public function beforeSave()
217209
{
218210
$data = [
219-
'modified' => (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT),
220211
'extra' => serialize($this->getExtra()),
221212
];
222213

app/code/Magento/User/Test/Unit/Model/UserTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ public function testBeforeSave()
372372
$this->eventManagerMock->expects($this->any())->method('dispatch');
373373
$this->model->setIsActive(1);
374374
$actualData = $this->model->beforeSave()->getData();
375-
$this->assertArrayHasKey('modified', $actualData);
376375
$this->assertArrayHasKey('extra', $actualData);
377376
$this->assertArrayHasKey('password', $actualData);
378377
$this->assertArrayHasKey('is_active', $actualData);

0 commit comments

Comments
 (0)