Skip to content

Date column UI component not functional with mysql type date, only compatible with datetime when date is empty in database (0000-00-00) #35619

Open
@sezio

Description

@sezio

Preconditions and environment

  • Magento version : 2.4.2-p1

Steps to reproduce

  1. Create a table with a date field in a db_schema.xml :
    <table name="test_table" resource="default" engine="innodb" comment="Test table">
        <column xsi:type="int" name="id" unsigned="true" nullable="false" identity="true" comment="Row ID"/>
        <column xsi:type="date" name="test_date" nullable="true" comment="Test date"/>
    </table>
  1. Create a new grid in backend with a column configured as follow :
        <column name="test_date" class="Magento\Ui\Component\Listing\Columns\Date" component="Magento_Ui/js/grid/columns/date" sortOrder="40">
            <settings>
                <filter>dateRange</filter>
                <dataType>date</dataType>
                <dateFormat>MMM d, YYYY</dateFormat>
                <label translate="true">My Date</label>
            </settings>
        </column>
  1. Insert a row in your table with the date value set to "0000-00-00" :
    insert into test_table(test_date) values("0000-00-00");

  2. Display your grid

Expected result

When displayed, the date column should not display any date as this is not a valid date.

Actual result

Magento calculates a date to "-0001-11-30 00:09:21" in \Magento\Ui\Component\Listing\Columns\Date::prepareDataSource

Additional information

The condition in \Magento\Ui\Component\Listing\Columns\Date::prepareDataSource to prevent a bad calculation of a datetime initialized to "0000-00-00 00:00:00" is the following :

                if (isset($item[$this->getData('name')])
                    && $item[$this->getData('name')] !== "0000-00-00 00:00:00"
                ) {
                    ...
                }

Therefore, it is strictly compatible with a datetime field and not with a date field.
To make it compatible with a date field, it should be something like :

                if (isset($item[$this->getData('name')])
                    && $item[$this->getData('name')] !== "0000-00-00 00:00:00"
                    && $item[$this->getData('name')] !== "0000-00-00"
                ) {
                    ...
                }

Also, Firefox won't display this date at all while Chrome displays it as the 11th january of 2030 :
Firefox :
image

Brave (also reproductible on chrome) :
image

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

Labels

Area: Admin UIComponent: BackendIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P3May be fixed according to the position in the backlog.Progress: dev in progressReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions