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

DateTime Filter issue #305

Closed
damien-list opened this issue Nov 7, 2012 · 8 comments
Closed

DateTime Filter issue #305

damien-list opened this issue Nov 7, 2012 · 8 comments
Milestone

Comments

@damien-list
Copy link

Hello,

I'm trying to filter my results set on a field with a datetime type and having some issue.
I've tried differents formats for the date, like "29/10/2012" (d/m/Y) and "2012-10-29" (Y-m-d) with the equals operator.

In the first case (29/10/2012), the column is not considered filtered : I test it with the method $column->isFiltered() and it returns me false.

In the second case, the column is considered filtered, but I have this error :

Warning: preg_quote() expects parameter 1 to be string, object given in D:\bloblo\vendor\apy\datagrid-bundle\APY\DataGridBundle\Grid\Source\Source.php line 268

the regex at line 268 expects a string but $value is a DateTime Object.

Am I doing something wrong ?
Thanks for your help

@damien-list
Copy link
Author

I've made a quick and dirty fix in Source.php line 263. I've added the follow lines and it works.

if($column->getType() == 'datetime') {
    $value = $value->format('Y-m-d H:i:s');
}

@Abhoryo
Copy link
Member

Abhoryo commented Nov 8, 2012

It's weird, I know this error and I'm certain that I've already correct it. Maybe on my personnal branch.

@Abhoryo Abhoryo closed this as completed Nov 8, 2012
@Abhoryo Abhoryo reopened this Nov 8, 2012
@Abhoryo
Copy link
Member

Abhoryo commented Nov 8, 2012

We several problems too. After that we try to compare a string date

                            case Column\Column::OPERATOR_GT:
                                $found = $fieldValue > $value;
                                break;
                            case Column\Column::OPERATOR_GTE:
                                $found = $fieldValue >= $value;
                                break;
                            case Column\Column::OPERATOR_LT:
                                $found = $fieldValue < $value;
                                break;
                            case Column\Column::OPERATOR_LTE:
                                $found = $fieldValue <= $value;
                                break;

@damien-list
Copy link
Author

Yes the problem is not only for the equal operator.

@damien-list
Copy link
Author

Hello @Abhoryo,

Have you look into this error ? You've written that you thought you have fixed this issue on your personnal branch. Have you found it ?

@Abhoryo
Copy link
Member

Abhoryo commented Nov 14, 2012

I've fix the same line that you but not the last ones.

@obretau
Copy link

obretau commented Oct 1, 2014

Hello, my english is not good, but I can fix this problem add follow line in Source.php line 260:
$strDate = "";
if($column->getType() == 'datetime' &&
($operator == Column\Column::OPERATOR_EQ ||
$operator == Column\Column::OPERATOR_NEQ )) {
$strDate = $value = $value->format('Y-m-d H:i:s');
}
And line 295, add:
if($column->getType() == 'datetime') {
$fieldValue = $fieldValue->format('Y-m-d H:i:s');
$found = ($strDate === $fieldValue);
break;
}
I hope I have helped

@Abhoryo
Copy link
Member

Abhoryo commented Oct 2, 2014

This issue is too old and there are chances that your problem isn't linked to this issue.
Create a new issue please.

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

4 participants