[TYPO3-mvc] How to compare a DateTime object correctly in anExtbase query?

Stephan Schuler Stephan.Schuler at netlogix.de
Mon Jan 12 16:19:58 CET 2015


Please have a look at the method Typo3DbQueryParser::getPlainValue($input):

> if ($input instanceof \DateTime() {
>     return $input->format('U');
> } elseif ([...]
> } else {
>     return $input;
> }

That's roughly what I said all together:

1: It uses UTC since 'U' returns the unix timestamp which always *is* UTC
2: Using \DateTime is supposed to work
3: You should be able to use ->format('U') because integers are used plain

Is your $datePublished property annotated as "@var \DateTime"? I don't know exactly where this comes to play, but this could result in string casting or something.

I stick to it:
* Either use \DateTime directoy or ->format('U').
* Debug the actual SQL query string being created.
Do both in one step. Everything else is pointless. Find out the reason why this doesn't work, since it has to.

Regards,



Stephan Schuler
Web-Entwickler | netlogix Media

Telefon: +49 (911) 539909 - 0
E-Mail: Stephan.Schuler at netlogix.de
Web: media.netlogix.de




netlogix GmbH & Co. KG
IT-Services | IT-Training | Media
Neuwieder Straße 10 | 90411 Nürnberg
Telefon: +49 (911) 539909 - 0 | Fax: +49 (911) 539909 - 99
E-Mail: info at netlogix.de | Web: http://www.netlogix.de

netlogix GmbH & Co. KG ist eingetragen am Amtsgericht Nürnberg (HRA 13338)
Persönlich haftende Gesellschafterin: netlogix Verwaltungs GmbH (HRB 20634)
Umsatzsteuer-Identifikationsnummer: DE 233472254
Geschäftsführer: Stefan Buchta, Matthias Schmidt



-----Ursprüngliche Nachricht-----
Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von Jan Kornblum
Gesendet: Montag, 12. Januar 2015 16:02
An: typo3-project-typo3v4mvc at lists.typo3.org
Betreff: Re: [TYPO3-mvc] How to compare a DateTime object correctly in anExtbase query?

Hi again,

> As the findPrevious() works fine using this:
>
> $query->setOrderings(array('datePublished' =>
> \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING));
> $query->matching($query->greaterThan('datePublished',
> $post->getDatePublished()->format('Y-m-d H:i:s')));
>
> ...and findNext() always returns the same (not the next) object as the
> object given as param to compare against in in the query:
>
> $query->setOrderings(array('datePublished' =>
> \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING));
> $query->matching($query->lessThan('datePublished',
> $post->getDatePublished()->format('Y-m-d H:i:s')));
>
> ...I believe that the problem is located in the fact, that the
> comparison isn't matching exactly (just nearly) because of the wrong
> format ("maybe some seconds / milliseconds are missing?")

O.K. i've figured out at least one thing:

findNext() returning the same object as the given object only happens when the given object itself has got a DateTime close to midnight
(23:30 01-01-2015). So this really seems to be a timezone problem.

But i still don't understand why the first query needs format('Y-m-d
H:i:s') to behave correctly while the second query only works "halbwegs" when using ->format('Y-m-d'). And non of the queries work without format().

Sometimes Extbase really is frustrating... Especially when trying to accomplish such basic things.

Kind regards, Jan


_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


More information about the TYPO3-project-typo3v4mvc mailing list