예제 #1
0
파일: ToDate.php 프로젝트: hnesk/todate
 /**
  * @param string $condition
  * @return DateConditionInterface
  */
 public static function condition($condition)
 {
     if (is_string($condition)) {
         $p = new FormalDateExpressionParser($condition);
         $condition = $p->parse();
     }
     return $condition;
 }
예제 #2
0
 /**
  *
  * @param \Iterator                     $iterator
  * @param DateConditionInterface|string $condition
  */
 public function __construct(\Iterator $iterator, $condition)
 {
     if (is_string($condition)) {
         $p = new FormalDateExpressionParser($condition);
         $condition = $p->parse();
     }
     if (!$condition instanceof DateConditionInterface) {
         throw new \InvalidArgumentException("Condition needs to implement DateConditionInterface or must be a parsable string");
     }
     $this->condition = $condition;
     parent::__construct($iterator);
 }
 public function testParseComplexStuff()
 {
     $expression = '(Month = 3-10 AND DayOfWeekOfMonth = -1SAT) OR (NOT(Month=3-10) AND DayOfWeekOfMonth = 1FRI)';
     $expectedExpression = '((Month = 3,4,5,6,7,8,9,10) AND (DayOfWeekOfMonth = -1SAT)) OR ((NOT(Month = 3,4,5,6,7,8,9,10)) AND (DayOfWeekOfMonth = 1FRI))';
     $parser = new FormalDateExpressionParser($expression);
     $result = $parser->parse();
     self::assertInstanceOf('ToDate\\Condition\\UnionCondition', $result);
     self::assertEquals($expectedExpression, (string) $result);
 }