Skip to content

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

Open

Description

@npielawski

Describe the bug
The doc shows that the Doctrine DateInterval should be a TextField in easy admin, but doing so breaks the page. There is a translation layer that is missing to go from a string to a DateInterval.

The exact error is:

The value of the "duration" field of the entity with ID = "1" can't be converted into a string, so it cannot be represented by a TextField or a TextareaField.

I just started using EasyAdmin, so I don't know if there is an easy solution. I tried to use formatValue, to no avail.

To Reproduce

  1. Create an entity which contains a DateInterval type variable
  2. Create a CRUD controller a configure the field to be a TextField.

Activity

  1. added this to the 4.x milestone on Jan 16, 2026
  2. javiereguiluz commented on Jan 25, 2026

    @javiereguiluz
    Collaborator

    I don't use intervals as values of entities so just asking: which would be the best way to handle these values? Just display them raw even if they are "cryptic" for most people? e.g. show P32D, P2Y4DT6H8M, etc.

  3. npielawski commented on Jan 25, 2026

    @npielawski
    Author

    Would converting those to text like "32 days" and "2 years 4 days 6 hours 8 minutes" be problematic (because of e.g. translation)?

    I created a new "DateIntervalField" and set the FormType to DateIntervalType::class, which creates a series of three combo boxes for years, months and days, when editing the period. Maybe this split between years, months and days should be reflected when serialized?

  4. javiereguiluz commented on Jan 26, 2026

    @javiereguiluz
    Collaborator

    Time interval patterns can be pretty complex according to the spec (see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals) so we cannot create a field that fully understands the spec, etc. It's too much.

    But, let's try at least to improve the current situation ... the minimum to make this work without losing information would be:

    • Use a raw input text in forms to set the interval pattern
    • Transform the pattern to text in detail/index pages

    Would that work?

  5. npielawski commented on Feb 10, 2026

    @npielawski
    Author

    Okay, I wasn't aware of how complex they get! And I am definitely not knowledgeable enough to take a decision here.

  6. Amoifr commented on May 5, 2026

    @Amoifr
    Contributor

    Hi @javiereguiluz! 👋

    Took a swing at this in #7596 following your plan: single-text ISO 8601 input in forms (powered by Symfony's built-in DateIntervalType), and a localized, pluralized rendering on index/detail (2 years 4 days 6 hours 8 minutes) using date_interval.* translation keys across all 38 locales. Per-field setFormat() and Crud::setDateIntervalFormat() still let users opt into a raw DateInterval::format() if they prefer.

    Also fixed the misleading TextField recommendation in the Doctrine type mapping table along the way. 😄

    Happy to iterate if anything needs tweaking!

  7. added a commit that references this issue on Sep 20, 2026
    9620a31
  8. added a commit that references this issue on Oct 2, 2026
    fb05945
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions