Skip to content

[Form] Date displayed as single_text is off by one. #12808

@derrabus

Description

@derrabus

Have a look a this simple controller action.

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DemoController extends Controller
{
    /**
     * @return array
     *
     * @Template()
     */
    public function indexAction()
    {
        return [
            'form' => $this->createFormBuilder(['date' => new \DateTime('2013-01-26')])
                ->add('date', 'date', ['widget' => 'single_text'])
                ->getForm()
                ->createView()
        ];
    }
}

The corresponding template simply renders the form.

{% extends '::base.html.twig' %}

{% block body %}
    {{ form(form) }}
{% endblock %}

What I would expect here, is a form with a singe text field displaying 2013-01-26. And this is what I get when I run this code with Symfony 2.5.

With Symfony 2.6, I get the same result. Sometimes. Depending on my date.timezone ini setting. If it is set to UTC or a timezone west of UTC, like America/New_York, everything's fine. However, if I use a timezone east of UTC, like Europe/Berlin, the field instead displays 2013-01-25, which is a day earlier.

I haven't traced the problem down yet, but I suppose it's related to the changes of PR #12404.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions