コード例 #1
0
 /**
  *
  * @param string|\DateTime $start
  * @param string|\DateTime $end
  */
 public function __construct($start, $end)
 {
     $this->start = ToDate::normalizeDate($start);
     $this->end = ToDate::normalizeDate($end);
     if ($this->start->getTimestamp() > $this->end->getTimestamp()) {
         throw new \InvalidArgumentException(sprintf('End needs to be before start, start was "%s", end was "%s"', $this->start->format('Y-m-d'), $this->end->format('Y-m-d')), 1414430503);
     }
     $this->rewind();
 }
コード例 #2
0
ファイル: EasterBasedCondition.php プロジェクト: hnesk/todate
 /**
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     $testDate = ToDate::normalizeDate($date, $this->offset . ' days');
     list($weekDay, $dayCheck, $year) = explode('-', $testDate->format('N-nd-Y'));
     // easter is never after 25.04, never before 22.03 and always on a sunday
     if ($dayCheck > 425 || $weekDay != 7 || $dayCheck < 322) {
         return false;
     }
     if (!isset(self::$easterCache[$year])) {
         $easterDate = new \DateTime('21-03-' . $year);
         $easterDate->modify(easter_days($year) . ' days');
         self::$easterCache[$year] = $easterDate;
     } else {
         $easterDate = self::$easterCache[$year];
     }
     return $testDate == $easterDate;
 }
コード例 #3
0
 /**
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     $date = ToDate::normalizeDate($date);
     if ($this->dayOfWeek != $date->format('N')) {
         return false;
     }
     foreach ($this->weeksOfMonth as $weekOfMonth) {
         $testDate = new \DateTime($date->format('Y-m-01'));
         if ($weekOfMonth < 0) {
             $testDate->add(new \DateInterval('P1M'));
         }
         $testDate->modify($weekOfMonth . ' ' . self::$PUKOOL[$this->dayOfWeek]);
         if ($date == $testDate) {
             return true;
         }
     }
     return false;
 }
コード例 #4
0
ファイル: DateCondition.php プロジェクト: hnesk/todate
 /**
  *
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     return $this->date == ToDate::normalizeDate($date);
 }
コード例 #5
0
 /**
  *
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     $days = $this->date->diff(ToDate::normalizeDate($date))->days;
     return $days % $this->offsetInDays === 0;
 }