Skip to content
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

Date is always 1970 #66

Open
lukepass opened this issue Feb 19, 2018 · 4 comments
Open

Date is always 1970 #66

lukepass opened this issue Feb 19, 2018 · 4 comments

Comments

@lukepass
Copy link

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
Copy link
Member

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

@lukepass
Copy link
Author

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
Copy link
Member

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

@lukepass
Copy link
Author

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.

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

No branches or pull requests

2 participants