DateTimeToHtml5LocalDateTimeTransformer example

$dateFormat = \is_int($options['date_format']) ? $options['date_format'] : self::DEFAULT_DATE_FORMAT;
        $timeFormat = self::DEFAULT_TIME_FORMAT;
        $calendar = \IntlDateFormatter::GREGORIAN;
        $pattern = \is_string($options['format']) ? $options['format'] : null;

        if (!\in_array($dateFormat, self::ACCEPTED_FORMATS, true)) {
            throw new InvalidOptionsException('The "date_format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
        }

        if ('single_text' === $options['widget']) {
            if (self::HTML5_FORMAT === $pattern) {
                $builder->addViewTransformer(new DateTimeToHtml5LocalDateTimeTransformer(
                    $options['model_timezone'],
                    $options['view_timezone'],
                    $options['with_seconds']
                ));
            } else {
                $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer(
                    $options['model_timezone'],
                    $options['view_timezone'],
                    $dateFormat,
                    $timeFormat,
                    $calendar,
                    
'Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+02:00', '2018-09-15T10:00:00+02:00'],
            ['Europe/Berlin', 'Europe/Berlin', '2018-09-15T10:00:00+0200', '2018-09-15T10:00:00+0200'],
            ['UTC', 'UTC', '2018-10-03T10:00:00.000Z', '2018-10-03T10:00:00.000Z'],
        ];
    }

    /** * @dataProvider transformProvider */
    public function testTransform($fromTz$toTz$from$to, bool $withSeconds)
    {
        $transformer = new DateTimeToHtml5LocalDateTimeTransformer($fromTz$toTz$withSeconds);

        $this->assertSame($to$transformer->transform(null !== $from ? new \DateTime($from) : null));
    }

    /** * @dataProvider transformProvider */
    public function testTransformDateTimeImmutable($fromTz$toTz$from$to, bool $withSeconds)
    {
        $transformer = new DateTimeToHtml5LocalDateTimeTransformer($fromTz$toTz$withSeconds);

        
Home | Imprint | This part of the site doesn't use cookies.