magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.55k stars 9.32k forks source link

work as the docs, i got an warning report when set timezone = false|true #30151

Closed khoailangthang-programing closed 3 years ago

khoailangthang-programing commented 4 years ago

Preconditions (*)

  1. M2.4.0
  2. PHP7.4
  3. Docs: https://devdocs.magento.com/guides/v2.4/ui_comp_guide/components/ui-datecolumn.html

Steps to reproduce (*)

  1. Create custom UI Listing with a date type column
  2. Or try modify core UI Listing (eg: sales_order_grid.xml, column created_at)
  3. Add config timezone as docs: <timezone>false</timezone> like this
<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date">
    <settings>
        <filter>dateRange</filter>
        <dataType>date</dataType>
        <label translate="true">Purchase Date</label>
        <sorting>desc</sorting>
        <timezone>false</timezone>
    </settings>
</column>
  1. Clear cache, reload page
  2. Open Inspect, tab Console

Expected result (*)

  1. No warning report in Console tab

Actual result (*)

  1. Got an console warning: moment-timezone-with-data.js:6 Moment Timezone has no data for false. See http://momentjs.com/timezone/docs/#/data-loading/
  2. SS https://imgur.com/rW7GdFV

Note

By the momentjs docs: https://momentjs.com/timezone/docs/ moment.tz() should take a param as region timezone as string instead of bool type (ex: Europe/Madrid)


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 4 years ago

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

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 give me 2.4-develop instance - upcoming 2.4.x release

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

Please, add a comment to assign the issue: @magento I am working on this


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

:movie_camera: You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

ilnytskyi commented 3 years ago

We got similar issue on customer_listing. @kamui23 have you managed to find any workaround ?

ilnytskyi commented 3 years ago

I think that in vendor/magento/module-ui/view/base/web/js/grid/columns/date.js this patch would work

            if (!this.timezone) {
                this.timezone = this.storeTimeZone;
            }
aarontalcott commented 3 years ago
--- a/vendor/magento/module-ui/view/base/web/js/grid/columns/date.js    (date 1608163508332)
+++ b/vendor/magento/module-ui/view/base/web/js/grid/columns/date.js    (date 1608163508332)
@@ -48,7 +48,7 @@

             date = moment.utc(this._super());

-            if (!_.isUndefined(this.timezone)) {
+            if (!_.isUndefined(this.timezone) && moment.tz.zone(this.timezone) !== null) {
                 date = date.tz(this.timezone);
             }
ilnytskyi commented 3 years ago

Another problem with this is that method

\Magento\Ui\Component\Listing\Columns\Date::prepareDataSource

tires to convert time on backend. Then module-ui/view/base/web/js/grid/columns/date.js would convert that time to UTC and apply the timezone, so we got wrong time on UI grids.

Workaround is to modify \Magento\Ui\Component\Listing\Columns\Date::prepareDataSource method

    public function getConfiguration()
    {
        $config = parent::getConfiguration();

        if (!isset($config['timezone'])) {
            $config['timezone'] = 'UTC'; //or date_default_timezone_get();
        }
        return $config;
    }

that would also fix problem in JS or just revert JS file to M2.3.4 version

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 14 days if no further activity occurs. Is this issue still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? Thank you for your contributions!

ilnytskyi commented 3 years ago

Up

magento-engcom-team commented 3 years ago

:white_check_mark: Confirmed by @engcom-Oscar Thank you for verifying the issue. Based on the provided information internal tickets MC-41877 were created

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

xtremevision commented 2 years ago

Same here, Magento 2.4.3-p1, happens in the admin customer grid, and a custom listing. The customer grid is no longer sorting the records ascending/descending, regardless of which column I click on.

MatthijsBreed commented 2 years ago

For whoever this helps, I've had the same issue after adding a custom customer attribute of the type date. However, after adding the following as view/adminhtml/ui_component/customer_listing.xml in my module, it works again:

<columns name="customer_columns">
    <column name="customer_first_order" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date" sortOrder="320">
        <settings>
            <timezone>false</timezone>
            <dateFormat>MMM d, y</dateFormat>
            <skipTimeZoneConversion>true</skipTimeZoneConversion>
            <filter>dateRange</filter>
            <dataType>date</dataType>
            <label translate="true">Customer First Order</label>
            <visible>false</visible>
        </settings>
    </column>
</columns>

My guess is that the skipTimeZoneConversion flag is what helps here