adesigns / calendar-bundle

This bundle allows you to integrate the jQuery FullCalendar plugin into your Symfony2 application.
MIT License
97 stars 60 forks source link

Date is always 1970 #66

Open lukepass opened 6 years ago

lukepass commented 6 years ago

Hello, I configured the bundle and it's working fine except that when I call $startDate = $calendarEvent->getStartDatetime(); the result is always 1970-01-01 01:00:00.0 Europe/Rome (+01:00).

Do you know why?

Thanks.

mikeyudin commented 6 years ago

That sounds like something is incorrect in your CalendarEventListener. This bundle doesn't control what you put in calendar events.

lukepass commented 6 years ago

This is my configuration:

    AppBundle\EventListener\CalendarEventListener:
        tags:
            - { name: 'kernel.event_listener', event: 'calendar.load_events', method: loadEvents }

And this is the class:

<?php

namespace AppBundle\EventListener;

use ADesigns\CalendarBundle\Entity\EventEntity;
use ADesigns\CalendarBundle\Event\CalendarEvent;
use AppBundle\Entity\Activity;
use Application\Sonata\UserBundle\Entity\TeacherUser;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

class CalendarEventListener
{
    private $entityManager;
    private $tokenStorage;

    public function __construct(EntityManagerInterface $entityManager, TokenStorageInterface $tokenStorage)
    {
        $this->entityManager = $entityManager;
        $this->tokenStorage  = $tokenStorage;
    }

    public function loadEvents(CalendarEvent $calendarEvent)
    {
        // TODO
        $startDate = $calendarEvent->getStartDatetime();
        $endDate   = $calendarEvent->getEndDatetime();
    }
}
mikeyudin commented 6 years ago

How are you creating the calendar event? that is handled automatically when the endpoint is called from the calendar JS.

lukepass commented 6 years ago

Sorry, maybe I explained bad my problem. I can put events in the calendar and they are correctly displayed. The problem is that I can't use the date as filters when doing the query. If you take the example from the documentation:

$startDate = $calendarEvent->getStartDatetime();
$endDate = $calendarEvent->getEndDatetime();

$companyEvents = $this->entityManager->getRepository('AcmeDemoBundle:MyCompanyEvents')
                  ->createQueryBuilder('company_events')
                  ->where('company_events.event_datetime BETWEEN :startDate and :endDate')
                  ->setParameter('startDate', $startDate->format('Y-m-d H:i:s'))
                  ->setParameter('endDate', $endDate->format('Y-m-d H:i:s'))
                  ->getQuery()->getResult();

$startDate is always 1970. Shouldn't it be 01 February 2018?

Thanks.