You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DateInterval as a textfield creates issues and can't be edited. #7374
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
Create an entity which contains a DateInterval type variable
Create a CRUD controller a configure the field to be a TextField.
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.
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?
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. 😄
Activity
javiereguiluz commentedon Jan 25, 2026
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.npielawski commentedon Jan 25, 2026
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?
javiereguiluz commentedon Jan 26, 2026
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:
Would that work?
npielawski commentedon Feb 10, 2026
Okay, I wasn't aware of how complex they get! And I am definitely not knowledgeable enough to take a decision here.
Amoifr commentedon May 5, 2026
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) usingdate_interval.*translation keys across all 38 locales. Per-fieldsetFormat()andCrud::setDateIntervalFormat()still let users opt into a rawDateInterval::format()if they prefer.Also fixed the misleading
TextFieldrecommendation in the Doctrine type mapping table along the way. 😄Happy to iterate if anything needs tweaking!
Add DateIntervalField for editable, localized DateInterval rendering
Add DateIntervalField for editable, localized DateInterval rendering