Skip to content

Commit 71f2261

Browse files
author
He, Joan(johe)
committed
Merge pull request #161 from magento-extensibility/MAGETWO-43960-custom-timezone-merged
[Extensibility] [Timezone] Magetwo 43960 custom timezone merged
2 parents a65e016 + 9aeba1b commit 71f2261

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

app/code/Magento/Email/Model/ResourceModel/Template.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,14 @@
1414
*/
1515
class Template extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1616
{
17-
/**
18-
* @var \Magento\Framework\Stdlib\DateTime
19-
*/
20-
protected $dateTime;
21-
2217
/**
2318
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
24-
* @param \Magento\Framework\Stdlib\DateTime $dateTime
2519
* @param string $connectionName
2620
*/
2721
public function __construct(
2822
\Magento\Framework\Model\ResourceModel\Db\Context $context,
29-
\Magento\Framework\Stdlib\DateTime $dateTime,
3023
$connectionName = null
3124
) {
32-
$this->dateTime = $dateTime;
3325
parent::__construct($context, $connectionName);
3426
}
3527

app/code/Magento/Reports/Controller/Adminhtml/Report/AbstractReport.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212
namespace Magento\Reports\Controller\Adminhtml\Report;
1313

14-
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
14+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1515

1616
abstract class AbstractReport extends \Magento\Backend\App\Action
1717
{
@@ -26,26 +26,26 @@ abstract class AbstractReport extends \Magento\Backend\App\Action
2626
protected $_dateFilter;
2727

2828
/**
29-
* @var DateTimeFormatterInterface
29+
* @var TimezoneInterface
3030
*/
31-
protected $dateTimeFormatter;
31+
protected $timezone;
3232

3333
/**
3434
* @param \Magento\Backend\App\Action\Context $context
3535
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
3636
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
37-
* @param DateTimeFormatterInterface $dateTimeFormatter
37+
* @param TimezoneInterface $timezone
3838
*/
3939
public function __construct(
4040
\Magento\Backend\App\Action\Context $context,
4141
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
4242
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
43-
DateTimeFormatterInterface $dateTimeFormatter
43+
TimezoneInterface $timezone
4444
) {
4545
parent::__construct($context);
4646
$this->_fileFactory = $fileFactory;
4747
$this->_dateFilter = $dateFilter;
48-
$this->dateTimeFormatter = $dateTimeFormatter;
48+
$this->timezone = $timezone;
4949
}
5050

5151
/**
@@ -134,14 +134,10 @@ protected function _showLastExecutionTime($flagCode, $refreshCode)
134134
$flag = $this->_objectManager->create('Magento\Reports\Model\Flag')->setReportFlagCode($flagCode)->loadSelf();
135135
$updatedAt = 'undefined';
136136
if ($flag->hasData()) {
137-
$updatedAt = $this->dateTimeFormatter->formatObject(
138-
$this->_objectManager->get(
139-
'Magento\Framework\Stdlib\DateTime\TimezoneInterface'
140-
)->scopeDate(
141-
0,
142-
$flag->getLastUpdate(),
143-
true
144-
)
137+
$updatedAt = $this->timezone->formatDate(
138+
$flag->getLastUpdate(),
139+
\IntlDateFormatter::MEDIUM,
140+
true
145141
);
146142
}
147143

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null)
235235
}
236236

237237
/**
238-
* @param \DateTimeInterface $date
238+
* @param string|\DateTimeInterface $date
239239
* @param int $dateType
240240
* @param int $timeType
241241
* @param null $locale
@@ -244,13 +244,17 @@ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null)
244244
* @return string
245245
*/
246246
public function formatDateTime(
247-
\DateTimeInterface $date,
247+
$date,
248248
$dateType = \IntlDateFormatter::SHORT,
249249
$timeType = \IntlDateFormatter::SHORT,
250250
$locale = null,
251251
$timezone = null,
252252
$pattern = null
253253
) {
254+
if (!($date instanceof \DateTime)) {
255+
$date = new \DateTime($date);
256+
}
257+
254258
if ($timezone === null) {
255259
if ($date->getTimezone() == null || $date->getTimezone()->getName() == 'UTC'
256260
|| $date->getTimezone()->getName() == '+00:00'

lib/internal/Magento/Framework/Stdlib/DateTime/TimezoneInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function getConfigTimezone($scopeType = null, $scopeCode = null);
121121
public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null);
122122

123123
/**
124-
* @param \DateTimeInterface $date
124+
* @param string|\DateTimeInterface $date
125125
* @param int $dateType
126126
* @param int $timeType
127127
* @param null $locale
@@ -130,7 +130,7 @@ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null);
130130
* @return string
131131
*/
132132
public function formatDateTime(
133-
\DateTimeInterface $date,
133+
$date,
134134
$dateType = \IntlDateFormatter::SHORT,
135135
$timeType = \IntlDateFormatter::SHORT,
136136
$locale = null,

0 commit comments

Comments
 (0)