Review main Merged

82093[BUGFIX] Fix initialization of 00:00 time input

Imko Schumacher CR +2 V +2 Normal +173 −4 updated 06/03/24, 07:54

Commit message

The value of the `time` input is sent as an ISO date to the
FormEngine, except for the time "00:00", which is just submitted
as "0".

This has lead to the input field not getting populated by
the JavaScript initialization, and the input "00:00" was lost.

In cases where such a `time` input is set as a required
field, the validation would then fail because of the field
getting interpreted as being empty/unset.

With this patch, a "0" value is also interpreted as a valid
"1970-01-01T00:00:00+00:00" string, that is parseable by
FormEngine. Note this only affects display within the
FormEngine; the format of the stored data is not changed
(converted by DataHandler to proper values and covered by
existing tests).

IMPORTANT: This only applies to NULLABLE time|timesec
inputs. Only for this configuration it is possible to
decide, that a stored "0" value in the database is
actually "00:00" and not an unset entry.

Integrators/developers need to set 'nullable'
TCA key to 'true' of the corresponding 'config' array,
in case they want to make a time/timesec input picker
be able to store and retrieve "00:00" as a valid
timestamp.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Garvin Hicking +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 2

Review log 3040

Show 1015 earlier messages
  1. Imko Schumacher uploaded patch set 1 12/05/23, 19:23

  2. core-ci voted on patch set 1 V +1 12/05/23, 19:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/50394

  3. Garvin Hicking commented on patch set 1 V +1 12/06/23, 08:12

    Very nice catch! Tried the patch and indeed it works. This issue existed for ages, odd that it wasn't addressed yet :-O Would you be able to add Tests for that specific scenario, to get a test that fails on the current setup and succeeds with your patch applied? (Something along the lines of https://review.typo3.org/c/Packages/TYPO3.CMS/+/81645/13/typo3/sysext/core/Tests/Acceptance/Application/FormEngine/ElementsEmptyElementsCest.php - don't know if it's possible to test it with a functional test like for DataHandler)
  4. Imko Schumacher commented on patch set 1 12/17/23, 16:58

    Reply

    I currently don't have the capacity to provide a functional tests.
  5. Garvin Hicking commented on patch set 1 12/17/23, 17:09

    Reply

    Thanks for the response. I'll try to add one and add it to your patch here.
  6. Benni Mack updated the commit message in patch set 2 V +1 01/08/24, 20:11

  7. core-ci voted on patch set 2 V +1 01/08/24, 20:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/51285

  8. Garvin Hicking commented on patch set 2 01/08/24, 20:18

    (Note: I still have it on my radar, but will probably only find time at the end of the month to work on it. If anyone else wants to add a test before that, please go ahead - but I think we should add it to prevent future regressions with this)
  9. Garvin Hicking uploaded patch set 3 V +1 04/05/24, 15:30

    Add test
  10. core-ci voted on patch set 3 V -1 04/05/24, 15:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55392

  11. Garvin Hicking commented on patch set 3 04/05/24, 15:37

    Hhm. Just after I submitted this, I saw a problem that tunnelvision hid from me. The problem is now (and already before) that we cannot discern a "00:00" entered timestamp from a "0" stored empty timestamp. Previously, this was interpreted as "yup, this is not set". With this fix, s aved value (!) is interpreted as "hey, 0 is actually 01.01.1970 00:00 and a set value". So, for a stored record with a "0" in a timestamp field, it will now be displayed as "00:00" and not "(empty)". For a "fresh" unsaved record without data retrieval from the database, the fields will properly be uninitialized. I suppose one could be able to use a NULLable field and set a time to NULL then, but this could be interpreted as a breaking change, if that would be required. On the other hand, the current situation can be considered a bug, because you will "lose data" when editing a record you intentionally saved with a "00:00" timestamp, if validation/required fields are utilized.
  12. Garvin Hicking uploaded patch set 4 V -1 04/05/24, 15:38

    cgl
  13. core-ci voted on patch set 4 V -1 04/05/24, 15:44 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55393

  14. core-ci voted on patch set 4 V +1 04/05/24, 15:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55393

  15. Garvin Hicking commented on patch set 4 04/05/24, 16:57

    Reply

    Note to next-week future me: That thought about NULLing could be a way. Make required fields nullable, so that only only for these fields the "00:00" value is stored when (int)$value === 0. Because on those fields we can differ between 0 (00:00) and NULL (no value yet). Question is only if we can fetch db stored value and differ between NULL and 0, or if its too late for that by then. That way wouldn't break BC arguably, and could still allow "require" a set field. For non nullable fields reverting from "00:00" to "" (0) should both result in being able to save and retrieve "0". People affected by this would need to change their fields to being nullable, but I think that's fair and understandable if one thinks about it? So, future Garvin: Test if this does work, or if NULLing timefields opens another can of worms.
  1. Garvin Hicking uploaded patch set 5 V +1 04/08/24, 09:29

    Evaluate nullable
  2. Garvin Hicking commented on patch set 5 04/08/24, 09:30

    Hi all and me. I think with "NULLABLE" this works well enough. Not sure if an Important RST might be needed.
  3. core-ci voted on patch set 5 V +1 04/08/24, 09:34 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55548

  4. Garvin Hicking commented on patch set 5 CR +1 V +1 04/08/24, 11:24

    Reply

    Done
  5. Andreas Kienast voted on patch set 5 CR +1 04/08/24, 11:46

  6. Andreas Kienast uploaded patch set 6 CR +1 V +1 04/08/24, 11:51

  7. core-ci voted on patch set 6 V +1 04/08/24, 11:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55557

  8. Andreas Kienast voted on patch set 6 CR +1 V +1 04/08/24, 11:56

  9. Garvin Hicking voted on patch set 6 CR +1 V +1 04/10/24, 11:46

  10. Jörg Bösche voted on patch set 6 CR +1 04/11/24, 12:56

  11. Benjamin Franzke commented on patch set 6 04/23/24, 06:33

    DatetimeElement.php:187

    This condition is hard to understand. We actually mean: ``` if ( (int)$itemValue > 0 || ((int)$itemValue === 0 && $config['nullable'] ?? false) ) { … } ``` I know that the current condition is more optimized, but I think it is important to express the intend of the business logic. Optimization will be done by PHP anyway.

    DatetimeElement.php:191

    case

    DatetimeElement.php:192

    or

    DatetimeElement.php:193

    casted
  12. Garvin Hicking uploaded patch set 7 CR +1 V +1 04/23/24, 10:19

    Better condition readability
  13. Garvin Hicking commented on patch set 6 CR +1 V +1 04/23/24, 10:22

    DatetimeElement.php:187 Reply

    Thanks. This is a good improvement! I adjusted it to !== 0 and not just > 0 because I'm actually not sure if negative integers should also trigger this properly...

    DatetimeElement.php:191 Reply

    Done

    DatetimeElement.php:192 Reply

    Done

    DatetimeElement.php:193 Reply

    "cast" is an irregular verb and thus the past participle form is more commonly used as "cast" instead of "casted", so even though "casted" isn't wrong, it's a much less commonly used form, if that's ok with you to keep 😊
  14. core-ci voted on patch set 7 V -1 04/23/24, 10:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56561

  15. Garvin Hicking uploaded patch set 8 V -1 04/23/24, 10:26

    Missing braces
  16. core-ci voted on patch set 8 V +1 04/23/24, 10:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56562

  17. Garvin Hicking voted on patch set 8 CR +1 V +1 04/25/24, 07:45

  18. Simon Schaufelberger voted on patch set 8 CR +1 05/16/24, 09:22

  19. Benjamin Franzke uploaded patch set 9 CR +1 V +1 06/03/24, 06:18

  20. Benjamin Franzke commented on patch set 9 06/03/24, 06:18

    DatetimeElement.php:193 Reply

    ack, lets write "casts to int", "be" still feels odd here.
  21. Benjamin Franzke voted on patch set 9 V +1 06/03/24, 06:20

  22. core-ci voted on patch set 9 V +1 06/03/24, 06:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58607

  23. Garvin Hicking commented on patch set 9 CR +1 V +1 06/03/24, 06:32

    DatetimeElement.php:193 Reply

    Thanks for the rework, that's better! :)
  24. Benjamin Franzke voted on patch set 9 CR +2 V +2 06/03/24, 07:47

  25. Benjamin Franzke merged patch set 10 06/03/24, 07:54