Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 9fde991

Browse files
MAGETWO-65722: [GitHub][PR] Type hint for \DateTimeInterface instead of \DateTime magento/magento2#7174
2 parents bdd51e8 + f7691bb commit 9fde991

File tree

25 files changed

+307
-91
lines changed

25 files changed

+307
-91
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function getHtml()
131131
public function getEscapedValue($index = null)
132132
{
133133
$value = $this->getValue($index);
134-
if ($value instanceof \DateTime) {
134+
if ($value instanceof \DateTimeInterface) {
135135
return $this->dateTimeFormatter->formatObject(
136136
$value,
137137
$this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function getEscapedValue($index = null)
147147
{
148148
if ($this->getColumn()->getFilterTime()) {
149149
$value = $this->getValue($index);
150-
if ($value instanceof \DateTime) {
150+
if ($value instanceof \DateTimeInterface) {
151151
return $this->_localeDate->formatDateTime($value);
152152
}
153153
return $value;

app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function _afterDelete(\Magento\Framework\Model\AbstractModel $rule)
153153
* Get catalog rules product price for specific date, website and
154154
* customer group
155155
*
156-
* @param \DateTime $date
156+
* @param \DateTimeInterface $date
157157
* @param int $wId
158158
* @param int $gId
159159
* @param int $pId
@@ -173,13 +173,13 @@ public function getRulePrice($date, $wId, $gId, $pId)
173173
* Retrieve product prices by catalog rule for specific date, website and customer group
174174
* Collect data with product Id => price pairs
175175
*
176-
* @param \DateTime $date
176+
* @param \DateTimeInterface $date
177177
* @param int $websiteId
178178
* @param int $customerGroupId
179179
* @param array $productIds
180180
* @return array
181181
*/
182-
public function getRulePrices(\DateTime $date, $websiteId, $customerGroupId, $productIds)
182+
public function getRulePrices(\DateTimeInterface $date, $websiteId, $customerGroupId, $productIds)
183183
{
184184
$connection = $this->getConnection();
185185
$select = $connection->select()

app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function beforeSave($object)
6565
* string format used from input fields (all date input fields need apply locale settings)
6666
* int value can be declared in code (this meen whot we use valid date)
6767
*
68-
* @param string|int|\DateTime $date
68+
* @param string|int|\DateTimeInterface $date
6969
* @return string
7070
*/
7171
public function formatDate($date)
@@ -76,7 +76,7 @@ public function formatDate($date)
7676
// unix timestamp given - simply instantiate date object
7777
if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) {
7878
$date = (new \DateTime())->setTimestamp($date);
79-
} elseif (!($date instanceof \DateTime)) {
79+
} elseif (!($date instanceof \DateTimeInterface)) {
8080
// normalized format expecting Y-m-d[ H:i:s] - time is optional
8181
$date = new \DateTime($date);
8282
}

app/code/Magento/Indexer/Model/Mview/View/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function getUpdated()
140140
/**
141141
* Set state updated time
142142
*
143-
* @param string|int|\DateTime $updated
143+
* @param string|int|\DateTimeInterface $updated
144144
* @return $this
145145
*/
146146
public function setUpdated($updated)

app/code/Magento/Reports/Model/ResourceModel/Report/AbstractReport.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ protected function _clearTableByDateRange(
188188
* @param string $table
189189
* @param string $column
190190
* @param string $whereColumn
191-
* @param null|string|\DateTime $from
192-
* @param null|string|\DateTime $to
191+
* @param null|string|\DateTimeInterface $from
192+
* @param null|string|\DateTimeInterface $to
193193
* @param [][] $additionalWhere
194194
* @param string $alias
195195
* @return \Magento\Framework\DB\Select
@@ -440,12 +440,12 @@ protected function _getTZOffsetTransitions($timezone, $from = null, $to = null)
440440
$tzTransitions = [];
441441
try {
442442
if (!empty($from)) {
443-
$from = $from instanceof \DateTime
443+
$from = $from instanceof \DateTimeInterface
444444
? $from->getTimestamp()
445445
: (new \DateTime($from))->getTimestamp();
446446
}
447447

448-
$to = $to instanceof \DateTime
448+
$to = $to instanceof \DateTimeInterface
449449
? $to
450450
: new \DateTime($to);
451451
$nextPeriod = $this->getConnection()->formatDate(

app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class Collection extends \Magento\Framework\Data\Collection
1919
/**
2020
* From value
2121
*
22-
* @var string
22+
* @var \DateTime
2323
*/
2424
protected $_from;
2525

2626
/**
2727
* To value
2828
*
29-
* @var string
29+
* @var \DateTime
3030
*/
3131
protected $_to;
3232

@@ -114,14 +114,14 @@ public function setPeriod($period)
114114
* Set interval
115115
* @codeCoverageIgnore
116116
*
117-
* @param \DateTime $fromDate
118-
* @param \DateTime $toDate
117+
* @param \DateTimeInterface $fromDate
118+
* @param \DateTimeInterface $toDate
119119
* @return $this
120120
*/
121-
public function setInterval($fromDate, $toDate)
121+
public function setInterval(\DateTimeInterface $fromDate, \DateTimeInterface $toDate)
122122
{
123-
$this->_from = $fromDate;
124-
$this->_to = $toDate;
123+
$this->_from = new \DateTime($fromDate->format('Y-m-d'), $fromDate->getTimezone());
124+
$this->_to = new \DateTime($toDate->format('Y-m-d'), $toDate->getTimezone());
125125

126126
return $this;
127127
}

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/CollectionTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public function testGetStoreIds()
7979

8080
/**
8181
* @param string $period
82-
* @param \DateTime $fromDate
83-
* @param \DateTime $toDate
82+
* @param \DateTimeInterface $fromDate
83+
* @param \DateTimeInterface $toDate
8484
* @param int $size
8585
* @dataProvider intervalsDataProvider
8686
* @return void
@@ -105,8 +105,8 @@ public function testGetPageSize()
105105

106106
/**
107107
* @param string $period
108-
* @param \DateTime $fromDate
109-
* @param \DateTime $toDate
108+
* @param \DateTimeInterface $fromDate
109+
* @param \DateTimeInterface $toDate
110110
* @param int $size
111111
* @dataProvider intervalsDataProvider
112112
* @return void

app/code/Magento/Rule/Model/ResourceModel/AbstractResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
5757
private function resolveDate(\Magento\Framework\Model\AbstractModel $object, $dateIdentifier)
5858
{
5959
$date = $object->getData($dateIdentifier);
60-
if ($date instanceof \DateTime) {
60+
if ($date instanceof \DateTimeInterface) {
6161
$object->setData($dateIdentifier, $date->format('Y-m-d H:i:s'));
6262
} elseif (!is_string($date) || empty($date)) {
6363
$object->setData($dateIdentifier, null);

app/code/Magento/Sales/Block/Adminhtml/Order/View/Tab/History.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function getItemComment(array $item)
207207
*
208208
* @param string $label
209209
* @param bool $notified
210-
* @param \DateTime $created
210+
* @param \DateTimeInterface $created
211211
* @param string $comment
212212
* @return array
213213
*/

0 commit comments

Comments
 (0)