Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace strftime with date #2934

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
sreichel marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$this->setScheduledAt(date('Y-m-d H:i:00', (int)$time));
$this->setScheduledAt(date('Y-m-d H:i', (int)$time));

Copy link
Collaborator Author

@luigifab luigifab Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is strange to put a value without seconds for me, even if this works.

php > echo date('Y-m-d H:i');
2023-01-14 20:49
php > echo date('Y-m-d H:i:00');
2023-01-14 20:49:00

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just compared before/after and this is the only change i found in output. (y, its strange ;) )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you agree to keep current behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way both will save the value with 00 seconds

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an opinion on this so as you all prefer :-)

}
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