Support for date time objects #274

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@dantleech
Collaborator

Not sure about this PR -- but hopefully this at least raises the issue.

The following doesn't work at the moment.

$qb->where($qb->expr()->lt('date', $post->getDate()));

This PR converts the date time object into a string, formatted like 2013-05-10T00:00:00+01:00 as I don't think there is a native way to do this with PHPCR? I seem to recall a discussion on the cmf mailing list about date times.

As I say, not 100% on this, so comments welcome :)

@dantleech dantleech Support for date time objects
- Absolutely not sure about the validity of this PR, but I can't seem to
  see any native support in PHPCR for datetimes.
588a151
@lsmith77
Member

why do you think that this might not be the correct approach?

@dantleech
Collaborator

Well, 2 things:

  • Not sure if the instanceof \DateTime check is in the right place
  • If casting the DateTime to a string with $date->format('c') is the best way - but there is no native support for datetime in PHPCR right?
@dbu dbu commented on the diff Apr 12, 2013
lib/Doctrine/ODM/PHPCR/Query/PhpcrExpressionVisitor.php
@@ -135,7 +135,13 @@ public function walkCompositeExpression(CompositeExpression $expr)
*/
public function walkValue(Value $value)
{
- return $this->qomf->literal($value->getValue());
+ $value = $value->getValue();
+
+ if ($value instanceof \DateTime) {
+ $value = $value->format('c');
@dbu
dbu Apr 12, 2013 Doctrine member

if we indeed need a string here, we probably should use PHPCR\PropertyType::convertType, see https://github.com/phpcr/phpcr/blob/master/src/PHPCR/PropertyType.php#L434

@dbu
Member
dbu commented Apr 12, 2013

as the QueryBuilder is using the QueryObjectModelFactory, i fear we have an issue somewhere in QOM or the QOM walker rather than phpcr-odm. DateTime objects are used for phpcr fields of type DATE, so phpcr should properly handle them internally i think.

can you investigate if its a problem in phpcr-utils / jackalope? there seem to be quite a few issues around the phpcr query builder and how we walk the qom tree in jackalope.

@dantleech
Collaborator

ok, tested with jackrabbit and that works fine without this fix. So assuming its a problem with jackalope-doctrine-dbal. Probably an easy fix, will put it on my todo.

@dantleech dantleech closed this Apr 14, 2013
@dbu
Member
dbu commented Apr 15, 2013

we definitely have a couple of problems with queries in jackalope-doctrine-dbal

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