Skip to content

Commit

Permalink
fixes #203: workflow expression enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
joebordes committed Jul 6, 2014
1 parent 84d7c47 commit 4c57db7
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
Expand Up @@ -73,9 +73,11 @@ function __vt_time_diff($arr) {

$time_operand1 = $time_operand2 = 0;
if(count($arr) > 1) {
$time_operand1 = $arr[0];
$time_operand2 = $arr[1];
$time_operand1 = $time1 = $arr[0];
$time_operand2 = $time2 = $arr[1];
} else {
// Added as we need to compare with the values based on the user date format and timezone
global $default_timezone;
$time_operand1 = date('Y-m-d H:i:s'); // Current time
$time_operand2 = $arr[0];
}
Expand All @@ -85,6 +87,14 @@ function __vt_time_diff($arr) {
$time_operand1 = getValidDBInsertDateTimeValue($time_operand1);
$time_operand2 = getValidDBInsertDateTimeValue($time_operand2);

//to give the difference if it is only time field
if(empty($time_operand1) && empty($time_operand2)) {
$pattern = "/([01]?[0-9]|2[0-3]):[0-5][0-9]/";
if(preg_match($pattern, $time1) && preg_match($pattern, $time2)){
$timeDiff = strtotime($time1) - strtotime($time2);
return date('H:i:s', $timeDiff);
}
}
return (strtotime($time_operand1) - strtotime($time_operand2));
}
/**
Expand Down Expand Up @@ -139,11 +149,38 @@ function __vt_get_date($arr) {
switch ($type) {
case 'today': return date('Y-m-d');
break;
case 'tomorrow': return date('Y-m-d', strtotime('+1 day'));
break;
case 'yesterday': return date('Y-m-d', strtotime('-1 day'));
break;
default : return date('Y-m-d');
break;
}
}

function __vt_add_time($arr) {
if(count($arr) > 1) {
$baseTime = $arr[0];
$minutes = $arr[1];
} else {
$baseTime = date('H:i:s');
$minutes = $arr[0];
}
$endTime = strtotime("+$minutes minutes", strtotime($baseTime));
return date('H:i:s',$endTime);
}

function __vt_sub_time($arr) {
if(count($arr) > 1) {
$baseTime = $arr[0];
$minutes = $arr[1];
} else {
$baseTime = date('H:i:s');
$minutes = $arr[0];
}
$endTime = strtotime("-$minutes minutes", strtotime($baseTime));
return date('H:i:s',$endTime);
}
/** END * */
class VTFieldExpressionEvaluater{
function __construct($expr){
Expand All @@ -165,7 +202,9 @@ class VTFieldExpressionEvaluater{
'time_diffdays' => '__vt_time_diffdays',
'add_days' => '__vt_add_days',
'sub_days' => '__vt_sub_days',
'get_date' => '__vt_get_date'
'get_date' => '__vt_get_date',
'add_time' => '__vt_add_time',
'sub_time' => '__vt_sub_time'
);

$this->operations = array_merge($this->functions, $this->operators);
Expand Down Expand Up @@ -202,7 +241,11 @@ class VTFieldExpressionEvaluater{
}

function env($sym){
if($this->env) {
return $this->env->get($sym->value);
} else {
return $sym->value;
}
}
}
?>
Expand Up @@ -39,9 +39,9 @@ class VTExpressionsManager{
}

function expressionFunctions() {
return array('concat' => 'concat(a,b)', 'time_diffdays' => 'time_diffdays(a,b)', 'time_diff' => 'time_diff(a,b)',
'add_days' => 'add_days(datefield, noofdays)', 'sub_days' => 'sub_days(datefield, noofdays)',
'get_date' => "get_date('today')");
return array('concat' => 'concat(a,b)', 'time_diffdays(a,b)' => 'time_diffdays(a,b)', 'time_diffdays(a)' => 'time_diffdays(a)', 'time_diff(a,b)' => 'time_diff(a,b)','time_diff(a)' => 'time_diff(a)',
'add_days' => 'add_days(datefield, noofdays)', 'sub_days' => 'sub_days(datefield, noofdays)', 'add_time(timefield, minutes)' => 'add_time(timefield, minutes)', 'sub_time(timefield, minutes)' => 'sub_time(timefield, minutes)',
'today' => "get_date('today')", 'tomorrow' => "get_date('tomorrow')", 'yesterday' => "get_date('yesterday')");
}
}

Expand Down

0 comments on commit 4c57db7

Please sign in to comment.