The existing TimestampCeFieldFormatter supports timestamp, created, and changed fields which store Unix timestamps. However, datetime and daterange fields store ISO date strings (e.g., 2025-04-10T09:00:00) and are not supported.
There is no built-in custom elements formatter for datetime and daterange field types. Users needing formatted date output with timezone and date format support for these field types must write a custom formatter.
Solution
Add a DateTimeCeFieldFormatter that extends TimestampCeFieldFormatter to support datetime and daterange fields. It:
- Reuses the same configuration form (date format, custom format, timezone)
- Parses ISO date strings via DrupalDateTime instead of using DateFormatterInterface::format() (which expects Unix timestamps)
- Handles daterange fields by outputting {value, endValue} objects
- Supports single and multi-cardinality fields
Issue fork custom_elements-3584113
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
fagothx! that would make sense, yes.
I've added a remark to the PR. Also I miss the configruation form and summary method implementations?
Then, same as for other formatters, please add a test-case that proofs it working.
Comment #4
kushal bansal commentedComment #5
fagoalso, we need to watch out for date-only values and do no timezone conversion there.
Comment #6
fagoI addressed my remarks and added test coverage for changes. please review.
Comment #7
kushal bansal commentedHi , I had a review and all looks goo to me. Thanks
Comment #9
fagoThank you, merged!