magento2: Magento 2.3.5 Wrong date on PDF invoice
Preconditions (*)
- Magento 2.3.5
Steps to reproduce (*)
- Go to Sales>Invoices>View>Print PDF invoice
Expected result (*)
- Invoice date on PDF file should be 08/05/2020 (today’s date)
Actual result (*)
- Did all the steps shown on this issue: #26675 and the error I am given is: `Could not apply patch! Skipping. The error was: Cannot apply patch patches/composer/267 01.diff
Installation failed, reverting ./composer.json to its original content.
[Exception]
Cannot apply patch 1.0 (patches/composer/26701.diff)! `
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 26 (12 by maintainers)
@alecx15
See topic: https://github.com/magento/magento2/issues/26675 And check my last comment like below.
I am using Magento 2.3.4
I have applied @edenduong’ code to the file located in; /vendor/magento/framework/Stdlib/DateTime/Timezone.php (line 196)
###############
public function scopeDate($scope = null, $date = null, $includeTime = false) { $timezone = new \DateTimeZone( $this->_scopeConfig->getValue($this->getDefaultTimezonePath(), $this->_scopeType, $scope) ); switch (true) { case (empty($date)): $date = new \DateTime(‘now’, $timezone); break; case ($date instanceof \DateTime): case ($date instanceof \DateTimeImmutable): $date = $date->setTimezone($timezone); break; default: $date = new \DateTime(is_numeric($date) ? ‘@’ . $date : $date); $date->setTimezone($timezone); break; }
} ###################
This corects dates on invoices. This works now for me. i updgraded to Magento 2.3.5-P1 and now it works. FInd the file with command: find . -name Timezone.php Result: ./vendor/magento/framework/Stdlib/DateTime/Timezone.php
I changed above in ./vendor/magento/framework/Stdlib/DateTime/Timezone.php And now it works 😃
This has been fixed in 2.4-develop in PR #26701. The bug exists in all 2.3 releases at the moment. Magento has stopped us targetting backports into 2.3 branch so whether this gets fixed in 2.3 at all is up to Magento and out of the hands of the community.
Recommendation is to apply fix from #26701 yourself into your local installation, until you either upgrade into 2.4 release whenever that happens, or it is backported into 2.3 by @magento-team.