示例#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);
 }