Skip to content

Commit

Permalink
Merge pull request #5306 from laboro/ticket/BAP-8936_1.6
Browse files Browse the repository at this point in the history
BAP-8936: Failed unit test build on 1.7 branch
  • Loading branch information
vsoroka committed Sep 4, 2015
2 parents b699cac + 7a996e2 commit d7f39dd
Show file tree
Hide file tree
Showing 2 changed files with 272 additions and 97 deletions.
101 changes: 59 additions & 42 deletions src/Oro/Bundle/FilterBundle/Expression/Date/ExpressionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,52 +38,54 @@ public function __construct($value, $timezone = null)
if (is_numeric($value)) {
$this->value = $value;
$this->sourceType = self::TYPE_INT;
} elseif ($value instanceof Token && $value->is(Token::TYPE_VARIABLE)) {
$dateValue = Carbon::now(new \DateTimeZone($timezone));
} elseif ($value instanceof Token) {
if ($value->is(Token::TYPE_VARIABLE)) {
$dateValue = Carbon::now(new \DateTimeZone($timezone));

switch ($value->getValue()) {
case DateModifierInterface::VAR_TODAY:
$dateValue->startOfDay();
break;
case DateModifierInterface::VAR_SOW:
case DateModifierInterface::VAR_THIS_WEEK:
//do not use start of the week due to it always use monday as 1 day
$dateValue->modify('this week');
$dateValue->startOfDay();
break;
case DateModifierInterface::VAR_SOM:
case DateModifierInterface::VAR_THIS_MONTH:
$dateValue->firstOfMonth();
break;
case DateModifierInterface::VAR_FMQ:
case DateModifierInterface::VAR_SOQ:
case DateModifierInterface::VAR_THIS_QUARTER:
case DateModifierInterface::VAR_FDQ:
$dateValue->firstOfQuarter();
break;
case DateModifierInterface::VAR_SOY:
case DateModifierInterface::VAR_THIS_YEAR:
$dateValue->firstOfYear();
break;
}
switch ($value->getValue()) {
case DateModifierInterface::VAR_TODAY:
$dateValue->startOfDay();
break;
case DateModifierInterface::VAR_SOW:
case DateModifierInterface::VAR_THIS_WEEK:
//do not use start of the week due to it always use monday as 1 day
$dateValue->modify('this week');
$dateValue->startOfDay();
break;
case DateModifierInterface::VAR_SOM:
case DateModifierInterface::VAR_THIS_MONTH:
$dateValue->firstOfMonth();
break;
case DateModifierInterface::VAR_FMQ:
case DateModifierInterface::VAR_SOQ:
case DateModifierInterface::VAR_THIS_QUARTER:
case DateModifierInterface::VAR_FDQ:
$dateValue->firstOfQuarter();
break;
case DateModifierInterface::VAR_SOY:
case DateModifierInterface::VAR_THIS_YEAR:
$dateValue->firstOfYear();
break;
}

$this->value = $dateValue;
$this->value = $dateValue;

$this->variableType = $value->getValue();
$this->variableLabel = (string)$value;
$this->sourceType = self::TYPE_DATE;
} elseif ($value instanceof Token && $value->is(Token::TYPE_TIME)) {
$dateValue = Carbon::parse('now', new \DateTimeZone($timezone));
call_user_func_array([$dateValue, 'setTime'], explode(':', $value->getValue()));
$this->variableType = $value->getValue();
$this->variableLabel = (string)$value;
$this->sourceType = self::TYPE_DATE;
} elseif ($value->is(Token::TYPE_TIME)) {
$dateValue = Carbon::parse('now', new \DateTimeZone($timezone));
call_user_func_array([$dateValue, 'setTime'], explode(':', $value->getValue()));

$this->value = $dateValue;
$this->sourceType = self::TYPE_TIME;
} elseif ($value instanceof Token && $value->is(Token::TYPE_DATE)) {
$this->sourceType = self::TYPE_DATE;
$this->value = Carbon::parse($value->getValue(), new \DateTimeZone($timezone));
} elseif ($value instanceof Token && $value->is(Token::TYPE_INTEGER)) {
$this->sourceType = self::TYPE_INT;
$this->value = $value->getValue();
$this->value = $dateValue;
$this->sourceType = self::TYPE_TIME;
} elseif ($value->is(Token::TYPE_DATE)) {
$this->sourceType = self::TYPE_DATE;
$this->value = Carbon::parse($value->getValue(), new \DateTimeZone($timezone));
} elseif ($value->is(Token::TYPE_INTEGER)) {
$this->sourceType = self::TYPE_INT;
$this->value = $value->getValue();
}
}
}

Expand Down Expand Up @@ -142,6 +144,11 @@ public function add(ExpressionResult $value)
case DateModifierInterface::VAR_NOW:
case DateModifierInterface::VAR_TODAY:
case DateModifierInterface::VAR_THIS_DAY:
case DateModifierInterface::VAR_SOW:
case DateModifierInterface::VAR_SOM:
case DateModifierInterface::VAR_SOQ:
case DateModifierInterface::VAR_SOY:
case DateModifierInterface::VAR_FDQ:
$dateValue->addDays($value->getValue());
break;
case DateModifierInterface::VAR_THIS_WEEK:
Expand Down Expand Up @@ -187,6 +194,11 @@ public function subtract(ExpressionResult $value)
case DateModifierInterface::VAR_NOW:
case DateModifierInterface::VAR_TODAY:
case DateModifierInterface::VAR_THIS_DAY:
case DateModifierInterface::VAR_SOW:
case DateModifierInterface::VAR_SOM:
case DateModifierInterface::VAR_SOQ:
case DateModifierInterface::VAR_SOY:
case DateModifierInterface::VAR_FDQ:
$dateValue->subDays($value->getValue());
break;
case DateModifierInterface::VAR_THIS_WEEK:
Expand All @@ -211,6 +223,11 @@ public function subtract(ExpressionResult $value)
case DateModifierInterface::VAR_NOW:
case DateModifierInterface::VAR_TODAY:
case DateModifierInterface::VAR_THIS_DAY:
case DateModifierInterface::VAR_SOW:
case DateModifierInterface::VAR_SOM:
case DateModifierInterface::VAR_SOQ:
case DateModifierInterface::VAR_SOY:
case DateModifierInterface::VAR_FDQ:
$this->value -= $value->getValue()->day;
break;
case DateModifierInterface::VAR_THIS_WEEK:
Expand Down
Loading

0 comments on commit d7f39dd

Please sign in to comment.