Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
12 changes: 10 additions & 2 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Level;
Expand Down Expand Up @@ -862,8 +863,15 @@ public static function isInstalled($options = [])
if (is_readable($localConfigFile)) {
$localConfig = simplexml_load_file($localConfigFile);
date_default_timezone_set('UTC');
if (($date = $localConfig->global->install->date) && Carbon::parse((string) $date)->getTimestamp()) {
self::$_isInstalled = true;
if ($date = $localConfig->global->install->date) {
try {
if (Carbon::parse((string) $date)->getTimestamp()) {
self::$_isInstalled = true;
}
} catch (InvalidFormatException) {
// Invalid date format, installation not complete
self::$_isInstalled = false;
}
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* AdminNotification Feed model
Expand Down Expand Up @@ -89,7 +90,11 @@ public function checkUpdate()
*/
public function getDate($rssDate)
{
return gmdate(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, Carbon::parse($rssDate)->getTimestamp());
try {
return gmdate(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, Carbon::parse($rssDate)->getTimestamp());
} catch (InvalidFormatException) {
return gmdate(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT);
}
}

/**
Expand Down
9 changes: 7 additions & 2 deletions app/code/core/Mage/Api/Model/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Webservice api session
Expand Down Expand Up @@ -219,8 +220,12 @@ public function isSessionExpired($user)
return true;
}

$timeout = Carbon::parse(Varien_Date::now())->getTimestamp() - Carbon::parse($user->getLogdate())->getTimestamp();
return $timeout > Mage::getStoreConfig('api/config/session_timeout');
try {
$timeout = Carbon::parse(Varien_Date::now())->getTimestamp() - Carbon::parse($user->getLogdate())->getTimestamp();
return $timeout > Mage::getStoreConfig('api/config/session_timeout');
} catch (InvalidFormatException) {
return true;
}
}

/**
Expand Down
16 changes: 13 additions & 3 deletions app/code/core/Mage/CatalogRule/Model/Resource/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Catalog rules resource model
Expand Down Expand Up @@ -180,8 +181,13 @@ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $website

$customerGroupIds = $rule->getCustomerGroupIds();

$fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(Carbon::parse((string) $rule->getFromDate())->getTimestamp());
$toTime = (int) Mage::getModel('core/date')->gmtTimestamp(Carbon::parse((string) $rule->getToDate())->getTimestamp());
try {
$fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(Carbon::parse((string) $rule->getFromDate())->getTimestamp());
$toTime = (int) Mage::getModel('core/date')->gmtTimestamp(Carbon::parse((string) $rule->getToDate())->getTimestamp());
} catch (InvalidFormatException) {
// Invalid date format, skip rule
return;
}
$toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0;

$timestamp = Carbon::now()->getTimestamp();
Expand Down Expand Up @@ -693,7 +699,11 @@ public function getRulesFromProduct($date, $websiteId, $customerGroupId, $produc
{
$adapter = $this->_getReadAdapter();
if (is_string($date)) {
$date = Carbon::parse($date)->getTimestamp();
try {
$date = Carbon::parse($date)->getTimestamp();
} catch (InvalidFormatException) {
return [];
}
}

$select = $adapter->select()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Catalog Rule Product Condition data model
Expand Down Expand Up @@ -102,7 +103,11 @@ protected function _prepareDatetimeValue($value, $object)
return null;
}

$value = Carbon::parse($value)->getTimestamp();
try {
$value = Carbon::parse($value)->getTimestamp();
} catch (InvalidFormatException) {
return null;
}
}

return $value;
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/Core/Block/Html/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* HTML select element block
Expand Down Expand Up @@ -79,7 +80,11 @@ protected function _toHtml()
public function getEscapedValue($index = null)
{
if ($this->getFormat() && $this->getValue()) {
return Carbon::parse($this->getValue())->format($this->getFormat());
try {
return Carbon::parse($this->getValue())->format($this->getFormat());
} catch (InvalidFormatException) {
return htmlspecialchars($this->getValue());
}
}

return htmlspecialchars($this->getValue());
Expand Down
13 changes: 11 additions & 2 deletions app/code/core/Mage/Core/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Date conversion model
Expand Down Expand Up @@ -122,7 +123,11 @@
} elseif (is_numeric($input)) {
$result = $input;
} else {
$result = Carbon::parse($input)->getTimestamp();
try {
$result = Carbon::parse($input)->getTimestamp();
} catch (InvalidFormatException) {
return false;
}
}

if ($result === false) {
Expand Down Expand Up @@ -151,7 +156,11 @@
} elseif (is_numeric($input)) {
$result = $input;
} else {
$result = Carbon::parse($input)->getTimestamp();
try {
$result = Carbon::parse($input)->getTimestamp();
} catch (InvalidFormatException) {
return false;

Check failure on line 162 in app/code/core/Mage/Core/Model/Date.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze

Method Mage_Core_Model_Date::timestamp() should return int but returns false.

Check failure on line 162 in app/code/core/Mage/Core/Model/Date.php

View workflow job for this annotation

GitHub Actions / PHPStan / Analyze

Method Mage_Core_Model_Date::timestamp() should return int but returns false.
}
}

$date = Mage::app()->getLocale()->date($result);
Expand Down
15 changes: 12 additions & 3 deletions app/code/core/Mage/Core/Model/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Locale model
Expand Down Expand Up @@ -632,7 +633,11 @@ public function storeTimeStamp($store = null)
@date_default_timezone_set($timezone);
$date = date(Varien_Date::DATETIME_PHP_FORMAT);
@date_default_timezone_set($currentTimezone);
return Carbon::parse($date)->getTimestamp();
try {
return Carbon::parse($date)->getTimestamp();
} catch (InvalidFormatException) {
return Carbon::now()->getTimestamp();
}
}

/**
Expand Down Expand Up @@ -886,8 +891,12 @@ public function isStoreDateInInterval($store, $dateFrom = null, $dateTo = null)
}

$storeTimeStamp = $this->storeTimeStamp($store);
$fromTimeStamp = Carbon::parse((string) $dateFrom)->getTimestamp();
$toTimeStamp = Carbon::parse((string) $dateTo)->getTimestamp();
try {
$fromTimeStamp = Carbon::parse((string) $dateFrom)->getTimestamp();
$toTimeStamp = Carbon::parse((string) $dateTo)->getTimestamp();
} catch (InvalidFormatException) {
return false;
}
Comment on lines +899 to +904
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

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

The try-catch block catches the InvalidFormatException and returns false, but the variables $fromTimeStamp and $toTimeStamp will not be defined if the exception is thrown. This means that line 907 will reference undefined variables when is_empty_date returns false. The code should either initialize these variables before the try-catch or check their existence before using them on lines 907-908.

Copilot uses AI. Check for mistakes.
if ($dateTo) {
// fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59
$toTimeStamp += 86400;
Expand Down
8 changes: 7 additions & 1 deletion app/code/core/Mage/Cron/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Crontab observer
Expand Down Expand Up @@ -243,8 +244,13 @@ public function cleanup()

$now = Carbon::now()->getTimestamp();
foreach ($history->getIterator() as $record) {
try {
$executedTimestamp = Carbon::parse($record->getExecutedAt())->getTimestamp();
} catch (InvalidFormatException) {
$executedTimestamp = null;
}
if (empty($record->getExecutedAt())
|| (Carbon::parse($record->getExecutedAt())->getTimestamp() < $now - $historyLifetimes[$record->getStatus()])
|| ($executedTimestamp && $executedTimestamp < $now - $historyLifetimes[$record->getStatus()])
) {
$record->delete();
}
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/Cron/Model/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Crontab schedule model
Expand Down Expand Up @@ -92,7 +93,11 @@ public function trySchedule($time)
}

if (!is_numeric($time)) {
$time = Carbon::parse($time)->getTimestamp();
try {
$time = Carbon::parse($time)->getTimestamp();
} catch (InvalidFormatException) {
$time = false;
}
}

if ($time === false) {
Expand Down
28 changes: 18 additions & 10 deletions app/code/core/Mage/Eav/Model/Attribute/Data/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* EAV Entity Attribute Date Data Model
Expand Down Expand Up @@ -63,16 +64,17 @@ public function validateValue($value)

//range validation
$validateRules = $attribute->getValidateRules();
if ((!empty($validateRules['date_range_min']) && (Carbon::parse($value)->getTimestamp() < $validateRules['date_range_min']))
|| (!empty($validateRules['date_range_max']) && (Carbon::parse($value)->getTimestamp() > $validateRules['date_range_max']))
) {
$format = 'd/m/Y';
if (!empty($validateRules['date_range_min']) && !empty($validateRules['date_range_max'])) {
$errors[] = Mage::helper('customer')->__(
'Please enter a valid date between %s and %s at %s.',
Carbon::createFromTimestamp($validateRules['date_range_min'])->format($format),
Carbon::createFromTimestamp($validateRules['date_range_max'])->format($format),
$label,
try {
if ((!empty($validateRules['date_range_min']) && (Carbon::parse($value)->getTimestamp() < $validateRules['date_range_min']))
|| (!empty($validateRules['date_range_max']) && (Carbon::parse($value)->getTimestamp() > $validateRules['date_range_max']))
) {
$format = 'd/m/Y';
if (!empty($validateRules['date_range_min']) && !empty($validateRules['date_range_max'])) {
$errors[] = Mage::helper('customer')->__(
'Please enter a valid date between %s and %s at %s.',
Carbon::createFromTimestamp($validateRules['date_range_min'])->format($format),
Carbon::createFromTimestamp($validateRules['date_range_max'])->format($format),
$label,
);
} elseif (!empty($validateRules['date_range_min'])) {
$errors[] = Mage::helper('customer')->__(
Expand All @@ -88,6 +90,12 @@ public function validateValue($value)
);
}
}
} catch (InvalidFormatException) {
$errors[] = Mage::helper('customer')->__(
'Please enter a valid date at %s.',
$label,
);
}

if (count($errors) == 0) {
return true;
Expand Down
7 changes: 6 additions & 1 deletion app/code/core/Mage/Install/Model/Installer/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* Config installer
Expand Down Expand Up @@ -169,7 +170,11 @@ protected function _checkUrl($url, $secure = false)

public function replaceTmpInstallDate($date = null)
{
$stamp = Carbon::parse((string) $date)->getTimestamp();
try {
$stamp = Carbon::parse((string) $date)->getTimestamp();
} catch (InvalidFormatException) {
$stamp = null;
}
$localXml = file_get_contents($this->_localConfigFile);
$localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, Carbon::createFromTimestamp($stamp ? $stamp : Carbon::now()->getTimestamp())->format('r'), $localXml);
file_put_contents($this->_localConfigFile, $localXml);
Expand Down
8 changes: 7 additions & 1 deletion app/code/core/Mage/Paypal/Model/Cert.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* PayPal specific model for certificate based authentication
Expand Down Expand Up @@ -54,7 +55,12 @@ public function getCertPath()
Mage::throwException(Mage::helper('paypal')->__('PayPal certificate does not exist.'));
}

$certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), Carbon::parse($this->getUpdatedAt())->getTimestamp());
try {
$timestamp = Carbon::parse($this->getUpdatedAt())->getTimestamp();
} catch (InvalidFormatException) {
$timestamp = Carbon::now()->getTimestamp();
}
$certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), $timestamp);
$certFile = $this->_getBaseDir() . DS . $certFileName;

if (!file_exists($certFile)) {
Expand Down
11 changes: 8 additions & 3 deletions app/code/core/Mage/Paypal/Model/Express.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;

/**
* @package Mage_Paypal
Expand Down Expand Up @@ -662,9 +663,13 @@ public function canCapture()
return false;
}

$dateCompass = Carbon::parse($orderTransaction->getCreatedAt())->addDays($orderValidPeriod);
$currentDate = Carbon::now();
if ($currentDate > $dateCompass) {
try {
$dateCompass = Carbon::parse($orderTransaction->getCreatedAt())->addDays($orderValidPeriod);
$currentDate = Carbon::now();
if ($currentDate > $dateCompass) {
return false;
}
} catch (InvalidFormatException) {
return false;
}
}
Expand Down
Loading
Loading