8000 DateType form field single_text transformer issue · Issue #18267 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

DateType form field single_text transformer issue #18267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yellowmamba opened this issue Mar 22, 2016 · 5 comments
Closed

DateType form field single_text transformer issue #18267

yellowmamba opened this issue Mar 22, 2016 · 5 comments

Comments

@yellowmamba
Copy link

Hi guys,

When I use "single_text" to render a doctrine date field as an HTML5 input field, I get errors when the date is set to "1985-04-01", however, if the value is "1985-04-02" or "1985-04-03", it works. This problem only occurs on our production server, it's not any issue in our local development environment.

Code:

$builder
    ...
    ->add('date_of_birth', 'date', ['widget' => 'single_text', 'format' => 'yyyy-MM-dd'])

I'm able to track down the issue that the error on production server is the result of TransformationFailedException. When Symfony transforms string to a datetime object, it gets an IntlDateFormatter object to parse the string value, should an error occur, it would be recorded and thrown through above Exception class. Symfony instantiates the php built-in IntlDateFormatter class which is from the INTL extension I believe, I compared the extension on our production server and development server, the version are the same, both 1.1.0, all directives are the same, only difference being ICU version, which on production is 52.1 while in development environment is 4.6.

The error I am getting on production for specific dates is U_PARSE_ERROR, which indicates something is wrong in the parse method I mentioned above.

I do find Symfony provides an alternative formatter, Symfony\Component\Intl\DateFormatter\IntlDateFormatter, but I don't know where it's been used. Is this class intended to tackle issues like I reported?

Any help would be appreciated!

Cheers

@jakzal
Copy link
Contributor
jakzal commented Mar 23, 2016

What Symfony version do you use? I have just tried on the latest 2.3 with ICU data 55.1 (also bundled with Symfony now) and all your date examples work just fine. Below the script I used.

<?php
require_once __DIR__.'/vendor/autoload.php';

$formFactory = \Symfony\Component\Form\Forms::createFormFactoryBuilder()
    ->getFormFactory();

foreach (['1985-04-01', '1985-04-02', '1985-04-03'] as $date) {
    $form = $formFactory->createBuilder('form')
        ->add('date_of_birth', 'date', ['widget' => 'single_text', 'format' => 'yyyy-MM-dd'])
        ->add('submit', 'submit')
        ->getForm();

    $form->submit(['date_of_birth' => $date]);
    if ($form->isValid()) {
        var_dump($form->getData());
    }
}

@mvrhov
Copy link
mvrhov commented Mar 23, 2016

The other question is also which timezone he has set.

@jakzal
Copy link
Contributor
jakzal commented Mar 23, 2016

@mvrhov indeed. Some dates are invalid in some time zones (see #15691).

@yellowmamba
Copy link
Author

We still use 2.6, I know it's no longer maintained, but it's not straightforward for us to upgrade it to 2.7 at the moment. The timezone we use in production is Asia/Baghdad, my local timezone is however Australia/Melbourne.

@yellowmamba
Copy link
Author

@jakzal Thanks for the reference to that ticket. I found out that 1985-04-01 was not a valid time in our production timezone. http://www.timeanddate.com/worldclock/converted.html?iso=19850401T00&p1=27&p2=136

That'd explain why the same code works on my local, but not production, with 765D the same version of INTL extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants
0