Skip to content

rector: Replace php date functions, Varien_Date with Carbon date library #4463

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented Jan 8, 2025

Description (*)

Use https://carbon.nesbot.com/docs/.

#3594 (comment)

I think its a bit more then "YetAnotherDateTime".

Currently we have ...

  • basic date funtions (mktime(), date(), ...)
  • Varien_Date
  • Zend_Date
  • Mage_Locale

This could be unified.

Carbon provides some usefull date operation (compare dates, add or subsract seconds/hours/days) that make writing code easier. Zend_Date, DateTime etc have similar, but its all mixed up.

(Plus. Rectors supports t. :) )

@Hanmac finally it should replace Zend_Date at all, but i'd start with Varien_Date etc first.

Edit: PR is based on #4454, that should be merge first.

@sreichel sreichel changed the title Replace php date functions, Varien_Date with Carbon library Replace php date functions, Varien_Date with Carbon date library Jan 8, 2025
@fballiano
Copy link

carbon requires all these components

"carbonphp/carbon-doctrine-types": "<100.0",
"psr/clock": "^1.0",
"symfony/clock": "^6.3 || ^7.0",
"symfony/polyfill-mbstring": "^1.0",
"symfony/translation": "^4.4.18 || ^5.2.1|| ^6.0 || ^7.0"

dependencies growth should be taken in deep consideration.

I agree with @Hanmac #3594 (comment)

@ajbonner
Copy link

Aside from dependencies performance should also be considered. Zend_Date / Locale handling is extremely slow. There ought to be significant benefits getting away from those, but would be interesting to quantify effects.

@Hanmac
Copy link
Contributor

Hanmac commented Jan 10, 2025

Aside from dependencies performance should also be considered. Zend_Date / Locale handling is extremely slow. There ought to be significant benefits getting away from those, but would be interesting to quantify effects.

The only interesting part of Zend is the "Additional Data",
like postalCodeData and telephoneCodeData

@sreichel
Copy link
Contributor Author

carbon requires all these components

"carbonphp/carbon-doctrine-types": "<100.0",
"psr/clock": "^1.0",
"symfony/clock": "^6.3 || ^7.0",
"symfony/polyfill-mbstring": "^1.0",
"symfony/translation": "^4.4.18 || ^5.2.1|| ^6.0 || ^7.0"

dependencies growth should be taken in deep consideration.

I agree with @Hanmac #3594 (comment)

We have added https://packagist.org/packages/pelago/emogrifier for single usage. That requires +2

  • sabberworm/php-css-parser
  • symfony/css-selector

Now we are talking about a complete replacement of Varien_Date (later Zend_Date) adding +2

  • symfony/clock
  • symfony/translation
  • ... psr/clock is a sub-dependency and symfony/polyfill-mbstring is already installed

Just to mention ...

Zend_Date / Locale handling is extremely slow

At the moment it is about ro replace Varien_Date. When it comes to Zend_Date / Locale handling i'll provide some tests. (btw. DDEV+XHGUI is easy to use. Feel free.)

The only interesting part of Zend is the "Additional Data",
like postalCodeData and telephoneCodeData

Both are part of Zend_Locale. "telephoneCodeData" was updated last in 2013 and isnt up to date. There are better libraries if needed. E.g. https://github.com/giggsey/libphonenumber-for-php

I'd be happy if we can get away from outdouted code. ZF1Future does its best to keep it alive, but it is outdated. There are no successors for Zend_Date/Zend_Locale in Zend2/lamininas.

@fballiano
Copy link

We have added https://packagist.org/packages/pelago/emogrifier for single usage. That requires +2

we didn't add emogrifier, it was a part of magento since way before, when I worked on it we just updated it.

@sreichel
Copy link
Contributor Author

Nitpicking?

We replaced bundled Emogrifier with updated composer-version - accecpting install additional dependencies w/o worriers.

Now you complain about 2 other dependencies - to make a much bigger step?

@sreichel
Copy link
Contributor Author

@fballiano

As long as I am blocked by you, i'd like you to not comment on any of my PRs/issues/whatever here! Thank you

@fballiano
Copy link

Nitpicking?

We replaced bundled Emogrifier with updated composer-version - accecpting install additional dependencies w/o worriers.

it's not nitpicking, we couldn't remove that because it would be BC and we chose to upgrade it, correctly.

that doesn't mean that you should add dependencies for everything.

this is a constructive criticism, growth in dependencies should be considered, that's the only thing I said, and you got defensive.

@sreichel sreichel closed this Mar 3, 2025
@sreichel sreichel reopened this Mar 13, 2025
@github-actions github-actions bot added Component: PayPal Relates to Mage_Paypal Component: Core Relates to Mage_Core Component: Catalog Relates to Mage_Catalog Component: Cms Relates to Mage_Cms Component: Reports Relates to Mage_Reports labels Mar 13, 2025
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

sreichel added 2 commits June 19, 2025 04:16
# Conflicts:
#	.phpstan.dist.baseline.neon
#	composer.lock
#	lib/Varien/Cache/Backend/Database.php
#	tests/unit/Mage/Catalog/Model/UrlTest.php
#	tests/unit/Mage/Sitemap/Model/SitemapTest.php
@github-actions github-actions bot added Template : admin Relates to admin template Template : base Relates to base template Mage.php Relates to app/Mage.php Component: Widget Relates to Mage_Widget Component: Shipping Relates to Mage_Shipping Template : install Relates to install template rector labels Jun 19, 2025
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@joshua-bn
Copy link
Contributor

I am confused by the description regarding "Rector". Was this (or is this) being done with a Rector? It should be doable and not that difficult to do with Rector or nikic/php-parser

@sreichel
Copy link
Contributor Author

Most changes where made with rector.

@joshua-bn
Copy link
Contributor

Most changes where made with rector.

If you're making changes with Rector or some other tool, it's helpful to see that in the PR. I review that first to make sure the logic is correct. If you have 1000 files that are changed with Rector, nobody is going to review all of them.

@sreichel sreichel changed the title Replace php date functions, Varien_Date with Carbon date library rector: Replace php date functions, Varien_Date with Carbon date library Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Admin Relates to Mage_Admin Component: Adminhtml Relates to Mage_Adminhtml Component: AdminNotification Relates to Mage_AdminNotification Component: Api PageRelates to Mage_Api Component: Api2 Relates to Mage_Api2 Component: Authorizenet Relates to Mage_Authorizenet Component: Captcha Relates to Mage_Captcha Component: Catalog Relates to Mage_Catalog Component: CatalogIndex Relates to Mage_CatalogIndex Component: CatalogInventory Relates to Mage_CatalogInventory Component: CatalogRule Relates to Mage_CatalogRule Component: CatalogSearch Relates to Mage_CatalogSearch Component: Checkout Relates to Mage_Checkout Component: Cms Relates to Mage_Cms Component: Core Relates to Mage_Core Component: Cron Relates to Mage_Cron Component: Customer Relates to Mage_Customer Component: Dataflow Relates to Mage_Dataflow Component: Eav Relates to Mage_Eav Component: ImportExport Relates to Mage_ImportExport Component: Index Relates to Mage_Index Component: Install Relates to Mage_Install Component: lib/Mage Relates to lib/Mage Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* Component: Log Relates to Mage_Log Component: Oauth Relates to Mage_Oauth Component: Payment Relates to Mage_Payment Component: PayPal Relates to Mage_Paypal Component: Reports Relates to Mage_Reports Component: Rss Relates to Mage_Rss Component: Rule Relates to Mage_Rule Component: Sales Relates to Mage_Sales Component: SalesRule Relates to Mage_SalesRule Component: Shipping Relates to Mage_Shipping Component: Tag Relates to Mage_Tag Component: Usa Relates to Mage_Usa Component: Weee Relates to Mage_Weee Component: Widget Relates to Mage_Widget Component: Wishlist Relates to Mage_Wishlist composer Relates to composer.json enhancement Mage.php Relates to app/Mage.php phpstan phpunit rector Template : admin Relates to admin template Template : base Relates to base template Template : install Relates to install template
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants