mohebifar / DateTimeBundle

A Symfony2 Bundle to format DateTime to string according to a Calendar and a Datepicker FormType.
16 stars 4 forks source link

DateConverter doesn't work as expected. #2

Closed motammem closed 10 years ago

motammem commented 10 years ago

Instead of converting '19-azar-1370' to '1991-12-10' it converts to '1921-11-09'.

mohebifar commented 10 years ago

Can you send a piece of code ?

motammem commented 10 years ago

error


namespace BlueTree\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class PageController extends Controller
{
    public function indexAction()
    {
        $form = $this->createFormBuilder()
            ->add('date', 'mohebifar_datetime',
                array(
                    'years' => range(1300, 1400)
                ))
            ->add('submit', 'submit')
            ->getForm();

        $form->handleRequest($this->get('request'));

        if ($form->isValid()) {

            // This line prints wrong date.
            var_dump($form->getData()['date']);
        }

        return $this->render('@BlueTreeApp/Pages/index.html.twig', array('form' => $form->createView()));
    }
}
motammem commented 10 years ago

I got the solution, values displayed in form begin from zero, how ever they should be same as the month, day and year numbers.

following code solves problem:

            ->add('date', 'mohebifar_datetime',
                array(
                    'years' => array_combine(range(1300, 1400),range(1300, 1400)),
                    'months' => array_combine(range(1,12),range(1,12)),
                    'days' => array_combine(range(1,31),range(1,31))
                ))
mohebifar commented 10 years ago

Yes exactly ! Thank you.