DateIntervalToStringTransformer example

'%y year', '1 year', 'P1Y'],
        ];

        return $data;
    }

    /** * @dataProvider dataProviderISO */
    public function testTransform($format$output$input)
    {
        $transformer = new DateIntervalToStringTransformer($format);
        $input = new \DateInterval($input);
        $this->assertEquals($output$transformer->transform($input));
    }

    public function testTransformEmpty()
    {
        $transformer = new DateIntervalToStringTransformer();
        $this->assertSame('', $transformer->transform(null));
    }

    public function testTransformExpectsDateTime()
    {
$format .= '%iM';
            $parts[] = 'minutes';
        }
        if ($options['with_seconds']) {
            $format .= '%sS';
            $parts[] = 'seconds';
        }
        if ($options['with_invert']) {
            $parts[] = 'invert';
        }
        if ('single_text' === $options['widget']) {
            $builder->addViewTransformer(new DateIntervalToStringTransformer($format));
        } else {
            foreach (self::TIME_PARTS as $part) {
                if ($options['with_'.$part]) {
                    $childOptions = [
                        'error_bubbling' => true,
                        'label' => $options['labels'][$part],
                        // Append generic carry-along options                         'required' => $options['required'],
                        'translation_domain' => $options['translation_domain'],
                        // when compound the array entries are ignored, we need to cascade the configuration here                         'empty_data' => $options['empty_data'][$part] ?? null,
                    ];
Home | Imprint | This part of the site doesn't use cookies.