Date field is not displaying correct value on a views with aggregation max/min

Created on 15 June 2020, over 4 years ago
Updated 26 April 2024, 8 months ago

I have users and deliveries, in a view I need to display a list of users, last delivery date and number of deliveries per user.
Adding aggregation to view works fine but max(field_delivery_date) displays only year.

User ID	Last/Next Delivery	Number of deliveries
26	2020	4
2224	2020	3
1195	2020	3

* field_delivery_date is of datetime_default type
* if I use max(created) view displays proper date (as it's timestamp and not actually a date)
* Database returns proper date (if I run a debug in [my_module]_views_pre_render $result->field_users_delivery_users_field_data__node__field_delivery_date_fi it returns a proper date)

Reason for this issue is in display handler is changed to Numeric for any grouped field (max, min, count, etc):
https://git.drupalcode.org/project/drupal/-/blob/8.9.x/core/modules/view...

Min/Max aggregations should be mindful of the field type they apply (as datetime actually can have min/max date).

Same issue applies to Drupal 7/9.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
ViewsΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia jannakha Brisbane!

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany pebosi

    Patch #12 worked for me too.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

    Still needs an automated test to show what we are fixing

  • πŸ‡¦πŸ‡ΉAustria maxilein

    Does this apply to D10 as well?

  • πŸ‡ΊπŸ‡ΈUnited States maskedjellybean Portland, OR

    Thank you. #12 worked for me in Drupal 10.2.3.

    It allowed me to aggregate using a date_recur field in a view of occurrences. I set the start date to aggregate using Min and the end date to aggregate using Max. This gave me one row for each event, and each row displayed the date of the first occurrence and the last occurrence. Exactly what I needed. Before applying the patch I saw this error:

    TypeError: round(): Argument #1 ($num) must be of type int|float, string given in round() (line 173 of /app/docroot/core/modules/views/src/Plugin/views/field/NumericField.php)

  • πŸ‡¬πŸ‡§United Kingdom oily Greater London

    andrew.farquharson β†’ made their first commit to this issue’s fork.

  • πŸ‡ΊπŸ‡ΈUnited States karlshea Minneapolis πŸ‡ΊπŸ‡Έ

    Unfortunately this breaks min/max aggregation for datetime sorting.

Production build 0.71.5 2024