Skip to content

Commit a7fdf56

Browse files
authored
PHP 8.1: Replaced deprecated strftime() with date() (#2934)
1 parent 23dbb91 commit a7fdf56

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

app/code/core/Mage/CatalogIndex/Model/Indexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p
717717
if (isset($values[$code]['from']) && isset($values[$code]['to'])) {
718718
if ($values[$code]['from']) {
719719
if (!is_numeric($values[$code]['from'])) {
720-
$_date = date("Y-m-d H:i:s", strtotime($values[$code]['from']));
720+
$_date = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['from']));
721721
$values[$code]['from'] = $_date;
722722
}
723723

@@ -726,7 +726,7 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p
726726

727727
if ($values[$code]['to']) {
728728
if (!is_numeric($values[$code]['to'])) {
729-
$values[$code]['to'] = date("Y-m-d H:i:s", strtotime($values[$code]['to']));
729+
$values[$code]['to'] = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['to']));
730730
}
731731
$filter[$code]->where("value <= ?", $values[$code]['to']);
732732
}

app/code/core/Mage/Cron/Model/Observer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected function _generateJobs($jobs, $exists)
183183
->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING);
184184

185185
for ($time = $now; $time < $timeAhead; $time += 60) {
186-
$ts = strftime('%Y-%m-%d %H:%M:00', $time);
186+
$ts = date('Y-m-d H:i:00', $time);
187187
if (!empty($exists[$jobCode . '/' . $ts])) {
188188
// already scheduled
189189
continue;
@@ -319,14 +319,14 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false)
319319
}
320320

321321
$schedule
322-
->setExecutedAt(strftime('%Y-%m-%d %H:%M:%S', time()))
322+
->setExecutedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT))
323323
->save();
324324

325325
call_user_func_array($callback, $arguments);
326326

327327
$schedule
328328
->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS)
329-
->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
329+
->setFinishedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT));
330330
} catch (Exception $e) {
331331
$schedule->setStatus($errorStatus)
332332
->setMessages($e->__toString());
@@ -347,7 +347,7 @@ protected function _getAlwaysJobSchedule($jobCode)
347347
/** @var Mage_Cron_Model_Schedule $schedule */
348348
$schedule = Mage::getModel('cron/schedule')->load($jobCode, 'job_code');
349349
if ($schedule->getId() === null) {
350-
$ts = strftime('%Y-%m-%d %H:%M:00', time());
350+
$ts = date('Y-m-d H:i:00');
351351
$schedule->setJobCode($jobCode)
352352
->setCreatedAt($ts)
353353
->setScheduledAt($ts);

app/code/core/Mage/Cron/Model/Schedule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ public function trySchedule($time)
107107
&& $this->matchCronExpression($e[4], $d['wday']);
108108

109109
if ($match) {
110-
$this->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
111-
$this->setScheduledAt(strftime('%Y-%m-%d %H:%M', (int)$time));
110+
$this->setCreatedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT));
111+
$this->setScheduledAt(date('Y-m-d H:i:00', (int)$time));
112112
}
113113
return $match;
114114
}

app/code/core/Mage/Log/Model/Aggregation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private function _date($in, $offset = null)
167167
{
168168
$out = $in;
169169
if (is_numeric($in)) {
170-
$out = date("Y-m-d H:i:s", $in);
170+
$out = date(Varien_Date::DATETIME_PHP_FORMAT, $in);
171171
}
172172
return $out;
173173
}

lib/Varien/Db/Adapter/Mysqli.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ public function convertDate($date)
115115
if ($date instanceof Zend_Date) {
116116
return $date->toString(self::ISO_DATE_FORMAT);
117117
}
118-
return strftime('%Y-%m-%d', strtotime($date));
118+
return date(Varien_Db_Adapter_Pdo_Mysql::DATE_FORMAT, strtotime($date));
119119
}
120120

121121
public function convertDateTime($datetime)
122122
{
123123
if ($datetime instanceof Zend_Date) {
124124
return $datetime->toString(self::ISO_DATETIME_FORMAT);
125125
}
126-
return strftime('%Y-%m-%d %H:%M:%S', strtotime($datetime));
126+
return date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($datetime));
127127
}
128128

129129
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps

0 commit comments

Comments
 (0)