2

Preconditions

  1. Magento 2.2.2, Nginx, Redis.
  2. Magento local timezone AEDT,
  3. server time AEDT
  4. mysql SELECT CURRENT_TIMESTAMP(); returns AEDT time
  5. SELECT @@global.time_zone, @@session.time_zone; returns SYSTEM.

Steps to reproduce

1. Go to Sales order grid 2. Apply purchase date range it should be a week or more in my case it's from 5-12-2018 to 12-12-2018 (7 days).

Expected result

1. It should display all orders in this range in my case it should show 42 orders.

Actual result

  1. Not displaying all order in from 5-12-2018 to 12-12-2018 (7 days), its showing 39 Order and the last order is 000153. See below screenshot for reference.

selection_123

  1. When I increase my date range in my case 4-12-2018 to 12-12-2018 (8 days) it's showing 3 more orders from 5-12-2018. See below screenshot for reference.

selection_124

2
  • I was faced same issue and debug to find cause of the Mirasvit_Report module conflict with the order date filter. I didn't need that module, then disabled to fixed date filter issue. May 29, 2019 at 9:41
  • You can check same third party or your custom added module disabled once and check. May 29, 2019 at 9:42

1 Answer 1

0

app/code/Vendor/Package/etc/adminhtml/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="plugin_datatype_date" type="Vendor\Package\Plugin\Date"/>
    </type>
</config>

app/code/Vendor/Package/Plugin/Date.php

<?php
namespace Vendor\Package\Plugin;

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;
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.