AnsweredAssumed Answered

Problem extending class TimeDate

Question asked by Diego Celdrán on Apr 10, 2018
Latest reply on Apr 11, 2018 by André Lopes

Hello,

 

I want to create new date filter operator, when i want to filter for a date field, i want to add the operator "before today".

I search in the community and i found this:

 

How to add another date filter to a module search 

 

The problem is because i have to edit the include/TimeDate.php and add the following:

protected $date_expressions = array(
        'yesterday' =>    array("-1 day", "-1 day"),
        'today' =>        array("", ""),
        'tomorrow' =>     array("+1 day", "+1 day"),
        'last_7_days' =>  array("-6 days", ""),
        'next_7_days' =>  array("", "+6 days"),
        'last_30_days' => array("-29 days", ""),
        'next_30_days' => array("", "+29 days"),
        'before_today' => array("-9999 days", "-1 day"),
    );

And i have to create the file /custom/clients/base/filters/operators/operators.php with:

require_once('clients/base/filters/operators/operators.php');

$viewdefs['base']['filter']['operators']['date']['before_today'] = "LBL_OPERATOR_BEFORE_TODAY";

And now i can see into the dropdown the new operator and it works fine, but of course this is not a good practise because i have to edit a core file.

 

I try to create the custom/include/TimeDate.php and copy/paste all file and create the operator here but it doesn't works.

 

Can i extend this class? or how can i create the new operator without modifying the core class?

 

Thanks!

Outcomes