Magento2: dd/mm mm/yy Sales order grid Date Filters not working in en_GB locale

Created on 5 Apr 2019  ·  18Comments  ·  Source: magento/magento2

Preconditions (*)

  1. Magento 2.2-develop or 2.3-develop
  2. Deploy using locale en_GB
  3. Change admin locale to en_GB

Steps to reproduce (*)

  1. Create test product and create test order
  2. View Sales order grid
  3. Set a date filter to include the order date in From and To

Expected result (*)

  1. Order should be visible

Actual result (*)

  1. Order is not visible

In my test case, 5th April 2019 was the date of the order.
Dates entered in filter box are From : 05/04/2019 To : 05/04/2019

This applies to locale en_GB but I suspect it also applies to all locales that use dd/mm date format.

Sales Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.2.x Reproduced on 2.3.x good first issue

All 18 comments

Hi @gwharton. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [x] Summary of the issue
  • [x] Information on your environment
  • [x] Steps to reproduce
  • [x] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me 2.3-develop instance - upcoming 2.3.x release

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

@gwharton do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [x] yes
  • [ ] no

Confirmed on vanilla 2.2-develop and 2.3-develop

On my production store which has many many orders, if I enter the dates 01/04/2019 to 31/04/2019, I was expecting to see all April's orders. Instead I see orders from 4th January to 4th May (well actually, 4th of the current month!).

This confirms a mm/dd dd/mm issue.

Also bump for #10663 which remains unresolved a year and a half after opening and may be related, infact, could be the underlying cause for all of the timezone issues, that have had hacks added to make work.

@gwharton : This will work when both the timezones are equal Server's time and Magento's timezone! After hours of investigation, I found that Magento\Ui\Component\Listing\Columns\Date somehow its converting the date in timezone and displaying in the grid!

My server timezone, php.ini timezone, magento timezone are the same. This is new behaviour since the 2.2.8 update.

We experienced similar issues in older versions ( e.g 2.2.6 ) when _Admin > My Account > Interface Locale_ was set to en_AU or en_GB. If you set it back to en_US you should be able to filter your sales order grid table normally. This will affect your admin account settings only, not the global locate settings. Just a temporary solution which requires further investigation.

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

:white_check_mark: Confirmed by @engcom-backlog-nazar
Thank you for verifying the issue. Based on the provided information internal tickets MAGETWO-99241, MAGETWO-99242 were created

Issue Available: @engcom-backlog-nazar, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

I am working on this at #dmcdindia19”

Hi @Madhumalak. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

Confirmed on 2.3.1

Hi @yrobag. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:

  • [ ] 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.
  • [ ] 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 3. If the issue is not relevant or is not reproducible any more, feel free to close it.


@gwharton thanks for this fix.
But even with this fix there is still a problem with the date filter. Filtering from 01/12 to 31/12 also returns orders from 30/11.

@amelojunior You might want to test this additional patch for filters:

--- Component/Filters/Type/Date.php (date 1588266305705)
+++ Component/Filters/Type/Date.php (date 1588266305705)
@@ -43,7 +43,12 @@
         $this->wrappedComponent = $this->uiComponentFactory->create(
             $this->getName(),
             static::COMPONENT,
-            ['context' => $this->getContext()]
+            [
+                'context' => $this->getContext(),
+                'data' => isset($this->getConfiguration()['dateFormat'])
+                    ? ['config' => ['options' => ['dateFormat' => $this->getConfiguration()['dateFormat']]]]
+                    : []
+            ]
         );
         $this->wrappedComponent->prepare();
         // Merge JS configuration with wrapped component configuration

It's still another dirty hack because some things do not seem to be very clear in the framework regarding the handling of config values between the Column and the Filter objects.

Replace below file line in magento ver 2.3.2, after replace filter working fine.

vendor/magento/module-ui/Component/Form/Element/DataType/Date.php
function convertDate

$dateObj = $this->localeDate->date(
new \DateTime(
$date,
new \DateTimeZone($this->localeDate->getConfigTimezone())
),
$this->getLocale(),
true
);

Replace To

$dateObj = $this->localeDate->date($date, $this->getLocale(), true);

Using the solutions above, I've created a plugin for that. It did fix the issue:

etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Ui\Component\Form\Element\DataType\Date">
        <plugin name="vendor_package_plugin_datatype_date" type="Vendor\Package\Plugin\Component\Form\Element\DataType\Date"/>
    </type>
</config>

Then, the plugin Vendor\Package\Plugin\Component\Form\Element\DataType\Date

<?php
namespace Vendor\Package\Plugin\Component\Form\Element\DataType;

use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
use Magento\Ui\Component\Form\Element\DataType\Date as DateDataType;

/**
 * Class Date
 */
class Date
{
    /**
     * @var TimezoneInterface
     */
    private $localeDate;

    /**
     * Date constructor.
     * @param TimezoneInterface $localeDate
     */
    public function __construct(
        TimezoneInterface $localeDate
    ) {
        $this->localeDate = $localeDate;
    }

    /**
     * Convert given date to default (UTC) timezone
     *
     * @param DateDataType $subject
     * @param callable $proceed
     * @param $date
     * @param int $hour
     * @param int $minute
     * @param int $second
     * @param bool $setUtcTimeZone
     * @return \DateTime|null
     */
    public function aroundConvertDate(DateDataType $subject, callable $proceed, $date, $hour = 0, $minute = 0,
        $second = 0, $setUtcTimeZone = true)
    {
        try {
            $dateObj = $this->localeDate->date($date, $subject->getLocale(), true);

            $dateObj->setTime($hour, $minute, $second);
            //convert store date to default date in UTC timezone without DST
            if ($setUtcTimeZone) {
                $dateObj->setTimezone(new \DateTimeZone('UTC'));
            }
            return $dateObj;
        } catch (\Exception $e) {
            return null;
        }
    }
}

That's it.

Was this page helpful?
0 / 5 - 0 ratings