Skip to content

Commit

Permalink
PHP 8.1: Replaced deprecated strftime() with date() (#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Jan 16, 2023
1 parent 23dbb91 commit a7fdf56
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/code/core/Mage/CatalogIndex/Model/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p
if (isset($values[$code]['from']) && isset($values[$code]['to'])) {
if ($values[$code]['from']) {
if (!is_numeric($values[$code]['from'])) {
$_date = date("Y-m-d H:i:s", strtotime($values[$code]['from']));
$_date = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['from']));
$values[$code]['from'] = $_date;
}

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

if ($values[$code]['to']) {
if (!is_numeric($values[$code]['to'])) {
$values[$code]['to'] = date("Y-m-d H:i:s", strtotime($values[$code]['to']));
$values[$code]['to'] = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['to']));
}
$filter[$code]->where("value <= ?", $values[$code]['to']);
}
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Cron/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected function _generateJobs($jobs, $exists)
->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING);

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

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

call_user_func_array($callback, $arguments);

$schedule
->setStatus(Mage_Cron_Model_Schedule::STATUS_SUCCESS)
->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
->setFinishedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT));
} catch (Exception $e) {
$schedule->setStatus($errorStatus)
->setMessages($e->__toString());
Expand All @@ -347,7 +347,7 @@ protected function _getAlwaysJobSchedule($jobCode)
/** @var Mage_Cron_Model_Schedule $schedule */
$schedule = Mage::getModel('cron/schedule')->load($jobCode, 'job_code');
if ($schedule->getId() === null) {
$ts = strftime('%Y-%m-%d %H:%M:00', time());
$ts = date('Y-m-d H:i:00');
$schedule->setJobCode($jobCode)
->setCreatedAt($ts)
->setScheduledAt($ts);
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Cron/Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public function trySchedule($time)
&& $this->matchCronExpression($e[4], $d['wday']);

if ($match) {
$this->setCreatedAt(strftime('%Y-%m-%d %H:%M:%S', time()));
$this->setScheduledAt(strftime('%Y-%m-%d %H:%M', (int)$time));
$this->setCreatedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT));
$this->setScheduledAt(date('Y-m-d H:i:00', (int)$time));
}
return $match;
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Log/Model/Aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private function _date($in, $offset = null)
{
$out = $in;
if (is_numeric($in)) {
$out = date("Y-m-d H:i:s", $in);
$out = date(Varien_Date::DATETIME_PHP_FORMAT, $in);
}
return $out;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Varien/Db/Adapter/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ public function convertDate($date)
if ($date instanceof Zend_Date) {
return $date->toString(self::ISO_DATE_FORMAT);
}
return strftime('%Y-%m-%d', strtotime($date));
return date(Varien_Db_Adapter_Pdo_Mysql::DATE_FORMAT, strtotime($date));
}

public function convertDateTime($datetime)
{
if ($datetime instanceof Zend_Date) {
return $datetime->toString(self::ISO_DATETIME_FORMAT);
}
return strftime('%Y-%m-%d %H:%M:%S', strtotime($datetime));
return date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($datetime));
}

// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
Expand Down

0 comments on commit a7fdf56

Please sign in to comment.