Skip to content

DateParserTransformer fails with a TypeError on a \DateTimeImmutable input #198

Closed

Description

@njoubert-cleverage

Description

DateParserTransformer fails with a TypeError when its input is a \DateTimeImmutable: only \DateTime objects are returned as-is, any other value is passed to \DateTime::createFromFormat().

Reproduction

clever_age_process:
    configurations:
        demo.date.date_parser:
            tasks:
                entry:
                    service: '@CleverAge\ProcessBundle\Task\ConstantOutputTask'
                    outputs: [ parse_immutable ]
                    options:
                        output: '2026-09-28 12:34:56'
                parse_immutable:
                    service: '@CleverAge\ProcessBundle\Task\TransformerTask'
                    outputs: debug
                    options:
                        transformers:
                            callback:
                                callback: date_create_immutable
                            date_parser:
                                format: 'Y-m-d H:i:s'
                debug:
                    service: '@CleverAge\ProcessBundle\Task\Debug\DebugTask'
$ bin/console cleverage:process:execute demo.date.date_parser
CRITICAL [cleverage_process] Critical process failure ["error" => "Process demo.date.date_parser has failed during process parse_immutable with message: 'Transformation 'date_parser' have failed: DateTime::createFromFormat(): Argument #2 ($datetime) must be of type string, DateTimeImmutable given'."]

Tested on main (c1a2804), PHP 8.5, Symfony 7.4.

Cause

In DateParserTransformer::transform(), only \DateTime is short-circuited:

if (!$value || $value instanceof \DateTime) {
    return $value;
}

$date = \DateTime::createFromFormat($options['format'], $value); // TypeError for a \DateTimeImmutable

The Notes section of docs/reference/transformers/date_parser_transformer.md currently documents this failure.

Proposed fix

  • convert a \DateTimeImmutable input to a \DateTime with \DateTime::createFromImmutable() (same date, time and timezone), so that the transformer keeps its contract of always outputting a \DateTime;
  • add a unit test;
  • update docs/reference/transformers/date_parser_transformer.md (Accepted inputs, remove the Notes entry).

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: a \DateTimeImmutable input currently always fails.

Activity

  1. added a commit that references this issue on Sep 28, 2026
  2. added a commit that references this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions