コード例 #1
0
ファイル: CompilerTest.php プロジェクト: Maksold/platform
 public function testCompile()
 {
     $expectedResult = 'Compiled String';
     $inputString = 'some test string';
     $tokens = [new Token(Token::TYPE_DATE, '2001-02-03')];
     $lexerMock = $this->getMockBuilder('Oro\\Bundle\\FilterBundle\\Expression\\Date\\Lexer')->disableOriginalConstructor()->getMock();
     $parserMock = $this->getMockBuilder('Oro\\Bundle\\FilterBundle\\Expression\\Date\\Parser')->disableOriginalConstructor()->getMock();
     $lexerMock->expects($this->once())->method('tokenize')->with($inputString)->will($this->returnValue($tokens));
     $parserMock->expects($this->once())->method('parse')->with($tokens)->will($this->returnValue($expectedResult));
     $compiler = new Compiler($lexerMock, $parserMock);
     $this->assertSame($expectedResult, $compiler->compile($inputString));
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function getConvertedValue(array $widgetConfig, $value = null, array $config = [], array $options = [])
 {
     if (is_null($value) || $value['value']['start'] === null && $value['value']['end'] === null) {
         list($start, $end) = $this->dateHelper->getDateTimeInterval('P1M');
         $type = AbstractDateFilterType::TYPE_BETWEEN;
     } else {
         list($startValue, $endValue, $type) = $this->getPeriodValues($value);
         $start = $startValue instanceof DateTime ? $startValue : $this->dateCompiler->compile($startValue);
         $start->setTime(0, 0, 0);
         $end = $endValue instanceof DateTime ? $endValue : $this->dateCompiler->compile($endValue);
         $end->setTime(23, 59, 59);
     }
     return ['start' => $start, 'end' => $end, 'type' => $type];
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getConvertedValue(array $widgetConfig, $value = null, array $config = [], array $options = [])
 {
     if (is_null($value) || $value['value']['start'] === null && $value['value']['end'] === null) {
         $end = new DateTime('now', new \DateTimeZone('UTC'));
         $start = clone $end;
         $start = $start->sub(new \DateInterval('P1M'));
         $type = AbstractDateFilterType::TYPE_BETWEEN;
     } else {
         list($startValue, $endValue, $type) = $this->getPeriodValues($value);
         $start = $startValue instanceof DateTime ? $startValue : $this->dateCompiler->compile($startValue);
         $end = $endValue instanceof DateTime ? $endValue : $this->dateCompiler->compile($endValue);
     }
     return ['start' => $start, 'end' => $end, 'type' => $type];
 }