Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@SebLevDev
Copy link
Contributor

The DATE_ADD and DATE_SUB built-in function of Doctrine supports only the "hour", "month" and "day" intervals. I don't see the point of not having all the intervals available. These should be "minute", "second" and "year". I didn't check compatibility with other database vendors rather than MySQL but I don't think it should be a problem

Cfr Also Ticket #3698

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, patch looks good, but misses testing (especially integration with other DBs

$this->intervalExpression->dispatch($sqlWalker)
);

case 'minute':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spotted some \t here ;-)

@SebLevDev
Copy link
Contributor Author

Can i do something again ?

@Ocramius
Copy link
Member

Ocramius commented Oct 3, 2017

Looks good to me: so far.

Assigning to @lcobucci for another pair of eyes.

@Ocramius Ocramius requested a review from lcobucci October 3, 2017 12:43
@Ocramius Ocramius assigned lcobucci and unassigned SebLevDev Oct 3, 2017
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It LGTM, just some nitpicking. Also, aren't we missing tests for year and week add/sub?

/**
* @group DDC-2938
*/
public function testDateAddTime()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add : void

{
$arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m")
->getArrayResult();
$this->assertTrue(strtotime($arg[0]['add']) > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self::assert*() instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use a more specific assertion?


$arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'hour') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m")
->getArrayResult();
$this->assertTrue(strtotime($arg[0]['add']) > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self::assert*() instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use a more specific assertion?


$arg = $this->_em->createQuery("SELECT DATE_ADD(CURRENT_TIMESTAMP(), 10, 'minute') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m")
->getArrayResult();
$this->assertTrue(strtotime($arg[0]['add']) > 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self::assert*() instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use a more specific assertion?

public function testDateSubTime()
{
$arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'second') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m")
->getArrayResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self::assert*() instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use a more specific assertion?

$this->assertTrue(strtotime($arg[0]['add']) > 0);

$arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'minute') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m")
->getArrayResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self::assert*() instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use a more specific assertion?

$this->assertTrue(strtotime($arg[0]['add']) > 0);

$arg = $this->_em->createQuery("SELECT DATE_SUB(CURRENT_TIMESTAMP(), 10, 'hour') AS add FROM Doctrine\Tests\Models\Company\CompanyManager m")
->getArrayResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self::assert*() instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use a more specific assertion?


/**
* @group DDC-2938
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add : void

@SebLevDev
Copy link
Contributor Author

@lcobucci I cannot change for self::assert*() and : void .
These changes must be the subject of another PR.

@lcobucci
Copy link
Member

lcobucci commented Oct 4, 2017

@Legenyes you can change for the code you're inserting.

@SebLevDev
Copy link
Contributor Author

It's worse.
Mixing two syntax in the same file is not a good practice.
I will not make this change in this PR

What about BC for : void ?

@Ocramius
Copy link
Member

Ocramius commented Oct 4, 2017 via email

@lcobucci
Copy link
Member

lcobucci commented Oct 4, 2017

@Legenyes self::assert*() has already been fixed for v3 on the entire codebase, this means that new code should adhere to that, otherwise we need to reapply things over and over again. On the other hand, if we apply the change on v2 as well we'll be creating conflicts.

I agree that it's not ideal to have mixed syntaxes but it is the least worse solution, given this context.

@SebLevDev
Copy link
Contributor Author

What' news ?

@lcobucci
Copy link
Member

lcobucci commented Oct 6, 2017

@Legenyes we still don't have tests for week and year and we still have the same self::assertTrue() checks that IMO are not really helpful since it doesn't provide you enough info about the operation that has been done.

@greg0ire
Copy link
Member

The docs currently say:

DATE_ADD(date, days, unit) - Add the number of days to a given date. (Supported units are DAY, MONTH)

please change that too (add your units, and change "number of days")

@greg0ire
Copy link
Member

Closes #5835 ?

SebLevDev and others added 2 commits October 29, 2017 21:48
So that we can do proper assertions and cover all the possibilities
of the functions.
@JoppeDC
Copy link

JoppeDC commented Jun 3, 2019

This wasn't in the docs yet, leading me to a search for how to do it. Luckily i found this old PR. I've created a PR to add this to the docs.
#7729

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants