Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Refactor datetime class #26538

Merged

Conversation

Tjitse-E
Copy link
Contributor

@Tjitse-E Tjitse-E commented Jan 26, 2020

Description (*)

When creating a console command that uses \Magento\Framework\Stdlib\DateTime\DateTime, the integration test suite will fail. This is because the constructor of this class does a call to the DB via the getConfigTimezone() method:

   public function __construct(TimezoneInterface $localeDate)
    {
        $this->_localeDate = $localeDate;
        $this->_offset = $this->calculateOffset($this->_localeDate->getConfigTimezone());
    }

I propose that we refactor this class, so this call is done in the getGmtOffset() method. I don't see any downsides to this, but let me know if I've missed any.

Fixed Issues (if relevant)

Related issue: baldwin-agency/magento2-module-url-data-integrity-checker#2

Manual testing scenarios (*)

  1. Create a new module with a console command.
  2. Inject an instance of \Magento\Framework\Stdlib\DateTime\DateTime in the console command class via DI.
  3. Run the integration testing suite. Normally this will fail. If you apply the commits from this PR it will pass.

Questions or comments

I thought about leaving private $_offset intact. But it isn't used anywhere else than in getGmtOffset(), so i've removed this.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@Tjitse-E Tjitse-E requested a review from YevSent as a code owner January 26, 2020 14:10
@m2-assistant
Copy link

m2-assistant bot commented Jan 26, 2020

Hi @Tjitse-E. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Guide documentation.

@Tjitse-E
Copy link
Contributor Author

@joni-jones the code styling issues are resolved.

Copy link
Contributor

@aleron75 aleron75 left a comment

Choose a reason for hiding this comment

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

the constructor of this class does a call to the DB via the getConfigTimezone() method

doing this calculation in constructor also violates the best practice of using constructors only for assignments so for me, this contribution is very appreciated

@magento-engcom-team
Copy link
Contributor

Hi @aleron75, thank you for the review.
ENGCOM-7155 has been created to process this Pull Request
✳️ @aleron75, could you please add one of the following labels to the Pull Request?

Label Description
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests
Auto-Tests: Not Covered Changes in Pull Request requires coverage by auto-tests
Auto-Tests: Not Required Changes in Pull Request does not require coverage by auto-tests

@engcom-Alfa engcom-Alfa self-assigned this Mar 23, 2020
@engcom-Alfa engcom-Alfa added the Auto-Tests: Covered All changes in Pull Request is covered by auto-tests label Mar 23, 2020
@engcom-Alfa
Copy link
Contributor

✔️ QA Passed

@magento-engcom-team magento-engcom-team merged commit 84e6108 into magento:2.4-develop Mar 25, 2020
@m2-assistant
Copy link

m2-assistant bot commented Mar 25, 2020

Hi @Tjitse-E, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@Tjitse-E Tjitse-E deleted the refactor-datetime-class branch July 15, 2020 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants