diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
index dab2777d40d..3dea07e321a 100644
--- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
+++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* Order create model
*
@@ -1705,7 +1707,7 @@ protected function _getNewCustomerEmail($customer)
$host = $this->getSession()
->getStore()
->getConfig(Mage_Customer_Model_Customer::XML_PATH_DEFAULT_EMAIL_DOMAIN);
- $account = $customer->getIncrementId() ? $customer->getIncrementId() : time();
+ $account = $customer->getIncrementId() ? $customer->getIncrementId() : Carbon::now()->getTimestamp();
$email = $account . '@' . $host;
$account = $this->getData('account');
$account['email'] = $email;
diff --git a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php
index 1860eb868e2..dd06c6b758b 100644
--- a/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php
+++ b/app/code/core/Mage/Adminhtml/Model/Sales/Order/Random.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* Create random order
*
@@ -148,7 +150,7 @@ public function render()
protected function _getRandomDate()
{
$timestamp = mktime(random_int(0, 23), random_int(0, 59), 0, random_int(1, 11), random_int(1, 28), random_int(2006, 2007));
- return date(Varien_Date::DATETIME_PHP_FORMAT, $timestamp);
+ return Carbon::createFromTimestamp($timestamp)->format(Varien_Date::DATETIME_PHP_FORMAT);
}
public function save()
diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php
index f53c061f2c0..bf996fb949a 100644
--- a/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php
+++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Source/Date/Short.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Adminhtml
* @deprecated
@@ -17,10 +19,10 @@ public function toOptionArray()
{
return [
['label' => '', 'value' => ''],
- ['label' => sprintf('MM/DD/YY (%s)', date('m/d/y')), 'value' => '%m/%d/%y'],
- ['label' => sprintf('MM/DD/YYYY (%s)', date('m/d/Y')), 'value' => '%m/%d/%Y'],
- ['label' => sprintf('DD/MM/YY (%s)', date('d/m/y')), 'value' => '%d/%m/%y'],
- ['label' => sprintf('DD/MM/YYYY (%s)', date('d/m/Y')), 'value' => '%d/%m/%Y'],
+ ['label' => sprintf('MM/DD/YY (%s)', Carbon::now()->format('m/d/y')), 'value' => '%m/%d/%y'],
+ ['label' => sprintf('MM/DD/YYYY (%s)', Carbon::now()->format('m/d/Y')), 'value' => '%m/%d/%Y'],
+ ['label' => sprintf('DD/MM/YY (%s)', Carbon::now()->format('d/m/y')), 'value' => '%d/%m/%y'],
+ ['label' => sprintf('DD/MM/YYYY (%s)', Carbon::now()->format('d/m/Y')), 'value' => '%d/%m/%Y'],
];
}
}
diff --git a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
index 0bc84a186b6..243c6a32185 100644
--- a/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/CustomerController.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* Customer admin controller
*
@@ -334,7 +336,7 @@ public function saveAction()
// Force new customer confirmation
if ($isNewCustomer) {
$customer->setPassword($data['account']['password']);
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$customer->setForceConfirmed(true);
if ($customer->getPassword() === 'auto') {
$sendPassToEmail = true;
@@ -886,7 +888,7 @@ public function viewfileAction()
->setHeader('Pragma', 'public', true)
->setHeader('Content-type', $contentType, true)
->setHeader('Content-Length', $contentLength)
- ->setHeader('Last-Modified', date('r', (int) $contentModify))
+ ->setHeader('Last-Modified', Carbon::createFromTimestamp((int) $contentModify)->format('r'))
->clearBody();
$this->getResponse()->sendHeaders();
diff --git a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php
index 621b31c4f53..db6339cfba9 100644
--- a/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* Adminhtml sales order shipment controller
*
@@ -758,7 +760,7 @@ protected function _createPdfPageFromImageString($imageString)
imageinterlace($image, false);
$tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_'
- . uniqid((string) mt_rand()) . time() . '.png';
+ . uniqid((string) mt_rand()) . Carbon::now()->getTimestamp() . '.png';
imagepng($image, $tmpFileName);
$pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName);
$page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php
index 54c7858b8b6..fbe245c0f81 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/Config/System/StorageController.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* Adminhtml account controller
*
@@ -56,7 +58,7 @@ public function synchronizeAction()
$flag = $this->_getSyncFlag();
if ($flag && $flag->getState() == Mage_Core_Model_File_Storage_Flag::STATE_RUNNING
&& $flag->getLastUpdate()
- && time() <= (strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL)
+ && Carbon::now()->getTimestamp() <= (Carbon::parse($flag->getLastUpdate())->getTimestamp() + Mage_Core_Model_File_Storage_Flag::FLAG_TTL)
) {
return;
}
@@ -103,7 +105,7 @@ public function statusAction()
break;
case Mage_Core_Model_File_Storage_Flag::STATE_RUNNING:
if (!$flag->getLastUpdate()
- || time() <= (strtotime($flag->getLastUpdate()) + Mage_Core_Model_File_Storage_Flag::FLAG_TTL)
+ || Carbon::now()->getTimestamp() <= (Carbon::parse($flag->getLastUpdate())->getTimestamp() + Mage_Core_Model_File_Storage_Flag::FLAG_TTL)
) {
$flagData = $flag->getFlagData();
if (is_array($flagData)
diff --git a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php
index 2ffa7fea7f2..fdb73dbd5a7 100644
--- a/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php
+++ b/app/code/core/Mage/Adminhtml/controllers/System/StoreController.php
@@ -7,6 +7,8 @@
* @package Mage_Adminhtml
*/
+use Carbon\Carbon;
+
/**
* Store controller
*
@@ -480,7 +482,7 @@ protected function _backupDatabase($failPath, $arguments = [])
try {
$backupDb = Mage::getModel('backup/db');
$backup = Mage::getModel('backup/backup')
- ->setTime(time())
+ ->setTime(Carbon::now()->getTimestamp())
->setType('db')
->setPath(Mage::getBaseDir('var') . DS . 'backups');
diff --git a/app/code/core/Mage/Api/Model/Session.php b/app/code/core/Mage/Api/Model/Session.php
index dc28f1c459c..420deb0682f 100644
--- a/app/code/core/Mage/Api/Model/Session.php
+++ b/app/code/core/Mage/Api/Model/Session.php
@@ -7,6 +7,8 @@
* @package Mage_Api
*/
+use Carbon\Carbon;
+
/**
* Webservice api session
*
@@ -29,7 +31,7 @@ class Mage_Api_Model_Session extends Mage_Core_Model_Session_Abstract
*/
public function start($sessionName = null)
{
- $this->_currentSessId = md5(time() . uniqid('', true) . $sessionName);
+ $this->_currentSessId = md5(Carbon::now()->getTimestamp() . uniqid('', true) . $sessionName);
$this->sessionIds[] = $this->getSessionId();
return $this;
}
@@ -217,7 +219,7 @@ public function isSessionExpired($user)
return true;
}
- $timeout = strtotime(Varien_Date::now()) - strtotime($user->getLogdate());
+ $timeout = Carbon::parse(Varien_Date::now())->getTimestamp() - Carbon::parse($user->getLogdate())->getTimestamp();
return $timeout > Mage::getStoreConfig('api/config/session_timeout');
}
diff --git a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php
index c2596ff1eff..a8ecb150bf6 100644
--- a/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php
+++ b/app/code/core/Mage/Authorizenet/Model/Directpost/Request.php
@@ -7,6 +7,8 @@
* @package Mage_Authorizenet
*/
+use Carbon\Carbon;
+
/**
* Authorize.net request model for DirectPost model.
*
@@ -155,7 +157,7 @@ public function setDataFromOrder(Mage_Sales_Model_Order $order, Mage_Authorizene
*/
public function signRequestData()
{
- $fpTimestamp = (string) time();
+ $fpTimestamp = (string) Carbon::now()->getTimestamp();
$signatureKey = $this->_getSignatureKey();
if (!empty($signatureKey)) {
$hash = $this->_generateSha2RequestSign(
diff --git a/app/code/core/Mage/Captcha/Model/Observer.php b/app/code/core/Mage/Captcha/Model/Observer.php
index e23d68a0a24..d271eebb0d3 100644
--- a/app/code/core/Mage/Captcha/Model/Observer.php
+++ b/app/code/core/Mage/Captcha/Model/Observer.php
@@ -7,6 +7,8 @@
* @package Mage_Captcha
*/
+use Carbon\Carbon;
+
/**
* Captcha Observer
*
@@ -141,6 +143,7 @@ public function checkRegisterCheckout($observer)
*
* @param Varien_Event_Observer $observer
* @return $this
+ * @throws Mage_Core_Exception
*/
public function checkUserLoginBackend($observer)
{
@@ -234,11 +237,13 @@ public function deleteOldAttempts()
* Delete Expired Captcha Images
*
* @return $this
+ * @throws Mage_Core_Exception
*/
public function deleteExpiredImages()
{
foreach (Mage::app()->getWebsites(true) as $website) {
- $expire = time() - Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore()) * 60;
+ $timeout = (int) Mage::helper('captcha')->getConfigNode('timeout', $website->getDefaultStore());
+ $expire = Carbon::now()->subMinutes($timeout)->getTimestamp();
$imageDirectory = Mage::helper('captcha')->getImgDir($website);
foreach (new DirectoryIterator($imageDirectory) as $file) {
if ($file->isFile() && pathinfo($file->getFilename(), PATHINFO_EXTENSION) == 'png') {
@@ -320,13 +325,13 @@ public function checkSendfriendSend($observer)
Mage::getSingleton('catalog/session')->addError(Mage::helper('captcha')->__('Incorrect CAPTCHA.'));
$controller->setFlag('', Mage_Core_Controller_Varien_Action::FLAG_NO_DISPATCH, true);
Mage::getSingleton('catalog/session')->setFormData($request->getPost());
- $id = (int) $request->getParam('id');
+ $sendId = (int) $request->getParam('id');
$catId = $request->getParam('cat_id');
if ($catId !== null) {
- $id .= '/cat_id/' . (int) $catId;
+ $sendId .= '/cat_id/' . (int) $catId;
}
- $controller->getResponse()->setRedirect(Mage::getUrl('*/*/send/id/' . $id));
+ $controller->getResponse()->setRedirect(Mage::getUrl('*/*/send/id/' . $sendId));
}
}
diff --git a/app/code/core/Mage/Captcha/Model/Resource/Log.php b/app/code/core/Mage/Captcha/Model/Resource/Log.php
index 0b465d571d7..52fa27ac33c 100644
--- a/app/code/core/Mage/Captcha/Model/Resource/Log.php
+++ b/app/code/core/Mage/Captcha/Model/Resource/Log.php
@@ -7,6 +7,8 @@
* @package Mage_Captcha
*/
+use Carbon\Carbon;
+
/**
* Log Attempts resource
*
@@ -135,7 +137,7 @@ public function deleteOldAttempts()
{
$this->_getWriteAdapter()->delete(
$this->getMainTable(),
- ['updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, time() - 60 * 30)],
+ ['updated_at < ?' => Mage::getSingleton('core/date')->gmtDate(null, Carbon::now()->subMinutes(30)->getTimestamp())],
);
}
}
diff --git a/app/code/core/Mage/Captcha/Model/Zend.php b/app/code/core/Mage/Captcha/Model/Zend.php
index 02323709dbd..a777cd6de87 100644
--- a/app/code/core/Mage/Captcha/Model/Zend.php
+++ b/app/code/core/Mage/Captcha/Model/Zend.php
@@ -7,6 +7,8 @@
* @package Mage_Captcha
*/
+use Carbon\Carbon;
+
/**
* Implementation of Zend_Captcha
*
@@ -457,7 +459,7 @@ public function getWord()
return null;
}
- return time() < $sessionData['expires'] ? $sessionData['data'] : null;
+ return Carbon::now()->getTimestamp() < $sessionData['expires'] ? $sessionData['data'] : null;
}
/**
@@ -470,7 +472,7 @@ protected function _setWord($word)
{
$this->getSession()->setData(
$this->_getFormIdKey(self::SESSION_WORD),
- ['data' => $word, 'expires' => time() + $this->getTimeout()],
+ ['data' => $word, 'expires' => Carbon::now()->getTimestamp() + $this->getTimeout()],
);
$this->_word = $word;
return $this;
diff --git a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php
index 8a967094f5e..d373214379d 100644
--- a/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php
+++ b/app/code/core/Mage/Catalog/Model/Product/Option/Type/Date.php
@@ -7,6 +7,9 @@
* @package Mage_Catalog
*/
+use Carbon\Carbon;
+use Carbon\Exceptions\InvalidFormatException;
+
/**
* Catalog product option date type
*
@@ -84,6 +87,8 @@ public function validateUserValue($values)
*
* @return mixed Prepared option value
* @throws Mage_Core_Exception
+ * @throws Zend_Date_Exception
+ * @throws Zend_Locale_Exception
*/
public function prepareForCart()
{
@@ -106,7 +111,7 @@ public function prepareForCart()
$timestamp += mktime(0, 0, 0, $value['month'], $value['day'], $value['year']);
}
} else {
- $timestamp += mktime(0, 0, 0, date('m'), date('d'), date('Y'));
+ $timestamp += mktime(0, 0, 0, Carbon::now()->format('m'), Carbon::now()->format('d'), Carbon::now()->format('Y'));
}
if ($this->_timeExists()) {
@@ -140,6 +145,9 @@ public function prepareForCart()
*
* @param string $optionValue Prepared for cart option value
* @return string
+ * @throws Mage_Core_Exception
+ * @throws Zend_Date_Exception
+ * @throws Zend_Locale_Exception
*/
public function getFormattedOptionValue($optionValue)
{
@@ -155,7 +163,7 @@ public function getFormattedOptionValue($optionValue)
->date($optionValue, Varien_Date::DATETIME_INTERNAL_FORMAT, null, false)->toString($format);
} elseif ($this->getOption()->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_TIME) {
$date = new Zend_Date($optionValue);
- $result = date($this->is24hTimeFormat() ? 'H:i' : 'h:i a', $date->getTimestamp());
+ $result = Carbon::createFromTimestamp($date->getTimestamp())->format($this->is24hTimeFormat() ? 'H:i' : 'h:i a');
} else {
$result = $optionValue;
}
@@ -194,10 +202,16 @@ public function getEditableOptionValue($optionValue)
* @param string $optionValue
* @param array $productOptionValues Values for product option
* @return null|string
+ * @throws Zend_Date_Exception
*/
public function parseOptionValue($optionValue, $productOptionValues)
{
- $timestamp = strtotime($optionValue);
+ try {
+ $timestamp = Carbon::parse($optionValue)->getTimestamp();
+ } catch (InvalidFormatException) {
+ $timestamp = false;
+ }
+
if ($timestamp === false || $timestamp == -1) {
return null;
}
@@ -251,7 +265,7 @@ public function is24hTimeFormat()
/**
* Year range start
*
- * @return mixed
+ * @return string
*/
public function getYearStart()
{
@@ -259,14 +273,14 @@ public function getYearStart()
if (isset($_range[0]) && !empty($_range[0])) {
return $_range[0];
} else {
- return date('Y');
+ return Carbon::now()->format('Y');
}
}
/**
* Year range end
*
- * @return mixed
+ * @return string
*/
public function getYearEnd()
{
@@ -274,7 +288,7 @@ public function getYearEnd()
if (isset($_range[1]) && !empty($_range[1])) {
return $_range[1];
} else {
- return date('Y');
+ return Carbon::now()->format('Y');
}
}
@@ -299,6 +313,7 @@ protected function _setInternalInRequest($internalValue)
* Does option have date?
*
* @return bool
+ * @throws Mage_Core_Exception
*/
protected function _dateExists()
{
@@ -312,6 +327,7 @@ protected function _dateExists()
* Does option have time?
*
* @return bool
+ * @throws Mage_Core_Exception
*/
protected function _timeExists()
{
diff --git a/app/code/core/Mage/CatalogIndex/Model/Indexer.php b/app/code/core/Mage/CatalogIndex/Model/Indexer.php
index f77ae9e3890..79ebf52bbfc 100644
--- a/app/code/core/Mage/CatalogIndex/Model/Indexer.php
+++ b/app/code/core/Mage/CatalogIndex/Model/Indexer.php
@@ -7,6 +7,8 @@
* @package Mage_CatalogIndex
*/
+use Carbon\Carbon;
+
/**
* CatalogIndex Index operation model
*
@@ -721,7 +723,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(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['from']));
+ $_date = Carbon::parse($values[$code]['from'])->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT);
$values[$code]['from'] = $_date;
}
@@ -730,7 +732,7 @@ public function buildEntityFilter($attributes, $values, &$filteredAttributes, $p
if ($values[$code]['to']) {
if (!is_numeric($values[$code]['to'])) {
- $values[$code]['to'] = date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($values[$code]['to']));
+ $values[$code]['to'] = Carbon::parse($values[$code]['to'])->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT);
}
$filter[$code]->where('value <= ?', $values[$code]['to']);
diff --git a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php
index f13d9147bf2..a52600d35f7 100644
--- a/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php
+++ b/app/code/core/Mage/CatalogIndex/Model/Resource/Aggregation.php
@@ -7,6 +7,8 @@
* @package Mage_CatalogIndex
*/
+use Carbon\Carbon;
+
/**
* Resource Model CatalogIndex Aggregation
*
@@ -101,7 +103,7 @@ public function saveCacheData($data, $key, $tags, $storeId)
$this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), [
'store_id' => $storeId,
- 'created_at' => $this->formatDate(time()),
+ 'created_at' => $this->formatDate(Carbon::now()->getTimestamp()),
'key' => $key,
'data' => $data,
], ['created_at', 'data']);
diff --git a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php
index 37878435cb5..a6113d55219 100644
--- a/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php
+++ b/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php
@@ -7,6 +7,8 @@
* @package Mage_CatalogRule
*/
+use Carbon\Carbon;
+
/**
* Catalog rules resource model
*
@@ -178,11 +180,11 @@ public function insertRuleData(Mage_CatalogRule_Model_Rule $rule, array $website
$customerGroupIds = $rule->getCustomerGroupIds();
- $fromTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getFromDate()));
- $toTime = (int) Mage::getModel('core/date')->gmtTimestamp(strtotime((string) $rule->getToDate()));
+ $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());
$toTime = $toTime ? ($toTime + self::SECONDS_IN_DAY - 1) : 0;
- $timestamp = time();
+ $timestamp = Carbon::now()->getTimestamp();
if ($fromTime > $timestamp
|| ($toTime && $toTime < $timestamp)
) {
@@ -691,7 +693,7 @@ public function getRulesFromProduct($date, $websiteId, $customerGroupId, $produc
{
$adapter = $this->_getReadAdapter();
if (is_string($date)) {
- $date = strtotime($date);
+ $date = Carbon::parse($date)->getTimestamp();
}
$select = $adapter->select()
diff --git a/app/code/core/Mage/CatalogRule/Model/Rule.php b/app/code/core/Mage/CatalogRule/Model/Rule.php
index a3f4766cb62..0d6179d93c7 100644
--- a/app/code/core/Mage/CatalogRule/Model/Rule.php
+++ b/app/code/core/Mage/CatalogRule/Model/Rule.php
@@ -7,6 +7,8 @@
* @package Mage_CatalogRule
*/
+use Carbon\Carbon;
+
/**
* Catalog Rule data model
*
@@ -363,7 +365,7 @@ public function calcProductPriceRule(Mage_Catalog_Model_Product $product, $price
}
$dateTs = Mage::app()->getLocale()->date()->getTimestamp();
- $cacheKey = date('Y-m-d', $dateTs) . "|$websiteId|$customerGroupId|$productId|$price";
+ $cacheKey = Carbon::createFromTimestamp($dateTs)->format('Y-m-d') . "|$websiteId|$customerGroupId|$productId|$price";
if (!array_key_exists($cacheKey, self::$_priceRulesData)) {
$rulesData = $this->_getResource()->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId);
diff --git a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php
index 79814ecd14e..c78f30b5ff2 100644
--- a/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php
+++ b/app/code/core/Mage/CatalogRule/Model/Rule/Condition/Product.php
@@ -7,6 +7,8 @@
* @package Mage_CatalogRule
*/
+use Carbon\Carbon;
+
/**
* Catalog Rule Product Condition data model
*
@@ -100,7 +102,7 @@ protected function _prepareDatetimeValue($value, $object)
return null;
}
- $value = strtotime($value);
+ $value = Carbon::parse($value)->getTimestamp();
}
return $value;
diff --git a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php
index 910c6fe527d..e7b455f5ee7 100644
--- a/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php
+++ b/app/code/core/Mage/Checkout/Model/Api/Resource/Customer.php
@@ -7,6 +7,8 @@
* @package Mage_Checkout
*/
+use Carbon\Carbon;
+
/**
* Checkout api resource for Customer
*
@@ -132,7 +134,7 @@ protected function _prepareNewCustomerQuote(Mage_Sales_Model_Quote $quote)
Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
$customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$quote->setCustomer($customer)
->setCustomerId(true);
$quote->setPasswordHash('');
diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php
index 56899e24b99..fda7d1c8c7e 100644
--- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php
+++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php
@@ -7,6 +7,8 @@
* @package Mage_Checkout
*/
+use Carbon\Carbon;
+
/**
* One page checkout processing model
*
@@ -727,7 +729,7 @@ protected function _prepareNewCustomerQuote()
Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);
$customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$quote->setCustomer($customer)
->setCustomerId(true);
$quote->setPasswordHash('');
diff --git a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
index a0e1b12eea8..4decac0e736 100644
--- a/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
+++ b/app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
@@ -7,6 +7,8 @@
* @package Mage_Cms
*/
+use Carbon\Carbon;
+
/**
* Wysiwyg Images model
*
@@ -348,7 +350,7 @@ public function getThumbnailUrl($filePath, $checkFile = false)
if (str_starts_with($filePath, $mediaRootDir)) {
$thumbSuffix = self::THUMBS_DIRECTORY_NAME . DS . substr($filePath, strlen($mediaRootDir));
if (!$checkFile || is_readable($this->getHelper()->getStorageRoot() . $thumbSuffix)) {
- $randomIndex = '?rand=' . time();
+ $randomIndex = '?rand=' . Carbon::now()->getTimestamp();
$thumbUrl = $this->getHelper()->getBaseUrl() . Mage_Cms_Model_Wysiwyg_Config::IMAGE_DIRECTORY
. DS . $thumbSuffix;
return str_replace('\\', '/', $thumbUrl) . $randomIndex;
diff --git a/app/code/core/Mage/Core/Block/Html/Date.php b/app/code/core/Mage/Core/Block/Html/Date.php
index e6f896c178e..a92040b8267 100644
--- a/app/code/core/Mage/Core/Block/Html/Date.php
+++ b/app/code/core/Mage/Core/Block/Html/Date.php
@@ -7,6 +7,8 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
+
/**
* HTML select element block
*
@@ -77,7 +79,7 @@ protected function _toHtml()
public function getEscapedValue($index = null)
{
if ($this->getFormat() && $this->getValue()) {
- return date($this->getFormat(), strtotime($this->getValue()));
+ return Carbon::parse($this->getValue())->format($this->getFormat());
}
return htmlspecialchars($this->getValue());
diff --git a/app/code/core/Mage/Core/Controller/Front/Action.php b/app/code/core/Mage/Core/Controller/Front/Action.php
index df758323326..a930d8ff357 100644
--- a/app/code/core/Mage/Core/Controller/Front/Action.php
+++ b/app/code/core/Mage/Core/Controller/Front/Action.php
@@ -7,6 +7,8 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
+
/**
* Base front controller
*
@@ -125,7 +127,7 @@ protected function _prepareDownloadResponse(
->setHeader('Content-type', $contentType, true)
->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength)
->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"')
- ->setHeader('Last-Modified', date('r'));
+ ->setHeader('Last-Modified', Carbon::now()->format('r'));
if (!is_null($content)) {
if ($isFile) {
diff --git a/app/code/core/Mage/Core/Controller/Varien/Action.php b/app/code/core/Mage/Core/Controller/Varien/Action.php
index d601a853f90..2cf84260c9e 100644
--- a/app/code/core/Mage/Core/Controller/Varien/Action.php
+++ b/app/code/core/Mage/Core/Controller/Varien/Action.php
@@ -7,6 +7,8 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
+
/**
* Custom Zend_Controller_Action class (formally)
*
@@ -1112,7 +1114,7 @@ protected function _prepareDownloadResponse(
->setHeader('Content-type', $contentType, true)
->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength, true)
->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)
- ->setHeader('Last-Modified', date('r'), true);
+ ->setHeader('Last-Modified', Carbon::now()->format('r'), true);
if (!is_null($content)) {
if ($isFile) {
diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php
index be1e632543e..48874a81ec9 100644
--- a/app/code/core/Mage/Core/Helper/Data.php
+++ b/app/code/core/Mage/Core/Helper/Data.php
@@ -7,6 +7,9 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
+use Carbon\Exceptions\InvalidFormatException;
+
/**
* Core data helper
*
@@ -199,9 +202,10 @@ public function formatTimezoneDate(
} elseif (is_int($date)) {
$date = $locale->date($date, null, null, $useTimezone);
} elseif (!$date instanceof Zend_Date) {
- if (($time = strtotime($date)) !== false) {
+ try {
+ $time = Carbon::parse($date)->getTimestamp();
$date = $locale->date($time, null, null, $useTimezone);
- } else {
+ } catch (InvalidFormatException) {
return '';
}
}
@@ -226,11 +230,11 @@ public function formatTime($time = null, $format = Mage_Core_Model_Locale::FORMA
$locale = Mage::app()->getLocale();
if (is_null($time)) {
- $date = $locale->date(time());
+ $date = $locale->date(Carbon::now()->getTimestamp());
} elseif ($time instanceof Zend_Date) {
$date = $time;
} else {
- $date = $locale->date(strtotime($time));
+ $date = $locale->date(Carbon::parse($time)->getTimestamp());
}
if ($showDate) {
diff --git a/app/code/core/Mage/Core/Model/Cookie.php b/app/code/core/Mage/Core/Model/Cookie.php
index c38b89ee4fd..7ef37137c0a 100644
--- a/app/code/core/Mage/Core/Model/Cookie.php
+++ b/app/code/core/Mage/Core/Model/Cookie.php
@@ -7,6 +7,7 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
use Mage_Adminhtml_Model_System_Config_Source_Cookie_Samesite as CookieSameSite;
/**
@@ -235,7 +236,7 @@ public function set($name, $value, $period = null, $path = null, $domain = null,
if ($period == 0) {
$expire = 0;
} else {
- $expire = time() + $period;
+ $expire = Carbon::now()->getTimestamp() + $period;
}
if (is_null($path)) {
diff --git a/app/code/core/Mage/Core/Model/Date.php b/app/code/core/Mage/Core/Model/Date.php
index bd7fd9342e2..61a15fffc82 100644
--- a/app/code/core/Mage/Core/Model/Date.php
+++ b/app/code/core/Mage/Core/Model/Date.php
@@ -7,6 +7,8 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
+
/**
* Date conversion model
*
@@ -58,7 +60,7 @@ public function calculateOffset($timezone = null)
}
if ($result === true) {
- $offset = (int) date('Z');
+ $offset = (int) Carbon::now()->format('Z');
}
if (!is_null($timezone)) {
@@ -87,7 +89,7 @@ public function gmtDate($format = null, $input = null)
return false;
}
- return date($format, (int) $date);
+ return Carbon::createFromTimestamp((int) $date)->format($format);
}
/**
@@ -104,7 +106,7 @@ public function date($format = null, $input = null)
$format = Varien_Date::DATETIME_PHP_FORMAT;
}
- return date($format, $this->timestamp($input));
+ return Carbon::createFromTimestamp($this->timestamp($input))->format($format);
}
/**
@@ -120,7 +122,7 @@ public function gmtTimestamp($input = null)
} elseif (is_numeric($input)) {
$result = $input;
} else {
- $result = strtotime($input);
+ $result = Carbon::parse($input)->getTimestamp();
}
if ($result === false) {
@@ -149,7 +151,7 @@ public function timestamp($input = null)
} elseif (is_numeric($input)) {
$result = $input;
} else {
- $result = strtotime($input);
+ $result = Carbon::parse($input)->getTimestamp();
}
$date = Mage::app()->getLocale()->date($result);
diff --git a/app/code/core/Mage/Core/Model/Locale.php b/app/code/core/Mage/Core/Model/Locale.php
index 15935c81a69..940ffae7bd5 100644
--- a/app/code/core/Mage/Core/Model/Locale.php
+++ b/app/code/core/Mage/Core/Model/Locale.php
@@ -7,6 +7,8 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
+
/**
* Locale model
*
@@ -630,7 +632,7 @@ public function storeTimeStamp($store = null)
@date_default_timezone_set($timezone);
$date = date(Varien_Date::DATETIME_PHP_FORMAT);
@date_default_timezone_set($currentTimezone);
- return strtotime($date);
+ return Carbon::parse($date)->getTimestamp();
}
/**
@@ -884,8 +886,8 @@ public function isStoreDateInInterval($store, $dateFrom = null, $dateTo = null)
}
$storeTimeStamp = $this->storeTimeStamp($store);
- $fromTimeStamp = strtotime((string) $dateFrom);
- $toTimeStamp = strtotime((string) $dateTo);
+ $fromTimeStamp = Carbon::parse((string) $dateFrom)->getTimestamp();
+ $toTimeStamp = Carbon::parse((string) $dateTo)->getTimestamp();
if ($dateTo) {
// fix date YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:59
$toTimeStamp += 86400;
diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
index 8363b61c4ba..20c79febd2b 100644
--- a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
+++ b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
@@ -7,6 +7,7 @@
* @package Mage_Core
*/
+use Carbon\Carbon;
use Mage_Adminhtml_Model_System_Config_Source_Cookie_Samesite as CookieSamesite;
/**
@@ -507,7 +508,7 @@ public function validate()
// Refresh expire timestamp
if ($this->useValidateSessionExpire() || $this->useValidateSessionPasswordTimestamp()) {
- $this->setValidatorSessionRenewTimestamp(time());
+ $this->setValidatorSessionRenewTimestamp(Carbon::now()->getTimestamp());
$_SESSION[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_LIFETIME] = $this->getCookie()->getLifetime();
}
}
@@ -575,7 +576,7 @@ protected function _validate()
&& isset($sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP])
&& isset($sessionData[self::VALIDATOR_SESSION_LIFETIME])
&& ((int) $sessionData[self::VALIDATOR_SESSION_RENEW_TIMESTAMP] + (int) $sessionData[self::VALIDATOR_SESSION_LIFETIME])
- < time()
+ < Carbon::now()->getTimestamp()
) {
return false;
}
diff --git a/app/code/core/Mage/Cron/Model/Observer.php b/app/code/core/Mage/Cron/Model/Observer.php
index 6c8491dcdef..180766325cb 100644
--- a/app/code/core/Mage/Cron/Model/Observer.php
+++ b/app/code/core/Mage/Cron/Model/Observer.php
@@ -7,6 +7,8 @@
* @package Mage_Cron
*/
+use Carbon\Carbon;
+
/**
* Crontab observer
*
@@ -40,6 +42,9 @@ class Mage_Cron_Model_Observer
* Cleanup tasks schedule
*
* @param Varien_Event_Observer $observer
+ * @throws Mage_Core_Exception
+ * @throws Throwable
+ * @throws Zend_Cache_Exception
*/
public function dispatch($observer)
{
@@ -69,6 +74,8 @@ public function dispatch($observer)
* Process cron queue for tasks marked as always
*
* @param Varien_Event_Observer $observer
+ * @throws Mage_Core_Exception
+ * @throws Throwable
*/
public function dispatchAlways($observer)
{
@@ -89,6 +96,8 @@ public function dispatchAlways($observer)
/**
* @return Mage_Cron_Model_Resource_Schedule_Collection
+ * @throws Mage_Core_Exception
+ * @throws Zend_Cache_Exception
*/
public function getPendingSchedules()
{
@@ -106,6 +115,9 @@ public function getPendingSchedules()
* Generate cron schedule
*
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Throwable
+ * @throws Zend_Cache_Exception
*/
public function generate()
{
@@ -113,7 +125,7 @@ public function generate()
* check if schedule generation is needed
*/
$lastRun = Mage::app()->loadCache(self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT);
- if ($lastRun > time() - Mage::getStoreConfig(self::XML_PATH_SCHEDULE_GENERATE_EVERY) * 60) {
+ if ($lastRun > Carbon::now()->subMinutes(Mage::getStoreConfigAsInt(self::XML_PATH_SCHEDULE_GENERATE_EVERY))->getTimestamp()) {
return $this;
}
@@ -142,7 +154,7 @@ public function generate()
/**
* save time schedules generation was ran with no expiration
*/
- Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null);
+ Mage::app()->saveCache(Carbon::now()->getTimestamp(), self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null);
return $this;
}
@@ -153,6 +165,8 @@ public function generate()
* @param SimpleXMLElement $jobs
* @param array $exists
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Throwable
*/
protected function _generateJobs($jobs, $exists)
{
@@ -173,15 +187,15 @@ protected function _generateJobs($jobs, $exists)
continue;
}
- $now = time();
+ $now = Carbon::now()->getTimestamp();
$timeAhead = $now + $scheduleAheadFor;
$schedule->setJobCode($jobCode)
->setCronExpr($cronExpr)
->setStatus(Mage_Cron_Model_Schedule::STATUS_PENDING);
for ($time = $now; $time < $timeAhead; $time += 60) {
- $ts = date('Y-m-d H:i:00', $time);
- if (!empty($exists[$jobCode . '/' . $ts])) {
+ $timestamp = Carbon::createFromTimestamp($time)->format('Y-m-d H:i:00');
+ if (!empty($exists[$jobCode . '/' . $timestamp])) {
// already scheduled
continue;
}
@@ -202,12 +216,14 @@ protected function _generateJobs($jobs, $exists)
* Clean up the history of tasks
*
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Zend_Cache_Exception
*/
public function cleanup()
{
// check if history cleanup is needed
$lastCleanup = Mage::app()->loadCache(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT);
- if ($lastCleanup > time() - Mage::getStoreConfig(self::XML_PATH_HISTORY_CLEANUP_EVERY) * 60) {
+ if ($lastCleanup > Carbon::now()->subMinutes(Mage::getStoreConfigAsInt(self::XML_PATH_HISTORY_CLEANUP_EVERY))->getTimestamp()) {
return $this;
}
@@ -225,17 +241,17 @@ public function cleanup()
Mage_Cron_Model_Schedule::STATUS_ERROR => Mage::getStoreConfig(self::XML_PATH_HISTORY_FAILURE) * 60,
];
- $now = time();
+ $now = Carbon::now()->getTimestamp();
foreach ($history->getIterator() as $record) {
if (empty($record->getExecutedAt())
- || (strtotime($record->getExecutedAt()) < $now - $historyLifetimes[$record->getStatus()])
+ || (Carbon::parse($record->getExecutedAt())->getTimestamp() < $now - $historyLifetimes[$record->getStatus()])
) {
$record->delete();
}
}
// save time history cleanup was ran with no expiration
- Mage::app()->saveCache(time(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null);
+ Mage::app()->saveCache(Carbon::now()->getTimestamp(), self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null);
return $this;
}
@@ -246,6 +262,8 @@ public function cleanup()
* @param string $jobCode
* @param SimpleXMLElement $jobConfig
* @return $this|void
+ * @throws Mage_Core_Exception
+ * @throws Throwable
*/
protected function _processAlwaysTask($jobCode, $jobConfig)
{
@@ -273,14 +291,15 @@ protected function _processAlwaysTask($jobCode, $jobConfig)
* @param SimpleXMLElement $jobConfig
* @param bool $isAlways
* @return $this|void
+ * @throws Throwable
*/
protected function _processJob($schedule, $jobConfig, $isAlways = false)
{
$runConfig = $jobConfig->run;
if (!$isAlways) {
$scheduleLifetime = Mage::getStoreConfig(self::XML_PATH_SCHEDULE_LIFETIME) * 60;
- $now = time();
- $time = strtotime($schedule->getScheduledAt());
+ $now = Carbon::now()->getTimestamp();
+ $time = Carbon::parse($schedule->getScheduledAt())->getTimestamp();
if ($time > $now) {
return;
}
@@ -354,16 +373,18 @@ protected function _processJob($schedule, $jobConfig, $isAlways = false)
*
* @param string $jobCode
* @return Mage_Cron_Model_Schedule
+ * @throws Mage_Core_Exception
+ * @throws Throwable
*/
protected function _getAlwaysJobSchedule($jobCode)
{
/** @var Mage_Cron_Model_Schedule $schedule */
$schedule = Mage::getModel('cron/schedule')->load($jobCode, 'job_code');
if ($schedule->getId() === null) {
- $ts = date('Y-m-d H:i:00');
+ $timestamp = Carbon::now()->format('Y-m-d H:i:00');
$schedule->setJobCode($jobCode)
- ->setCreatedAt($ts)
- ->setScheduledAt($ts);
+ ->setCreatedAt($timestamp)
+ ->setScheduledAt($timestamp);
}
$schedule->setStatus(Mage_Cron_Model_Schedule::STATUS_RUNNING)->save();
diff --git a/app/code/core/Mage/Cron/Model/Schedule.php b/app/code/core/Mage/Cron/Model/Schedule.php
index 698c16c6477..8216ff5f1f9 100644
--- a/app/code/core/Mage/Cron/Model/Schedule.php
+++ b/app/code/core/Mage/Cron/Model/Schedule.php
@@ -7,6 +7,8 @@
* @package Mage_Cron
*/
+use Carbon\Carbon;
+
/**
* Crontab schedule model
*
@@ -90,7 +92,7 @@ public function trySchedule($time)
}
if (!is_numeric($time)) {
- $time = strtotime($time);
+ $time = Carbon::parse($time)->getTimestamp();
}
if ($time === false) {
@@ -107,7 +109,7 @@ public function trySchedule($time)
if ($match) {
$this->setCreatedAt(date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT));
- $this->setScheduledAt(date('Y-m-d H:i:00', (int) $time));
+ $this->setScheduledAt(Carbon::createFromTimestamp((int) $time)->format('Y-m-d H:i:00'));
}
return $match;
diff --git a/app/code/core/Mage/Customer/Model/Resource/Customer.php b/app/code/core/Mage/Customer/Model/Resource/Customer.php
index 56d6aa4c8a9..d14ab5df77d 100644
--- a/app/code/core/Mage/Customer/Model/Resource/Customer.php
+++ b/app/code/core/Mage/Customer/Model/Resource/Customer.php
@@ -7,6 +7,8 @@
* @package Mage_Customer
*/
+use Carbon\Carbon;
+
/**
* Customer entity resource model
*
@@ -229,7 +231,7 @@ public function loadByEmail(Mage_Customer_Model_Customer $customer, $email)
*/
public function changePassword(Mage_Customer_Model_Customer $customer, $newPassword)
{
- $customer->setPassword($newPassword)->setPasswordCreatedAt(time());
+ $customer->setPassword($newPassword)->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$this->saveAttribute($customer, 'password_hash');
$this->saveAttribute($customer, 'password_created_at');
return $this;
diff --git a/app/code/core/Mage/Customer/controllers/AccountController.php b/app/code/core/Mage/Customer/controllers/AccountController.php
index 96c34fa85aa..ed7c82ea780 100644
--- a/app/code/core/Mage/Customer/controllers/AccountController.php
+++ b/app/code/core/Mage/Customer/controllers/AccountController.php
@@ -7,6 +7,7 @@
* @package Mage_Customer
*/
+use Carbon\Carbon;
use Mage_Customer_Helper_Data as Helper;
/**
@@ -295,7 +296,7 @@ public function createPostAction()
if (empty($errors)) {
$customer->cleanPasswordsValidationData();
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$customer->save();
$this->_dispatchRegisterSuccess($customer);
$this->_successProcessRegistration($customer);
@@ -885,7 +886,7 @@ public function resetPasswordPostAction()
$customer->setRpToken(null);
$customer->setRpTokenCreatedAt(null);
$customer->cleanPasswordsValidationData();
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$customer->setRpCustomerId(null);
$customer->setConfirmation(null); // Set email is confirmed.
$customer->save();
@@ -1056,7 +1057,7 @@ public function editPostAction()
try {
$customer->cleanPasswordsValidationData();
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
// Reset all password reset tokens if all data was sufficient and correct on email change
if ($customer->getIsChangeEmail()) {
diff --git a/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php b/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php
index 5392ab8d66a..3e446699ce2 100644
--- a/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php
+++ b/app/code/core/Mage/Dataflow/Model/Convert/Iterator.php
@@ -7,6 +7,8 @@
* @package Mage_Dataflow
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Dataflow
*/
@@ -56,7 +58,7 @@ protected function _getProgressBarHtml($sessionId, $totalRows)
';
+ . $args['row']['session_id'] . '", "' . $args['idx'] . '", "' . Carbon::now()->getTimestamp() . '", "' . $memory . '");';
echo '' . $memory . '';
return [];
diff --git a/app/code/core/Mage/Dataflow/Model/Profile.php b/app/code/core/Mage/Dataflow/Model/Profile.php
index ce1b5ccbc4f..32906511a02 100644
--- a/app/code/core/Mage/Dataflow/Model/Profile.php
+++ b/app/code/core/Mage/Dataflow/Model/Profile.php
@@ -7,6 +7,8 @@
* @package Mage_Dataflow
*/
+use Carbon\Carbon;
+
/**
* Convert profile
*
@@ -241,7 +243,7 @@ protected function _afterSave()
}
if ($uploadFile) {
- $newFilename = 'import-' . date('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile;
+ $newFilename = 'import-' . Carbon::now()->format('YmdHis') . '-' . ($index + 1) . '_' . $uploadFile;
rename($path . $uploadFile, $path . $newFilename);
$newUploadedFilenames[] = $newFilename;
}
diff --git a/app/code/core/Mage/Dataflow/Model/Resource/Profile.php b/app/code/core/Mage/Dataflow/Model/Resource/Profile.php
index 56a3dd913ac..bd7b25bcf4c 100644
--- a/app/code/core/Mage/Dataflow/Model/Resource/Profile.php
+++ b/app/code/core/Mage/Dataflow/Model/Resource/Profile.php
@@ -7,6 +7,8 @@
* @package Mage_Dataflow
*/
+use Carbon\Carbon;
+
/**
* Convert profile resource model
*
@@ -30,10 +32,10 @@ protected function _construct()
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
if (!$object->getCreatedAt()) {
- $object->setCreatedAt($this->formatDate(time()));
+ $object->setCreatedAt($this->formatDate(Carbon::now()->getTimestamp()));
}
- $object->setUpdatedAt($this->formatDate(time()));
+ $object->setUpdatedAt($this->formatDate(Carbon::now()->getTimestamp()));
return parent::_beforeSave($object);
}
diff --git a/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php b/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php
index cb1c54b803e..0d283bda268 100644
--- a/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php
+++ b/app/code/core/Mage/Dataflow/Model/Resource/Profile/History.php
@@ -7,6 +7,8 @@
* @package Mage_Dataflow
*/
+use Carbon\Carbon;
+
/**
* Convert history resource model
*
@@ -30,7 +32,7 @@ protected function _construct()
protected function _beforeSave(Mage_Core_Model_Abstract $object)
{
if (!$object->getPerformedAt()) {
- $object->setPerformedAt($this->formatDate(time()));
+ $object->setPerformedAt($this->formatDate(Carbon::now()->getTimestamp()));
}
parent::_beforeSave($object);
diff --git a/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php b/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php
index b58004c1aa6..ce4c652be6a 100644
--- a/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php
+++ b/app/code/core/Mage/Eav/Model/Attribute/Data/Date.php
@@ -7,6 +7,8 @@
* @package Mage_Eav
*/
+use Carbon\Carbon;
+
/**
* EAV Entity Attribute Date Data Model
*
@@ -17,7 +19,8 @@ class Mage_Eav_Model_Attribute_Data_Date extends Mage_Eav_Model_Attribute_Data_A
/**
* Extract data from request and return value
*
- * @return array|false|string
+ * @return false|string
+ * @throws Mage_Core_Exception
*/
public function extractValue(Zend_Controller_Request_Http $request)
{
@@ -31,6 +34,8 @@ public function extractValue(Zend_Controller_Request_Http $request)
*
* @param array|string $value
* @return array|bool
+ * @throws Mage_Core_Exception
+ * @throws Mage_Core_Model_Store_Exception
*/
public function validateValue($value)
{
@@ -58,15 +63,29 @@ public function validateValue($value)
//range validation
$validateRules = $attribute->getValidateRules();
- if ((!empty($validateRules['date_range_min']) && (strtotime($value) < $validateRules['date_range_min']))
- || (!empty($validateRules['date_range_max']) && (strtotime($value) > $validateRules['date_range_max']))
+ 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.', date('d/m/Y', $validateRules['date_range_min']), date('d/m/Y', $validateRules['date_range_max']), $label);
+ $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')->__('Please enter a valid date equal to or greater than %s at %s.', date('d/m/Y', $validateRules['date_range_min']), $label);
+ $errors[] = Mage::helper('customer')->__(
+ 'Please enter a valid date equal to or greater than %s at %s.',
+ Carbon::createFromTimestamp($validateRules['date_range_min'])->format($format),
+ $label,
+ );
} elseif (!empty($validateRules['date_range_max'])) {
- $errors[] = Mage::helper('customer')->__('Please enter a valid date less than or equal to %s at %s.', date('d/m/Y', $validateRules['date_range_max']), $label);
+ $errors[] = Mage::helper('customer')->__(
+ 'Please enter a valid date less than or equal to %s at %s.',
+ Carbon::createFromTimestamp($validateRules['date_range_max'])->format($format),
+ $label,
+ );
}
}
@@ -82,6 +101,7 @@ public function validateValue($value)
*
* @param array|string $value
* @return $this
+ * @throws Mage_Core_Exception
*/
public function compactValue($value)
{
@@ -99,6 +119,7 @@ public function compactValue($value)
*
* @param array|string $value
* @return $this
+ * @throws Mage_Core_Exception
*/
public function restoreValue($value)
{
@@ -110,6 +131,8 @@ public function restoreValue($value)
*
* @param string $format
* @return array|string
+ * @throws Mage_Core_Exception
+ * @throws Zend_Locale_Exception
*/
public function outputValue($format = Mage_Eav_Model_Attribute_Data::OUTPUT_FORMAT_TEXT)
{
diff --git a/app/code/core/Mage/ImportExport/Model/Export.php b/app/code/core/Mage/ImportExport/Model/Export.php
index aa2a515ffd2..831c3631a4d 100644
--- a/app/code/core/Mage/ImportExport/Model/Export.php
+++ b/app/code/core/Mage/ImportExport/Model/Export.php
@@ -7,6 +7,8 @@
* @package Mage_ImportExport
*/
+use Carbon\Carbon;
+
/**
* Export model
*
@@ -304,6 +306,6 @@ public function getFileFormat()
*/
public function getFileName()
{
- return $this->getEntity() . '_' . date('Ymd_His') . '.' . $this->_getWriter()->getFileExtension();
+ return $this->getEntity() . '_' . Carbon::now()->format('Ymd_His') . '.' . $this->_getWriter()->getFileExtension();
}
}
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
index 2020e469c79..b6a06274454 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Abstract.php
@@ -7,6 +7,9 @@
* @package Mage_ImportExport
*/
+use Carbon\Carbon;
+use Carbon\Exceptions\InvalidFormatException;
+
/**
* Import entity abstract model
*
@@ -176,6 +179,9 @@ abstract class Mage_ImportExport_Model_Import_Entity_Abstract
*/
protected $_uniqueAttributes = [];
+ /**
+ * @throws Mage_Core_Exception
+ */
public function __construct()
{
$entityType = Mage::getSingleton('eav/config')->getEntityType($this->getEntityTypeCode());
@@ -191,6 +197,7 @@ public function __construct()
* Inner source object getter.
*
* @return Mage_ImportExport_Model_Import_Adapter_Abstract
+ * @throws Mage_Core_Exception
*/
protected function _getSource()
{
@@ -244,6 +251,7 @@ protected function _prepareRowForDb(array $rowData)
* Validate data rows and save bunches to DB.
*
* @return Mage_ImportExport_Model_Import_Entity_Abstract|void
+ * @throws Mage_Core_Exception
*/
protected function _saveValidatedBunches()
{
@@ -561,8 +569,13 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData, $
break;
case 'datetime':
$val = trim($rowData[$attrCode]);
- $valid = strtotime($val) !== false
- || preg_match('/^\d{2}.\d{2}.\d{2,4}(?:\s+\d{1,2}.\d{1,2}(?:.\d{1,2})?)?$/', $val);
+ try {
+ $valid = Carbon::parse($val)->getTimestamp();
+ } catch (InvalidFormatException) {
+ $valid = false;
+ }
+
+ $valid = $valid !== false || preg_match('/^\d{2}.\d{2}.\d{2,4}(?:\s+\d{1,2}.\d{1,2}(?:.\d{1,2})?)?$/', $val);
break;
case 'text':
$val = Mage::helper('core/string')->cleanString($rowData[$attrCode]);
@@ -591,6 +604,7 @@ public function isAttributeValid($attrCode, array $attrParams, array $rowData, $
* Is all of data valid?
*
* @return bool
+ * @throws Exception
*/
public function isDataValid()
{
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php
index 03b2d05415e..3625ba2a0ba 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer.php
@@ -7,6 +7,8 @@
* @package Mage_ImportExport
*/
+use Carbon\Carbon;
+
/**
* Import entity customer model
*
@@ -401,7 +403,7 @@ protected function _saveCustomers()
'store_id' => empty($rowData[self::COL_STORE])
? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]],
'created_at' => empty($rowData['created_at'])
- ? $now : gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($rowData['created_at'])),
+ ? $now : gmdate(Varien_Date::DATETIME_PHP_FORMAT, Carbon::parse($rowData['created_at'])->getTimestamp()),
'updated_at' => $now,
];
@@ -434,7 +436,7 @@ protected function _saveCustomers()
if ($attrParams['type'] === 'select') {
$value = $attrParams['options'][strtolower($value)];
} elseif ($attrParams['type'] === 'datetime') {
- $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($value));
+ $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, Carbon::parse($value)->getTimestamp());
} elseif ($attrParams['type'] === 'multiselect') {
$value = (array) $attrParams['options'][strtolower($value)];
$attribute->getBackend()->beforeSave($resource->setData($attrCode, $value));
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php
index 5fb8e9c83f6..434f3ab9ee9 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Customer/Address.php
@@ -7,6 +7,8 @@
* @package Mage_ImportExport
*/
+use Carbon\Carbon;
+
/**
* Import entity customer address
*
@@ -186,7 +188,7 @@ protected function _importData()
if ($attrParams['type'] === 'select') {
$value = $attrParams['options'][strtolower($rowData[$attrAlias])];
} elseif ($attrParams['type'] === 'datetime') {
- $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($rowData[$attrAlias]));
+ $value = gmdate(Varien_Date::DATETIME_PHP_FORMAT, Carbon::parse($rowData[$attrAlias])->getTimestamp());
} elseif ($attrParams['type'] === 'multiselect') {
$value = $attrParams['options'][strtolower($rowData[$attrAlias])];
$multiSelect[$attrParams['id']][] = $value;
diff --git a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php
index e649f4a7811..2fd8ab4cc65 100644
--- a/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php
+++ b/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php
@@ -7,6 +7,9 @@
* @package Mage_ImportExport
*/
+use Carbon\Carbon;
+use Carbon\Exceptions\InvalidFormatException;
+
/**
* Import entity product model
*
@@ -424,6 +427,10 @@ class Mage_ImportExport_Model_Import_Entity_Product extends Mage_ImportExport_Mo
*/
protected $_urlKeyAttributeId;
+ /**
+ * @throws Exception
+ * @throws Mage_Core_Exception
+ */
public function __construct()
{
parent::__construct();
@@ -441,6 +448,8 @@ public function __construct()
* Delete products.
*
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Zend_Db_Adapter_Exception
*/
protected function _deleteProducts()
{
@@ -496,6 +505,7 @@ protected function _importData()
* Initialize attribute sets code-to-id pairs.
*
* @return $this
+ * @throws Mage_Core_Exception
*/
protected function _initAttributeSets()
{
@@ -524,8 +534,8 @@ protected function _initCategories()
$pathSize = count($structure);
if ($pathSize > 1) {
$path = [];
- for ($i = 1; $i < $pathSize; $i++) {
- $path[] = $collection->getItemById($structure[$i])->getName();
+ for ($pathIndex = 1; $pathIndex < $pathSize; $pathIndex++) {
+ $path[] = $collection->getItemById($structure[$pathIndex])->getName();
}
$rootCategoryName = array_shift($path);
@@ -562,6 +572,7 @@ protected function _initCustomerGroups()
* Initialize existent product SKUs.
*
* @return $this
+ * @throws Mage_Core_Exception
*/
protected function _initSkus()
{
@@ -584,6 +595,7 @@ protected function _initSkus()
* Initialize stores hash.
*
* @return $this
+ * @throws Mage_Core_Exception
*/
protected function _initStores()
{
@@ -636,6 +648,7 @@ protected function _initTypeModels()
* Initialize website values.
*
* @return $this
+ * @throws Mage_Core_Exception
*/
protected function _initWebsites()
{
@@ -829,6 +842,8 @@ protected function _isProductSkuValid(array $rowData, $rowNum)
* Custom options save.
*
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Zend_Db_Exception
*/
protected function _saveCustomOptions()
{
@@ -1173,6 +1188,8 @@ protected function _saveCustomOptions()
* Must be called after ALL products saving done.
*
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Zend_Db_Select_Exception
*/
protected function _saveLinks()
{
@@ -1287,6 +1304,7 @@ protected function _saveLinks()
* Save product attributes.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveProductAttributes(array $attributesData)
{
@@ -1336,6 +1354,7 @@ protected function _saveProductAttributes(array $attributesData)
* Save product categories.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveProductCategories(array $categoriesData)
{
@@ -1379,6 +1398,8 @@ protected function _saveProductCategories(array $categoriesData)
* @param array $entityRowsIn Row for insert
* @param array $entityRowsUp Row for update
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Zend_Db_Exception
*/
protected function _saveProductEntity(array $entityRowsIn, array $entityRowsUp)
{
@@ -1414,6 +1435,8 @@ protected function _saveProductEntity(array $entityRowsIn, array $entityRowsUp)
* Gather and save information about product entities.
*
* @return $this
+ * @throws Mage_Core_Exception
+ * @throws Zend_Db_Exception
*/
protected function _saveProducts()
{
@@ -1567,8 +1590,8 @@ protected function _saveProducts()
);
try {
$attributes = $this->_prepareAttributes($rowData, $rowScope, $attributes, $rowSku, $rowStore);
- } catch (Exception $e) {
- Mage::logException($e);
+ } catch (Exception $exception) {
+ Mage::logException($exception);
continue;
}
}
@@ -1601,6 +1624,7 @@ protected function _getStrftimeFormat()
*
* @param string $code
* @return Mage_Eav_Model_Entity_Attribute_Abstract
+ * @throws Mage_Core_Exception
*/
protected function _getAttribute($code)
{
@@ -1624,6 +1648,8 @@ protected function _getAttribute($code)
* @param null|string $rowSku
* @param int $rowStore
* @return array
+ * @throws Mage_Core_Exception
+ * @throws Mage_Core_Model_Store_Exception
*/
protected function _prepareAttributes($rowData, $rowScope, $attributes, $rowSku, $rowStore)
{
@@ -1643,8 +1669,14 @@ protected function _prepareAttributes($rowData, $rowScope, $attributes, $rowSku,
$attrTable = $attribute->getBackend()->getTable();
$storeIds = [0];
- if ($attribute->getBackendType() === 'datetime' && strtotime($attrValue)) {
- $attrValue = gmdate(Varien_Date::DATETIME_PHP_FORMAT, strtotime($attrValue));
+ try {
+ $timestamp = Carbon::parse($attrValue)->getTimestamp();
+ } catch (InvalidFormatException) {
+ $timestamp = false;
+ }
+
+ if ($attribute->getBackendType() === 'datetime' && $timestamp) {
+ $attrValue = gmdate(Varien_Date::DATETIME_PHP_FORMAT, $timestamp);
} elseif ($attribute->getAttributeCode() === 'url_key') {
if (empty($attrValue)) {
$locale = Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $product->getStoreId());
@@ -1692,6 +1724,7 @@ protected function _prepareAttributes($rowData, $rowScope, $attributes, $rowSku,
* Save product tier prices.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveProductTierPrices(array $tierPriceData)
{
@@ -1735,6 +1768,7 @@ protected function _saveProductTierPrices(array $tierPriceData)
* Save product group prices.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveProductGroupPrices(array $groupPriceData)
{
@@ -1778,6 +1812,7 @@ protected function _saveProductGroupPrices(array $groupPriceData)
* Returns an object for upload a media files
*
* @SuppressWarnings("PHPMD.ErrorControlOperator")
+ * @throws Mage_Core_Exception
*/
protected function _getUploader()
{
@@ -1825,6 +1860,7 @@ protected function _uploadMediaFiles($fileName)
* Save product media gallery.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveMediaGallery(array $mediaGalleryData)
{
@@ -1906,6 +1942,7 @@ protected function _saveMediaGallery(array $mediaGalleryData)
* Save product websites.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveProductWebsites(array $websiteData)
{
@@ -1983,6 +2020,7 @@ protected function getModel($modelName)
* Stock item saving.
*
* @return $this
+ * @throws Zend_Db_Exception
*/
protected function _saveStockItem()
{
diff --git a/app/code/core/Mage/Index/Model/Event.php b/app/code/core/Mage/Index/Model/Event.php
index 765600b0b6d..77d88c6bab4 100644
--- a/app/code/core/Mage/Index/Model/Event.php
+++ b/app/code/core/Mage/Index/Model/Event.php
@@ -7,6 +7,8 @@
* @package Mage_Index
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Index
*
@@ -333,7 +335,7 @@ protected function _beforeSave()
$newData = $this->getNewData(false);
$this->setNewData(serialize($newData));
if (!$this->hasCreatedAt()) {
- $this->setCreatedAt($this->_getResource()->formatDate(time(), true));
+ $this->setCreatedAt($this->_getResource()->formatDate(Carbon::now()->getTimestamp(), true));
}
return parent::_beforeSave();
diff --git a/app/code/core/Mage/Index/Model/Lock.php b/app/code/core/Mage/Index/Model/Lock.php
index 0b791c702eb..ecc2b39f9ed 100644
--- a/app/code/core/Mage/Index/Model/Lock.php
+++ b/app/code/core/Mage/Index/Model/Lock.php
@@ -7,6 +7,8 @@
* @package Mage_Index
*/
+use Carbon\Carbon;
+
/**
* Lock model
*
@@ -298,7 +300,7 @@ protected function _getLockFile($lockName)
throw new Exception(sprintf("Unable to open lock file '%s': %s", $file, error_get_last()));
}
- fwrite(self::$_lockFileResource[$lockName], date('r'));
+ fwrite(self::$_lockFileResource[$lockName], Carbon::now()->format('r'));
}
return self::$_lockFileResource[$lockName];
diff --git a/app/code/core/Mage/Index/Model/Observer.php b/app/code/core/Mage/Index/Model/Observer.php
index c39fb0ae232..b59dfe44670 100644
--- a/app/code/core/Mage/Index/Model/Observer.php
+++ b/app/code/core/Mage/Index/Model/Observer.php
@@ -7,6 +7,8 @@
* @package Mage_Index
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Index
*/
@@ -145,7 +147,7 @@ public function cleanOutdatedEvents()
->getProcessesCollection()
->addFieldToFilter('mode', Mage_Index_Model_Process::MODE_MANUAL);
- $now = new DateTime();
+ $now = Carbon::now();
/** @noinspection PhpUnhandledExceptionInspection */
$dateInterval = new DateInterval('PT' . self::OLD_INDEX_EVENT_THRESHOLD_SECONDS . 'S');
$oldEventsThreshold = $now
diff --git a/app/code/core/Mage/Index/Model/Resource/Process.php b/app/code/core/Mage/Index/Model/Resource/Process.php
index 2da28caf95c..3fe164bc577 100644
--- a/app/code/core/Mage/Index/Model/Resource/Process.php
+++ b/app/code/core/Mage/Index/Model/Resource/Process.php
@@ -7,6 +7,8 @@
* @package Mage_Index
*/
+use Carbon\Carbon;
+
/**
* Index Process Resource Model
*
@@ -50,7 +52,7 @@ public function endProcess(Mage_Index_Model_Process $process)
{
$data = [
'status' => Mage_Index_Model_Process::STATUS_PENDING,
- 'ended_at' => $this->formatDate(time()),
+ 'ended_at' => $this->formatDate(Carbon::now()->getTimestamp()),
];
$this->_updateProcessData($process->getId(), $data);
return $this;
@@ -65,7 +67,7 @@ public function startProcess(Mage_Index_Model_Process $process)
{
$data = [
'status' => Mage_Index_Model_Process::STATUS_RUNNING,
- 'started_at' => $this->formatDate(time()),
+ 'started_at' => $this->formatDate(Carbon::now()->getTimestamp()),
];
$this->_updateProcessData($process->getId(), $data);
return $this;
@@ -80,7 +82,7 @@ public function failProcess(Mage_Index_Model_Process $process)
{
$data = [
'status' => Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX,
- 'ended_at' => $this->formatDate(time()),
+ 'ended_at' => $this->formatDate(Carbon::now()->getTimestamp()),
];
$this->_updateProcessData($process->getId(), $data);
return $this;
@@ -121,7 +123,7 @@ protected function _updateProcessData($processId, $data)
*/
public function updateProcessStartDate(Mage_Index_Model_Process $process)
{
- $this->_updateProcessData($process->getId(), ['started_at' => $this->formatDate(time())]);
+ $this->_updateProcessData($process->getId(), ['started_at' => $this->formatDate(Carbon::now()->getTimestamp())]);
return $this;
}
@@ -132,7 +134,7 @@ public function updateProcessStartDate(Mage_Index_Model_Process $process)
*/
public function updateProcessEndDate(Mage_Index_Model_Process $process)
{
- $this->_updateProcessData($process->getId(), ['ended_at' => $this->formatDate(time())]);
+ $this->_updateProcessData($process->getId(), ['ended_at' => $this->formatDate(Carbon::now()->getTimestamp())]);
return $this;
}
diff --git a/app/code/core/Mage/Install/Model/Installer/Config.php b/app/code/core/Mage/Install/Model/Installer/Config.php
index b901d2e0af4..f39c4aea9e3 100644
--- a/app/code/core/Mage/Install/Model/Installer/Config.php
+++ b/app/code/core/Mage/Install/Model/Installer/Config.php
@@ -7,6 +7,8 @@
* @package Mage_Install
*/
+use Carbon\Carbon;
+
/**
* Config installer
*
@@ -167,9 +169,9 @@ protected function _checkUrl($url, $secure = false)
public function replaceTmpInstallDate($date = null)
{
- $stamp = strtotime((string) $date);
+ $stamp = Carbon::parse((string) $date)->getTimestamp();
$localXml = file_get_contents($this->_localConfigFile);
- $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, date('r', $stamp ? $stamp : time()), $localXml);
+ $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, Carbon::createFromTimestamp($stamp ? $stamp : Carbon::now()->getTimestamp())->format('r'), $localXml);
file_put_contents($this->_localConfigFile, $localXml);
return $this;
diff --git a/app/code/core/Mage/Log/Model/Aggregation.php b/app/code/core/Mage/Log/Model/Aggregation.php
index f1622d5fe0b..a4d217481c3 100644
--- a/app/code/core/Mage/Log/Model/Aggregation.php
+++ b/app/code/core/Mage/Log/Model/Aggregation.php
@@ -7,6 +7,8 @@
* @package Mage_Log
*/
+use Carbon\Carbon;
+
/**
* Log Aggregation Model
*
@@ -34,6 +36,8 @@ protected function _construct()
/**
* Run action
+ *
+ * @throws Mage_Core_Exception
*/
public function run()
{
@@ -48,17 +52,18 @@ public function run()
*
* @param int $store
* @return mixed
+ * @throws Mage_Core_Exception
*/
private function _process($store)
{
$lastDateRecord = null;
$start = $this->_lastRecord;
- $end = time();
+ $end = Carbon::now()->getTimestamp();
$date = $start;
while ($date < $end) {
- $to = $date + 3600;
- $counts = $this->_getCounts($this->_date($date), $this->_date($to), $store);
+ $toDate = $date + 3600;
+ $counts = $this->_getCounts($this->_date($date), $this->_date($toDate), $store);
$data = [
'store_id' => $store,
'visitor_count' => $counts['visitors'],
@@ -67,11 +72,11 @@ private function _process($store)
];
if ($counts['visitors'] || $counts['customers']) {
- $this->_save($data, $this->_date($date), $this->_date($to));
+ $this->_save($data, $this->_date($date), $this->_date($toDate));
}
$lastDateRecord = $date;
- $date = $to;
+ $date = $toDate;
}
return $lastDateRecord;
@@ -83,6 +88,7 @@ private function _process($store)
* @param array $data
* @param string $from
* @param string $to
+ * @throws Mage_Core_Exception
*/
private function _save($data, $from, $to)
{
@@ -96,6 +102,7 @@ private function _save($data, $from, $to)
/**
* @param string $id
* @param array $data
+ * @throws Mage_Core_Exception
*/
private function _update($id, $data)
{
@@ -104,6 +111,7 @@ private function _update($id, $data)
/**
* @param array $data
+ * @throws Mage_Core_Exception
*/
private function _insert($data)
{
@@ -115,6 +123,7 @@ private function _insert($data)
* @param string $to
* @param int $store
* @return array
+ * @throws Mage_Core_Exception
*/
private function _getCounts($from, $to, $store)
{
@@ -122,13 +131,14 @@ private function _getCounts($from, $to, $store)
}
/**
- * @return false|string
+ * @return int|string
+ * @throws Mage_Core_Exception
*/
public function getLastRecordDate()
{
$result = $this->_getResource()->getLastRecordDate();
if (!$result) {
- $result = $this->_date(strtotime('now - 2 months'));
+ $result = $this->_date(Carbon::parse('now - 2 months')->getTimestamp());
}
return $result;
@@ -143,7 +153,7 @@ private function _date($in, $offset = null)
{
$out = $in;
if (is_numeric($in)) {
- $out = date(Varien_Date::DATETIME_PHP_FORMAT, $in);
+ $out = Carbon::createFromTimestamp($in)->format(Varien_Date::DATETIME_PHP_FORMAT);
}
return $out;
@@ -152,13 +162,13 @@ private function _date($in, $offset = null)
/**
* @param int|string $in
* @param null $offset deprecated
- * @return false|int
+ * @return int
*/
private function _timestamp($in, $offset = null)
{
$out = $in;
if (!is_numeric($in)) {
- $out = strtotime($in);
+ $out = Carbon::parse($in)->getTimestamp();
}
return $out;
@@ -170,6 +180,6 @@ private function _timestamp($in, $offset = null)
*/
private function _round($in)
{
- return date('Y-m-d H:00:00', $this->_timestamp($in));
+ return Carbon::createFromTimestamp($this->_timestamp($in))->format('Y-m-d H:00:00');
}
}
diff --git a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php
index 5ad2849e847..e7b5d907c63 100644
--- a/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php
+++ b/app/code/core/Mage/Log/Model/Resource/Visitor/Online.php
@@ -7,6 +7,8 @@
* @package Mage_Log
*/
+use Carbon\Carbon;
+
/**
* Log Prepare Online visitors resource
*
@@ -29,7 +31,7 @@ protected function _construct()
*/
public function prepare(Mage_Log_Model_Visitor_Online $object)
{
- if (($object->getUpdateFrequency() + $object->getPrepareAt()) > time()) {
+ if (($object->getUpdateFrequency() + $object->getPrepareAt()) > Carbon::now()->getTimestamp()) {
return $this;
}
diff --git a/app/code/core/Mage/Log/Model/Visitor/Online.php b/app/code/core/Mage/Log/Model/Visitor/Online.php
index fefb469cdda..51ff6af25b6 100644
--- a/app/code/core/Mage/Log/Model/Visitor/Online.php
+++ b/app/code/core/Mage/Log/Model/Visitor/Online.php
@@ -7,6 +7,8 @@
* @package Mage_Log
*/
+use Carbon\Carbon;
+
/**
* Prepare Log Online Visitors Model
*
@@ -73,7 +75,7 @@ public function getPrepareAt()
public function setPrepareAt($time = null)
{
if (is_null($time)) {
- $time = time();
+ $time = Carbon::now()->getTimestamp();
}
Mage::app()->saveCache($time, 'log_visitor_online_prepare_at');
diff --git a/app/code/core/Mage/Oauth/Model/Consumer.php b/app/code/core/Mage/Oauth/Model/Consumer.php
index fbf57e8687f..04d72e6da4f 100644
--- a/app/code/core/Mage/Oauth/Model/Consumer.php
+++ b/app/code/core/Mage/Oauth/Model/Consumer.php
@@ -7,6 +7,8 @@
* @package Mage_Oauth
*/
+use Carbon\Carbon;
+
/**
* Application model
*
@@ -59,7 +61,7 @@ protected function _construct()
protected function _beforeSave()
{
if (!$this->getId()) {
- $this->setUpdatedAt(time());
+ $this->setUpdatedAt(Carbon::now()->getTimestamp());
}
$this->setCallbackUrl(trim($this->getCallbackUrl()));
diff --git a/app/code/core/Mage/Oauth/Model/Resource/Nonce.php b/app/code/core/Mage/Oauth/Model/Resource/Nonce.php
index 62c83408f39..a3be6227b23 100644
--- a/app/code/core/Mage/Oauth/Model/Resource/Nonce.php
+++ b/app/code/core/Mage/Oauth/Model/Resource/Nonce.php
@@ -7,6 +7,8 @@
* @package Mage_Oauth
*/
+use Carbon\Carbon;
+
/**
* oAuth nonce resource model
*
@@ -27,6 +29,7 @@ protected function _construct()
*
* @param int $minutes Delete entries older than
* @return int
+ * @throws Mage_Core_Exception
*/
public function deleteOldEntries($minutes)
{
@@ -35,7 +38,7 @@ public function deleteOldEntries($minutes)
return $adapter->delete(
$this->getMainTable(),
- $adapter->quoteInto('timestamp <= ?', time() - $minutes * 60, Zend_Db::INT_TYPE),
+ $adapter->quoteInto('timestamp <= ?', Carbon::now()->subMinutes($minutes)->getTimestamp(), Zend_Db::INT_TYPE),
);
} else {
return 0;
diff --git a/app/code/core/Mage/Oauth/Model/Resource/Token.php b/app/code/core/Mage/Oauth/Model/Resource/Token.php
index 409088b5f4b..5852a58ae38 100644
--- a/app/code/core/Mage/Oauth/Model/Resource/Token.php
+++ b/app/code/core/Mage/Oauth/Model/Resource/Token.php
@@ -7,6 +7,8 @@
* @package Mage_Oauth
*/
+use Carbon\Carbon;
+
/**
* OAuth token resource model
*
@@ -27,6 +29,7 @@ protected function _construct()
*
* @param Mage_Oauth_Model_Token $exceptToken Token just created to exclude from delete
* @return int The number of affected rows
+ * @throws Mage_Core_Exception
*/
public function cleanOldAuthorizedTokensExcept(Mage_Oauth_Model_Token $exceptToken)
{
@@ -58,6 +61,7 @@ public function cleanOldAuthorizedTokensExcept(Mage_Oauth_Model_Token $exceptTok
*
* @param int $minutes
* @return int
+ * @throws Mage_Core_Exception
*/
public function deleteOldEntries($minutes)
{
@@ -68,7 +72,7 @@ public function deleteOldEntries($minutes)
$this->getMainTable(),
$adapter->quoteInto(
'type = "' . Mage_Oauth_Model_Token::TYPE_REQUEST . '" AND created_at <= ?',
- Varien_Date::formatDate(time() - $minutes * 60),
+ Varien_Date::formatDate(Carbon::now()->subMinutes($minutes)->getTimestamp()),
),
);
} else {
diff --git a/app/code/core/Mage/Oauth/Model/Server.php b/app/code/core/Mage/Oauth/Model/Server.php
index 5108e669f53..f9e6c93bcd8 100644
--- a/app/code/core/Mage/Oauth/Model/Server.php
+++ b/app/code/core/Mage/Oauth/Model/Server.php
@@ -7,6 +7,8 @@
* @package Mage_Oauth
*/
+use Carbon\Carbon;
+
/**
* oAuth Server
*
@@ -496,7 +498,7 @@ protected function _validateNonce($nonce, $timestamp)
{
$timestamp = (int) $timestamp;
- if ($timestamp <= 0 || $timestamp > (time() + self::TIME_DEVIATION)) {
+ if ($timestamp <= 0 || $timestamp > (Carbon::now()->getTimestamp() + self::TIME_DEVIATION)) {
$this->_throwException('', self::ERR_TIMESTAMP_REFUSED);
}
diff --git a/app/code/core/Mage/Payment/Block/Form/Cc.php b/app/code/core/Mage/Payment/Block/Form/Cc.php
index c6887259d8c..cf02b458c69 100644
--- a/app/code/core/Mage/Payment/Block/Form/Cc.php
+++ b/app/code/core/Mage/Payment/Block/Form/Cc.php
@@ -7,6 +7,8 @@
* @package Mage_Payment
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Payment
*/
@@ -134,7 +136,7 @@ public function hasSsCardType()
public function getSsStartYears()
{
$years = [];
- $first = date('Y');
+ $first = Carbon::now()->format('Y');
for ($index = 5; $index >= 0; $index--) {
$year = $first - $index;
diff --git a/app/code/core/Mage/Payment/Model/Config.php b/app/code/core/Mage/Payment/Model/Config.php
index 7887413b155..63c828a2ed4 100644
--- a/app/code/core/Mage/Payment/Model/Config.php
+++ b/app/code/core/Mage/Payment/Model/Config.php
@@ -7,6 +7,8 @@
* @package Mage_Payment
*/
+use Carbon\Carbon;
+
/**
* Payment configuration model
*
@@ -136,7 +138,7 @@ public function getMonths()
public function getYears()
{
$years = [];
- $first = date('Y');
+ $first = Carbon::now()->format('Y');
for ($index = 0; $index <= 10; $index++) {
$year = $first + $index;
diff --git a/app/code/core/Mage/Payment/Model/Recurring/Profile.php b/app/code/core/Mage/Payment/Model/Recurring/Profile.php
index 1825f9a3ce6..8ff8fd93e83 100644
--- a/app/code/core/Mage/Payment/Model/Recurring/Profile.php
+++ b/app/code/core/Mage/Payment/Model/Recurring/Profile.php
@@ -7,6 +7,8 @@
* @package Mage_Payment
*/
+use Carbon\Carbon;
+
/**
* Recurring payment profile
* Extends from Mage_Core_Abstract for a reason: to make descendants have its own resource
@@ -314,8 +316,8 @@ public function setNearestStartDatetime(?Zend_Date $minAllowed = null)
{
// TODO: implement proper logic with invoking payment method instance
$date = $minAllowed;
- if (!$date || $date->getTimestamp() < time()) {
- $date = new Zend_Date(time());
+ if (!$date || $date->getTimestamp() < Carbon::now()->getTimestamp()) {
+ $date = new Zend_Date(Carbon::now()->getTimestamp());
}
$this->setStartDatetime($date->toString(Varien_Date::DATETIME_INTERNAL_FORMAT));
@@ -335,7 +337,7 @@ public function exportStartDatetime($asString = true)
return;
}
- $date = $this->_locale->storeDate($this->_store, strtotime($datetime), true);
+ $date = $this->_locale->storeDate($this->_store, Carbon::parse($datetime)->getTimestamp(), true);
if ($asString) {
return $date->toString($this->_locale->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
}
diff --git a/app/code/core/Mage/Paypal/Model/Cert.php b/app/code/core/Mage/Paypal/Model/Cert.php
index f9ffef47e36..ff3203c580f 100644
--- a/app/code/core/Mage/Paypal/Model/Cert.php
+++ b/app/code/core/Mage/Paypal/Model/Cert.php
@@ -7,6 +7,8 @@
* @package Mage_Paypal
*/
+use Carbon\Carbon;
+
/**
* PayPal specific model for certificate based authentication
*
@@ -52,7 +54,7 @@ public function getCertPath()
Mage::throwException(Mage::helper('paypal')->__('PayPal certificate does not exist.'));
}
- $certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), strtotime($this->getUpdatedAt()));
+ $certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), Carbon::parse($this->getUpdatedAt())->getTimestamp());
$certFile = $this->_getBaseDir() . DS . $certFileName;
if (!file_exists($certFile)) {
diff --git a/app/code/core/Mage/Paypal/Model/Express.php b/app/code/core/Mage/Paypal/Model/Express.php
index 8df54a272ca..9d9de14f11b 100644
--- a/app/code/core/Mage/Paypal/Model/Express.php
+++ b/app/code/core/Mage/Paypal/Model/Express.php
@@ -7,6 +7,8 @@
* @package Mage_Paypal
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Paypal
*/
@@ -656,12 +658,13 @@ public function canCapture()
}
$orderValidPeriod = abs((int) $this->getConfigData('order_valid_period'));
+ if (!$orderValidPeriod) {
+ return false;
+ }
- $dateCompass = new DateTime($orderTransaction->getCreatedAt());
- $dateCompass->modify('+' . $orderValidPeriod . ' days');
- $currentDate = new DateTime();
-
- if ($currentDate > $dateCompass || $orderValidPeriod == 0) {
+ $dateCompass = Carbon::parse($orderTransaction->getCreatedAt())->addDays($orderValidPeriod);
+ $currentDate = Carbon::now();
+ if ($currentDate > $dateCompass) {
return false;
}
}
diff --git a/app/code/core/Mage/Paypal/Model/Express/Checkout.php b/app/code/core/Mage/Paypal/Model/Express/Checkout.php
index a4c5877bbec..9c144ad14e9 100644
--- a/app/code/core/Mage/Paypal/Model/Express/Checkout.php
+++ b/app/code/core/Mage/Paypal/Model/Express/Checkout.php
@@ -7,6 +7,8 @@
* @package Mage_Paypal
*/
+use Carbon\Carbon;
+
/**
* Wrapper that performs Paypal Express and Checkout communication
* Use current Paypal Express method instance
@@ -1025,7 +1027,7 @@ protected function _prepareNewCustomerQuote()
$customer->setSuffix($quote->getCustomerSuffix());
$customer->setPassword($customer->decryptPassword($quote->getPasswordHash()));
$customer->setPasswordHash($customer->hashPassword($customer->getPassword()));
- $customer->setPasswordCreatedAt(time());
+ $customer->setPasswordCreatedAt(Carbon::now()->getTimestamp());
$customer->save();
$quote->setCustomer($customer);
diff --git a/app/code/core/Mage/Persistent/Model/Session.php b/app/code/core/Mage/Persistent/Model/Session.php
index 98ce296fcf8..7ebb5f4db1c 100644
--- a/app/code/core/Mage/Persistent/Model/Session.php
+++ b/app/code/core/Mage/Persistent/Model/Session.php
@@ -7,6 +7,8 @@
* @package Mage_Persistent
*/
+use Carbon\Carbon;
+
/**
* Persistent Session Model
*
@@ -82,7 +84,7 @@ public function getExpiredBefore($store = null)
{
return gmdate(
Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT,
- time() - Mage::helper('persistent')->getLifeTime($store),
+ Carbon::now()->getTimestamp() - Mage::helper('persistent')->getLifeTime($store),
);
}
@@ -214,7 +216,7 @@ public function deleteExpired($websiteId = null)
if ($lifetime) {
$this->getResource()->deleteExpired(
$websiteId,
- gmdate(Varien_Date::DATETIME_PHP_FORMAT, time() - $lifetime),
+ gmdate(Varien_Date::DATETIME_PHP_FORMAT, Carbon::now()->getTimestamp() - $lifetime),
);
}
diff --git a/app/code/core/Mage/Reports/Helper/Data.php b/app/code/core/Mage/Reports/Helper/Data.php
index 003fb17e6e5..0f32749fbf4 100644
--- a/app/code/core/Mage/Reports/Helper/Data.php
+++ b/app/code/core/Mage/Reports/Helper/Data.php
@@ -7,6 +7,8 @@
* @package Mage_Reports
*/
+use Carbon\Carbon;
+
/**
* @package Mage_Reports
*/
@@ -74,11 +76,11 @@ public function getIntervals($from, $to, $period = self::REPORT_PERIOD_TYPE_DAY)
}
if ($period == self::REPORT_PERIOD_TYPE_MONTH) {
- $dateStart = new Zend_Date(date('Y-m', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
+ $dateStart = new Zend_Date(Carbon::createFromTimestamp($start->getTimestamp())->format('Y-m'), Varien_Date::DATE_INTERNAL_FORMAT);
}
if ($period == self::REPORT_PERIOD_TYPE_YEAR) {
- $dateStart = new Zend_Date(date('Y', $start->getTimestamp()), Varien_Date::DATE_INTERNAL_FORMAT);
+ $dateStart = new Zend_Date(Carbon::createFromTimestamp($start->getTimestamp())->format('Y'), Varien_Date::DATE_INTERNAL_FORMAT);
}
if (!$period || !$dateStart) {
diff --git a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php
index 6bb22e389be..5be6bdab9e0 100644
--- a/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php
+++ b/app/code/core/Mage/Reports/Model/Resource/Entity/Summary/Collection/Abstract.php
@@ -7,6 +7,8 @@
* @package Mage_Reports
*/
+use Carbon\Carbon;
+
/**
* Reports summary collection
*
@@ -54,11 +56,11 @@ public function setSelectPeriod($periodType, $customStart = null, $customEnd = n
default:
if (is_string($customStart)) {
- $customStart = strtotime($customStart);
+ $customStart = Carbon::parse($customStart)->getTimestamp();
}
if (is_string($customEnd)) {
- $customEnd = strtotime($customEnd);
+ $customEnd = Carbon::parse($customEnd)->getTimestamp();
}
break;
diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php
index 5b4de386e2d..3f9f0a1cb03 100644
--- a/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php
+++ b/app/code/core/Mage/Reports/Model/Resource/Report/Abstract.php
@@ -7,6 +7,8 @@
* @package Mage_Reports
*/
+use Carbon\Carbon;
+
/**
* Abstract report aggregate resource model
*
@@ -463,7 +465,7 @@ protected function _isValidTransition($transition, $to)
{
$result = true;
$timeStamp = $transition['ts'];
- $transitionYear = date('Y', $timeStamp);
+ $transitionYear = Carbon::createFromTimestamp($timeStamp)->format('Y');
if ($transitionYear > 10000 || $transitionYear < -10000) {
$result = false;
diff --git a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php
index 9e3f7cfb44d..629b0c6a32f 100644
--- a/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php
+++ b/app/code/core/Mage/Reports/Model/Resource/Report/Collection.php
@@ -7,6 +7,8 @@
* @package Mage_Reports
*/
+use Carbon\Carbon;
+
/**
* Report Reviews collection
*
@@ -131,7 +133,7 @@ public function getIntervals()
$time['end'] = ($lastInterval) ? $dateStart->setDay($dateEnd->getDay())
->toString('yyyy-MM-dd 23:59:59')
- : $dateStart->toString('yyyy-MM-' . date('t', $dateStart->getTimestamp()) . ' 23:59:59');
+ : $dateStart->toString('yyyy-MM-' . Carbon::createFromTimestamp($dateStart->getTimestamp())->format('t') . ' 23:59:59');
$dateStart->addMonth(1);
diff --git a/app/code/core/Mage/Reports/Model/Test.php b/app/code/core/Mage/Reports/Model/Test.php
index 15efb623336..366b7fc6f4f 100644
--- a/app/code/core/Mage/Reports/Model/Test.php
+++ b/app/code/core/Mage/Reports/Model/Test.php
@@ -7,6 +7,8 @@
* @package Mage_Reports
*/
+use Carbon\Carbon;
+
/**
* Model for flex reports
*
@@ -68,17 +70,17 @@ public function getTimelineData()
public function getAllLinearExample()
{
$session = Mage::getModel('review/session');
-
- $startPoint = time() - 24 * 60 * 60;
+ $startPoint = Carbon::now()->subDays(1)->getTimestamp();
+ $format = 'Y-m-d H:i';
$allData = [];
$countOfStartData = 12;
for ($i = 1; $i <= $countOfStartData; $i++) {
- $allData[] = ['time' => date('Y-m-d H:i', $startPoint), 'value' => random_int(1, 100)];
+ $allData[] = ['time' => Carbon::createFromTimestamp($startPoint)->format($format), 'value' => random_int(1, 100)];
$startPoint += 30 * 60;
}
- $allData[] = ['time' => date('Y-m-d H:i', $startPoint + (90 * 60))];
+ $allData[] = ['time' => Carbon::createFromTimestamp($startPoint + (90 * 60))->format($format)];
$session -> setData('startPoint', $startPoint);
@@ -91,17 +93,16 @@ public function getAllLinearExample()
public function getNewLinearData()
{
$session = Mage::getModel('review/session');
-
$startPoint = $session->getData('startPoint');
-
$reset = 12;
+ $format = 'Y-m-d H:i';
$newData = [
- ['time' => date('Y-m-d H:i', $startPoint), 'value' => random_int(1, 100)],
+ ['time' => Carbon::createFromTimestamp($startPoint)->format($format), 'value' => random_int(1, 100)],
];
$startPoint += 30 * 60;
- $newData[] = ['time' => date('Y-m-d H:i', $startPoint + (90 * 60))];
+ $newData[] = ['time' => Carbon::createFromTimestamp($startPoint + (90 * 60))->format($format)];
$session->setData('startPoint', $startPoint);
diff --git a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php
index 3afb2240ac5..266facf60fd 100644
--- a/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php
+++ b/app/code/core/Mage/Rss/Block/Catalog/Salesrule.php
@@ -7,6 +7,8 @@
* @package Mage_Rss
*/
+use Carbon\Carbon;
+
/**
* Review form block
*
@@ -36,7 +38,7 @@ protected function _toHtml()
$storeId = $this->_getStoreId();
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
$customerGroup = $this->_getCustomerGroupId();
- $now = date('Y-m-d');
+ $now = Carbon::now()->format('Y-m-d');
$url = Mage::getUrl('');
$newUrl = Mage::getUrl('rss/catalog/salesrule');
$lang = Mage::getStoreConfig('general/locale/code');
diff --git a/app/code/core/Mage/Rss/Block/Order/New.php b/app/code/core/Mage/Rss/Block/Order/New.php
index e1a24214b10..2ffb36d22a0 100644
--- a/app/code/core/Mage/Rss/Block/Order/New.php
+++ b/app/code/core/Mage/Rss/Block/Order/New.php
@@ -7,6 +7,8 @@
* @package Mage_Rss
*/
+use Carbon\Carbon;
+
/**
* Review form block
*
@@ -44,7 +46,7 @@ protected function _toHtml()
$order = Mage::getModel('sales/order');
$period = Mage::helper('rss')->getRssAdminOrderNewPeriod($storeId);
$passDate = $order->getResource()->formatDate(
- mktime(0, 0, 0, (int) date('m'), (int) date('d') - $period),
+ mktime(0, 0, 0, (int) Carbon::now()->format('m'), (int) Carbon::now()->format('d') - $period),
);
$newurl = Mage::helper('adminhtml')->getUrl('adminhtml/sales_order', ['_secure' => true, '_nosecret' => true]);
diff --git a/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php b/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php
index 9e65253bc5f..61596880316 100644
--- a/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php
+++ b/app/code/core/Mage/Rule/Model/Condition/Product/Abstract.php
@@ -7,6 +7,8 @@
* @package Mage_Rule
*/
+use Carbon\Carbon;
+
/**
* Abstract Rule product condition data model
*
@@ -504,8 +506,8 @@ public function validate(Varien_Object $object)
$attr = $object->getResource()->getAttribute($attrCode);
if ($attr && $attr->getBackendType() == 'datetime' && !is_int($this->getValue())) {
- $this->setValue(strtotime($this->getValue()));
- $value = strtotime($object->getData($attrCode));
+ $this->setValue(Carbon::parse($this->getValue())->getTimestamp());
+ $value = Carbon::parse($object->getData($attrCode))->getTimestamp();
return $this->validateAttribute($value);
}
@@ -524,7 +526,7 @@ public function validate(Varien_Object $object)
foreach ($this->_entityAttributeValues[$object->getId()] as $value) {
$attr = $object->getResource()->getAttribute($attrCode);
if ($attr && $attr->getBackendType() == 'datetime') {
- $value = strtotime($value);
+ $value = Carbon::parse($value)->getTimestamp();
} elseif ($attr && $attr->getFrontendInput() == 'multiselect') {
$value = strlen($value) ? explode(',', $value) : [];
}
diff --git a/app/code/core/Mage/Rule/Model/Environment.php b/app/code/core/Mage/Rule/Model/Environment.php
index 0b511a6a09c..a07a7d7ad4f 100644
--- a/app/code/core/Mage/Rule/Model/Environment.php
+++ b/app/code/core/Mage/Rule/Model/Environment.php
@@ -7,6 +7,8 @@
* @package Mage_Rule
*/
+use Carbon\Carbon;
+
/**
* Class Mage_Rule_Model_Environment
*
@@ -24,7 +26,7 @@ class Mage_Rule_Model_Environment extends Varien_Object
*/
public function collect()
{
- $this->setNow(time());
+ $this->setNow(Carbon::now()->getTimestamp());
Mage::dispatchEvent('rule_environment_collect', ['env' => $this]);
diff --git a/app/code/core/Mage/Sales/Model/Observer.php b/app/code/core/Mage/Sales/Model/Observer.php
index 60562b978d2..51891f58dad 100644
--- a/app/code/core/Mage/Sales/Model/Observer.php
+++ b/app/code/core/Mage/Sales/Model/Observer.php
@@ -7,6 +7,8 @@
* @package Mage_Sales
*/
+use Carbon\Carbon;
+
/**
* Sales observer
*
@@ -39,7 +41,7 @@ public function cleanExpiredQuotes()
/** @var Mage_Sales_Model_Resource_Quote_Collection $quotes */
$quotes = Mage::getResourceModel('sales/quote_collection');
$quotes->addFieldToFilter('store_id', $storeId);
- $quotes->addFieldToFilter('updated_at', ['to' => date('Y-m-d', time() - $lifetime)]);
+ $quotes->addFieldToFilter('updated_at', ['to' => Carbon::createFromTimestamp(Carbon::now()->getTimestamp() - $lifetime)->format('Y-m-d')]);
if ($day == 0) {
$quotes->addFieldToFilter('is_active', 0);
}
diff --git a/app/code/core/Mage/Shipping/Block/Tracking/Popup.php b/app/code/core/Mage/Shipping/Block/Tracking/Popup.php
index bac50a0afe4..246514520ae 100644
--- a/app/code/core/Mage/Shipping/Block/Tracking/Popup.php
+++ b/app/code/core/Mage/Shipping/Block/Tracking/Popup.php
@@ -7,6 +7,8 @@
* @package Mage_Shipping
*/
+use Carbon\Carbon;
+
/**
* Class Mage_Shipping_Block_Tracking_Popup
*
@@ -219,7 +221,7 @@ public function formatDeliveryDate($date)
{
$locale = Mage::app()->getLocale();
$format = $locale->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM);
- return $locale->date(strtotime($date), Zend_Date::TIMESTAMP, null, false)
+ return $locale->date(Carbon::parse($date)->getTimestamp(), Zend_Date::TIMESTAMP, null, false)
->toString($format);
}
@@ -239,7 +241,7 @@ public function formatDeliveryTime($time, $date = null)
$locale = Mage::app()->getLocale();
$format = $locale->getTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
- return $locale->date(strtotime($time), Zend_Date::TIMESTAMP, null, false)
+ return $locale->date(Carbon::parse($time)->getTimestamp(), Zend_Date::TIMESTAMP, null, false)
->toString($format);
}
diff --git a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php
index e26684137ad..fef1a35859d 100644
--- a/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php
+++ b/app/code/core/Mage/Tag/Model/Resource/Tag/Relation.php
@@ -7,6 +7,8 @@
* @package Mage_Tag
*/
+use Carbon\Carbon;
+
/**
* Tag Relation resource model
*
@@ -168,7 +170,7 @@ public function addRelations($model)
'store_id' => $model->getStoreId(),
'product_id' => $value,
'customer_id' => $model->getCustomerId(),
- 'created_at' => $this->formatDate(time()),
+ 'created_at' => $this->formatDate(Carbon::now()->getTimestamp()),
];
}
diff --git a/app/code/core/Mage/Tag/Model/Tag.php b/app/code/core/Mage/Tag/Model/Tag.php
index d4664926fa7..35100d4b53a 100644
--- a/app/code/core/Mage/Tag/Model/Tag.php
+++ b/app/code/core/Mage/Tag/Model/Tag.php
@@ -7,6 +7,8 @@
* @package Mage_Tag
*/
+use Carbon\Carbon;
+
/**
* Tag model
*
@@ -363,7 +365,7 @@ public function saveRelation($productId, $customerId, $storeId)
->setProductId($productId)
->setCustomerId($customerId)
->setActive(Mage_Tag_Model_Tag_Relation::STATUS_ACTIVE)
- ->setCreatedAt($relationModel->getResource()->formatDate(time()));
+ ->setCreatedAt($relationModel->getResource()->formatDate(Carbon::now()->getTimestamp()));
$result = '';
$relationModelSaveNeed = false;
diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php
index 94d7c256768..c6775f9fc54 100644
--- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php
+++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/Abstract.php
@@ -7,6 +7,8 @@
* @package Mage_Usa
*/
+use Carbon\Carbon;
+
/**
* DHL Abstract class
*
@@ -59,12 +61,12 @@ protected function _determineShippingDay($shippingDays, $date)
$shippingDays = explode(',', $shippingDays);
$index = 0;
- $weekday = date('D', strtotime($date));
+ $weekday = Carbon::parse($date)->format('D');
while (!in_array($weekday, $shippingDays) && $index < 10) {
$index++;
- $weekday = date('D', strtotime("$date +$index day"));
+ $weekday = Carbon::parse("$date +$index day")->format('D');
}
- return date(self::REQUEST_DATE_FORMAT, strtotime("$date +$index day"));
+ return Carbon::parse("$date +$index day")->format(self::REQUEST_DATE_FORMAT);
}
}
diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php
index 5fd7155e44c..cb2ae205532 100644
--- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php
+++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Dhl/International.php
@@ -7,6 +7,8 @@
* @package Mage_Usa
*/
+use Carbon\Carbon;
+
/**
* DHL International (API v1.4)
*
@@ -785,7 +787,7 @@ protected function _getQuotes()
$debugPoint = &$debugData['try-' . $offset];
$requestXml = $this->_buildQuotesRequestXml();
- $date = date(self::REQUEST_DATE_FORMAT, strtotime($this->_getShipDate() . " +$offset days"));
+ $date = Carbon::parse($this->_getShipDate() . " +$offset days")->format(self::REQUEST_DATE_FORMAT);
$this->_setQuotesRequestXmlDate($requestXml, $date);
$request = $requestXml->asXML();
diff --git a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php
index 8ace1b2a4c8..b82956f00d6 100644
--- a/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php
+++ b/app/code/core/Mage/Usa/Model/Shipping/Carrier/Fedex.php
@@ -7,6 +7,8 @@
* @package Mage_Usa
*/
+use Carbon\Carbon;
+
/**
* Fedex shipping implementation
*
@@ -313,7 +315,7 @@ protected function _formRateRequest($purpose)
'Version' => $this->getVersionInfo(),
'RequestedShipment' => [
'DropoffType' => $r->getDropoffType(),
- 'ShipTimestamp' => date('c'),
+ 'ShipTimestamp' => Carbon::now()->format('c'),
'PackagingType' => $r->getPackaging(),
'TotalInsuredValue' => [
'Amount' => $r->getValue(),
@@ -608,7 +610,7 @@ protected function _getXmlQuotes()
$requestHeader->addChild('AccountNumber', $r->getAccount());
$requestHeader->addChild('MeterNumber', '0');
- $xml->addChild('ShipDate', date('Y-m-d'));
+ $xml->addChild('ShipDate', Carbon::now()->format('Y-m-d'));
$xml->addChild('DropoffType', $r->getDropoffType());
if ($r->hasService()) {
$xml->addChild('Service', $r->getService());
@@ -1062,10 +1064,10 @@ protected function _parseTrackingResponse($trackingValue, $response)
$resultArray['status'] = (string) $trackInfo->StatusDescription;
$resultArray['service'] = (string) $trackInfo->ServiceInfo;
$timestamp = $trackInfo->EstimatedDeliveryTimestamp ?? $trackInfo->ActualDeliveryTimestamp;
- $timestamp = strtotime((string) $timestamp);
+ $timestamp = Carbon::parse((string) $timestamp)->getTimestamp();
if ($timestamp) {
- $resultArray['deliverydate'] = date('Y-m-d', $timestamp);
- $resultArray['deliverytime'] = date('H:i:s', $timestamp);
+ $resultArray['deliverydate'] = Carbon::createFromTimestamp($timestamp)->format('Y-m-d');
+ $resultArray['deliverytime'] = Carbon::createFromTimestamp($timestamp)->format('H:i:s');
}
$deliveryLocation = $trackInfo->EstimatedDeliveryAddress ?? $trackInfo->ActualDeliveryAddress;
@@ -1087,7 +1089,7 @@ protected function _parseTrackingResponse($trackingValue, $response)
}
$resultArray['signedby'] = (string) $trackInfo->DeliverySignatureName;
- $resultArray['shippeddate'] = date('Y-m-d', (int) $trackInfo->ShipTimestamp);
+ $resultArray['shippeddate'] = Carbon::createFromTimestamp((int) $trackInfo->ShipTimestamp)->format('Y-m-d');
if (isset($trackInfo->PackageWeight) && isset($trackInfo->Units)) {
$weight = (string) $trackInfo->PackageWeight;
$unit = (string) $trackInfo->Units;
@@ -1104,10 +1106,10 @@ protected function _parseTrackingResponse($trackingValue, $response)
foreach ($events as $event) {
$tempArray = [];
$tempArray['activity'] = (string) $event->EventDescription;
- $timestamp = strtotime((string) $event->Timestamp);
+ $timestamp = Carbon::parse((string) $event->Timestamp)->getTimestamp();
if ($timestamp) {
- $tempArray['deliverydate'] = date('Y-m-d', $timestamp);
- $tempArray['deliverytime'] = date('H:i:s', $timestamp);
+ $tempArray['deliverydate'] = Carbon::createFromTimestamp($timestamp)->format('Y-m-d');
+ $tempArray['deliverytime'] = Carbon::createFromTimestamp($timestamp)->format('H:i:s');
}
if (isset($event->Address)) {
@@ -1374,7 +1376,7 @@ protected function _formShipmentRequest(Varien_Object $request)
$paymentType = $request->getIsReturn() ? 'RECIPIENT' : 'SENDER';
$requestClient = [
'RequestedShipment' => [
- 'ShipTimestamp' => time(),
+ 'ShipTimestamp' => Carbon::now()->getTimestamp(),
'DropoffType' => $this->getConfigData('dropoff'),
'PackagingType' => $request->getPackagingType(),
'ServiceType' => $request->getShippingMethod(),
diff --git a/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml b/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml
index d40495d72c6..402e62cc7f4 100644
--- a/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml
+++ b/app/design/adminhtml/default/default/template/catalog/category/checkboxes/tree.phtml
@@ -12,7 +12,7 @@
*/
?>
-
+getTimestamp() ?>
- __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', date('Y')) ?>
+ __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', \Carbon\Carbon::now()->format('Y')) ?>
diff --git a/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml b/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml
index b8f24dac9b5..8f5e6dc2923 100644
--- a/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml
+++ b/app/design/adminhtml/default/default/template/oauth/authorize/reject.phtml
@@ -21,7 +21,7 @@
__('Rejection Of Authorization') ?>
getMessagesBlock()->toHtml() ?>
- __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', date('Y')) ?>
+ __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', \Carbon\Carbon::now()->format('Y')) ?>
diff --git a/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml b/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml
index b6111b6cfec..0a544dbec33 100644
--- a/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml
+++ b/app/design/adminhtml/default/default/template/widget/form/element/gallery.phtml
@@ -39,7 +39,7 @@ if (!is_null($this->getValues())): ?>
getValues()->getAttributeBackend()->getImageTypes() as $type): ?>
- ->getSourceUrl() ?>?<?php echo time() ?>)
+ ->getSourceUrl() ?>?<?php echo \Carbon\Carbon::now()->getTimestamp() ?>)
|
|
diff --git a/app/design/frontend/base/default/template/customer/orders.phtml b/app/design/frontend/base/default/template/customer/orders.phtml
index 193ee19ce13..bf54585d8bb 100644
--- a/app/design/frontend/base/default/template/customer/orders.phtml
+++ b/app/design/frontend/base/default/template/customer/orders.phtml
@@ -33,7 +33,7 @@
| getRealOrderId() ?> |
- getCreatedAt())) ?> |
+ getCreatedAt())->format("D, j M, Y") ?> |
getGrandTotal() ?> |
getStatus() ?> |
diff --git a/app/design/install/default/default/template/page.phtml b/app/design/install/default/default/template/page.phtml
index baf843ab171..e0a7783267d 100644
--- a/app/design/install/default/default/template/page.phtml
+++ b/app/design/install/default/default/template/page.phtml
@@ -95,7 +95,7 @@
$('bug_tracking_link').target = "varien_external";
//]]>
- __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', date('Y')) ?>
+ __('Magento is a trademark of Magento Inc. Copyright © %s Magento Inc.', \Carbon\Carbon::now()->format('Y')) ?>
diff --git a/get.php b/get.php
index 572e2d1788f..4eaa1f503c8 100644
--- a/get.php
+++ b/get.php
@@ -7,6 +7,8 @@
* @package Mage
*/
+use Carbon\Carbon;
+
$start = microtime(true);
/**
* Error reporting
@@ -56,7 +58,7 @@
$config = json_decode(file_get_contents($configCacheFile), true);
//checking update time
- if (filemtime($configCacheFile) + $config['update_time'] > time()) {
+ if (filemtime($configCacheFile) + $config['update_time'] > Carbon::now()->getTimestamp()) {
$mediaDirectory = trim(str_replace($bp . $ds, '', $config['media_directory']), $ds);
$allowedResources = array_merge($allowedResources, $config['allowed_resources']);
}
diff --git a/lib/Mage/Cache/Backend/File.php b/lib/Mage/Cache/Backend/File.php
index b03eb321f93..2937586fe35 100644
--- a/lib/Mage/Cache/Backend/File.php
+++ b/lib/Mage/Cache/Backend/File.php
@@ -35,6 +35,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+use Carbon\Carbon;
+
/**
* Optimized file cache backend
*
@@ -131,7 +133,7 @@ public function load($id, $doNotTestCacheValidity = false)
}
[$metadatas, $data] = $cache;
- if (!$doNotTestCacheValidity && time() > $metadatas['expire']) {
+ if (!$doNotTestCacheValidity && Carbon::now()->getTimestamp() > $metadatas['expire']) {
// ?? $this->remove($id);
return false;
}
@@ -188,7 +190,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
$metadatas = [
'hash' => $hash,
- 'mtime' => time(),
+ 'mtime' => Carbon::now()->getTimestamp(),
'expire' => $this->_expireTime($this->getLifetime($specificLifetime)),
'tags' => implode(',', $tags),
];
@@ -346,13 +348,13 @@ public function touch($id, $extraLifetime)
}
[$metadatas, $data] = $cache;
- if (time() > $metadatas['expire']) {
+ if (Carbon::now()->getTimestamp() > $metadatas['expire']) {
return false;
}
$newMetadatas = [
'hash' => $metadatas['hash'],
- 'mtime' => time(),
+ 'mtime' => Carbon::now()->getTimestamp(),
'expire' => $metadatas['expire'] + $extraLifetime,
'tags' => $metadatas['tags'],
];
@@ -516,7 +518,7 @@ protected function _clean($dir, $mode = Zend_Cache::CLEANING_MODE_ALL, $tags = [
}
if ($mode == Zend_Cache::CLEANING_MODE_OLD) {
- if (time() > $metadatas['expire']) {
+ if (Carbon::now()->getTimestamp() > $metadatas['expire']) {
$result = $this->_remove($file) && $result;
$result = $this->_updateIdsTags([$id], explode(',', $metadatas['tags']), 'diff') && $result;
}
diff --git a/lib/Varien/Cache/Backend/Database.php b/lib/Varien/Cache/Backend/Database.php
index d9d55c6fe4d..2d8b48c0ef2 100644
--- a/lib/Varien/Cache/Backend/Database.php
+++ b/lib/Varien/Cache/Backend/Database.php
@@ -30,6 +30,8 @@
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
+use Carbon\Carbon;
+
/**
* Database cache backend
*/
@@ -130,7 +132,7 @@ public function load($id, $doNotTestCacheValidity = false)
->where('id=:cache_id');
if (!$doNotTestCacheValidity) {
- $select->where('expire_time=0 OR expire_time>?', time());
+ $select->where('expire_time=0 OR expire_time>?', Carbon::now()->getTimestamp());
}
return $this->_getAdapter()->fetchOne($select, ['cache_id' => $id]);
@@ -151,7 +153,7 @@ public function test($id)
$select = $this->_getAdapter()->select()
->from($this->_getDataTable(), 'update_time')
->where('id=:cache_id')
- ->where('expire_time=0 OR expire_time>?', time());
+ ->where('expire_time=0 OR expire_time>?', Carbon::now()->getTimestamp());
return $this->_getAdapter()->fetchOne($select, ['cache_id' => $id]);
} else {
return false;
@@ -179,7 +181,7 @@ public function save($data, $id, $tags = [], $specificLifetime = false)
$dataTable = $this->_getDataTable();
$lifetime = $this->getLifetime($specificLifetime);
- $time = time();
+ $time = Carbon::now()->getTimestamp();
$expire = ($lifetime === 0 || $lifetime === null) ? 0 : $time + $lifetime;
$dataCol = $adapter->quoteIdentifier('data');
@@ -298,7 +300,7 @@ public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = [])
*/
protected function _cleanOldCache()
{
- $time = time();
+ $time = Carbon::now()->getTimestamp();
$counter = 0;
$result = true;
$adapter = $this->_getAdapter();
@@ -469,7 +471,7 @@ public function touch($id, $extraLifetime)
return $this->_getAdapter()->update(
$this->_getDataTable(),
['expire_time' => new Zend_Db_Expr('expire_time+' . $extraLifetime)],
- ['id=?' => $id, 'expire_time = 0 OR expire_time>?' => time()],
+ ['id=?' => $id, 'expire_time = 0 OR expire_time>?' => Carbon::now()->getTimestamp()],
);
} else {
return true;
diff --git a/lib/Varien/Date.php b/lib/Varien/Date.php
index e5b65a40dfc..e56f63200d5 100644
--- a/lib/Varien/Date.php
+++ b/lib/Varien/Date.php
@@ -7,6 +7,9 @@
* @package Varien_Date
*/
+use Carbon\Carbon;
+use Carbon\Exceptions\InvalidFormatException;
+
/**
* Converter of date formats
* Internal dates
@@ -106,7 +109,7 @@ protected static function _convert($value, $dictionary)
* Returns current UNIX timestamp if date is true
*
* @param string|true|Zend_Date $date
- * @return int
+ * @return false|int
*/
public static function toTimestamp($date)
{
@@ -115,10 +118,14 @@ public static function toTimestamp($date)
}
if ($date === true) {
- return time();
+ return Carbon::now()->getTimestamp();
}
- return strtotime($date);
+ try {
+ return Carbon::parse($date)->getTimestamp();
+ } catch (InvalidFormatException) {
+ return false;
+ }
}
/**
@@ -163,6 +170,6 @@ public static function formatDate($date, $includeTime = true)
}
$format = $includeTime ? self::DATETIME_PHP_FORMAT : self::DATE_PHP_FORMAT;
- return date($format, $date);
+ return Carbon::createFromTimestamp($date)->format($format);
}
}
diff --git a/lib/Varien/Db/Adapter/Mysqli.php b/lib/Varien/Db/Adapter/Mysqli.php
index 33deb8b8655..2103914e4d8 100644
--- a/lib/Varien/Db/Adapter/Mysqli.php
+++ b/lib/Varien/Db/Adapter/Mysqli.php
@@ -1,5 +1,7 @@
toString(self::ISO_DATE_FORMAT);
}
- return date(Varien_Db_Adapter_Pdo_Mysql::DATE_FORMAT, strtotime($date));
+ return Carbon::parse($date)->format(Varien_Db_Adapter_Pdo_Mysql::DATE_FORMAT);
}
public function convertDateTime($datetime)
@@ -119,7 +121,7 @@ public function convertDateTime($datetime)
return $datetime->toString(self::ISO_DATETIME_FORMAT);
}
- return date(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT, strtotime($datetime));
+ return Carbon::parse($datetime)->format(Varien_Db_Adapter_Pdo_Mysql::TIMESTAMP_FORMAT);
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
diff --git a/lib/Varien/Event/Observer/Cron.php b/lib/Varien/Event/Observer/Cron.php
index 9623759afc3..1aec878de22 100644
--- a/lib/Varien/Event/Observer/Cron.php
+++ b/lib/Varien/Event/Observer/Cron.php
@@ -7,6 +7,8 @@
* @package Varien_Event
*/
+use Carbon\Carbon;
+
/**
* Event cron observer object
*
@@ -47,7 +49,7 @@ public function isValidFor(Varien_Event $event)
public function getNow()
{
if (!$this->hasNow()) {
- $this->setNow(time());
+ $this->setNow(Carbon::now()->getTimestamp());
}
return $this->getData('now');
diff --git a/lib/Varien/Io/File.php b/lib/Varien/Io/File.php
index a3140338f5f..0da11f18679 100644
--- a/lib/Varien/Io/File.php
+++ b/lib/Varien/Io/File.php
@@ -7,6 +7,8 @@
* @package Varien_Io
*/
+use Carbon\Carbon;
+
/**
* Filesystem client
*
@@ -846,7 +848,7 @@ public function ls($grep = null)
}
$listItem['text'] = $entry;
- $listItem['mod_date'] = date(Varien_Date::DATETIME_PHP_FORMAT, filectime($fullpath));
+ $listItem['mod_date'] = Carbon::createFromTimestamp(filectime($fullpath))->format(Varien_Date::DATETIME_PHP_FORMAT);
$listItem['permissions'] = $this->_parsePermissions(fileperms($fullpath));
$listItem['owner'] = $this->_getFileOwner($fullpath);
diff --git a/tests/unit/Base/CarbonTest.php b/tests/unit/Base/CarbonTest.php
new file mode 100644
index 00000000000..6be7a7a1e89
--- /dev/null
+++ b/tests/unit/Base/CarbonTest.php
@@ -0,0 +1,48 @@
+format(Varien_Date::DATETIME_PHP_FORMAT),
+ );
+ }
+
+ /**
+ * @group Carbon
+ */
+ public function testTime(): void
+ {
+ self::assertSame(time(), Carbon::now()->getTimestamp());
+ }
+
+ /**
+ * @group Carbon
+ */
+ public function testStrtotime(): void
+ {
+ $dateString = '2024-01-15 14:30:00';
+ self::assertSame(strtotime($dateString), Carbon::parse($dateString)->getTimestamp());
+ }
+}
diff --git a/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php b/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php
index 47a1b69aff6..89d6d6737f5 100644
--- a/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php
+++ b/tests/unit/Traits/DataProvider/Mage/Core/Helper/DataTrait.php
@@ -10,6 +10,7 @@
namespace OpenMage\Tests\Unit\Traits\DataProvider\Mage\Core\Helper;
+use Carbon\Carbon;
use Generator;
trait DataTrait
@@ -18,9 +19,9 @@ public function provideFormatTimezoneDate(): Generator
{
/** @phpstan-ignore method.nonObject */
$date = date_create()->getTimestamp();
- $dateShort = date('n/j/Y', $date);
- $dateLong = date('F j, Y', $date);
- $dateShortTime = date('n/j/Y g:i A', $date);
+ $dateShort = Carbon::createFromTimestamp($date)->format('n/j/Y');
+ $dateLong = Carbon::createFromTimestamp($date)->format('F j, Y');
+ $dateShortTime = Carbon::createFromTimestamp($date)->format('n/j/Y g:i A');
yield 'null' => [
$dateShort,