Description
Preconditions and environment
- Magento version : 2.4.2-p1
Steps to reproduce
- 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>
- 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>
-
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");
-
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 :
Brave (also reproductible on chrome) :
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”.