Skip to content

Add DateIntervalField for editable, localized DateInterval rendering#7596

Open
Amoifr wants to merge 1 commit intoEasyCorp:5.xfrom
Amoifr:fix_7374
Open

Add DateIntervalField for editable, localized DateInterval rendering#7596
Amoifr wants to merge 1 commit intoEasyCorp:5.xfrom
Amoifr:fix_7374

Conversation

@Amoifr
Copy link
Copy Markdown
Contributor

@Amoifr Amoifr commented May 5, 2026

Fix #7374

Storing a DateInterval (Doctrine dateinterval type) in a TextField currently breaks the page with The value of the "..." field can't be converted into a string. The doc itself recommended TextField for this Doctrine type, which doesn't actually work.

This PR introduces a dedicated DateIntervalField, following the plan @javiereguiluz outlined in the issue:

  • Forms (new/edit): a single text input expecting an ISO 8601 duration pattern (P1Y2M3D, PT1H30M, etc.). Powered by Symfony's built-in DateIntervalType with widget => single_text and input => dateinterval, so we don't have to maintain a custom transformer.
  • Read-only pages (index/detail): a localized, pluralized rendering of the duration (2 years 4 days 6 hours 8 minutes). Each part uses a date_interval.* translation key with the standard Symfony pluralization syntax ({1} %count% year|]1,Inf] %count% years), so locales handle their own grammar.

Per-field opt-out: setFormat('%y years…') falls back to raw DateInterval::format(). Same applies to Crud::setDateIntervalFormat(), which existed already as a stub but was never read by anything.

Other changes in this PR:

  • doc/fields.rst: the Doctrine dateinterval row now points to DateIntervalField instead of the (broken) TextField recommendation, and the new field is added to the field list.
  • doc/fields/DateIntervalField.rst: new dedicated doc page.
  • translations/EasyAdminBundle.{en,fr}.php + 36 other locales: new date_interval.* keys (English placeholder for non-EN/FR per AGENTS.md guidance).
  • src/Dto/CrudDto::$dateIntervalFormat: default switched from the (unused) hardcoded English string to null, so the configurator can distinguish "no override → render localized" from "explicit format → raw DateInterval::format()". The public Crud::setDateIntervalFormat(string) signature is unchanged.

Test plan

  • tests/Unit/Field/DateIntervalFieldTest.php: 5 new tests cover null value, no-format → sentinel + value preserved, per-field setFormat(), template pluralization (1 year + 2 months + 3 days + 4 hours + 5 minutes + 6 seconds), and zero-duration empty label.
  • All tests/Unit/Field/ (610 tests) pass.
  • pdo_sqlite was unavailable in my local env, so the existing functional DateIntervalFormatTest (which already only asserts the page renders) wasn't run here, but it still relies on the same Crud::setDateIntervalFormat() API I left untouched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DateInterval as a textfield creates issues and can't be edited.

1 participant