/**
  *
  * @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();
 }
Example #2
0
 /**
  * @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;
 }
 /**
  * @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;
 }
Example #4
0
<?php

/*                                                                        *
 * This file is part of the ToDate library                                *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License, either version 3   *
 * of the License, or (at your option) any later version.                 *
 *                                                                        *
 * (c) 2012-2014 Johannes Künsebeck <kuensebeck@googlemail.com            */
require_once __DIR__ . '/../vendor/autoload.php';
use ToDate\ToDate;
$secondOrLastSaturday = ToDate::condition('DayOfWeekOfMonth = 2,-1SAT');
$soRight = $secondOrLastSaturday->contains(new \DateTime('2014-11-29')) && $secondOrLastSaturday->contains(new \DateTime('2014-11-08'));
var_dump($soRight);
$soWrong = $secondOrLastSaturday->contains(new \DateTime('2014-11-09')) || $secondOrLastSaturday->contains(new \DateTime('2014-11-15'));
var_dump($soWrong);
$everySecondAndLastSaturydayIn2014 = ToDate::conditionalIterator('2014-01-01', '2014-12-31', $secondOrLastSaturday);
foreach ($everySecondAndLastSaturydayIn2014 as $saturday) {
    echo $saturday->format('d.m.Y, l') . PHP_EOL;
}
Example #5
0
<?php

/*                                                                        *
 * This file is part of the ToDate library                                *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License, either version 3   *
 * of the License, or (at your option) any later version.                 *
 *                                                                        *
 * (c) 2012-2014 Johannes Künsebeck <kuensebeck@googlemail.com            */
require_once __DIR__ . '/../vendor/autoload.php';
use ToDate\ToDate;
/* All german holidays in one simple string! */
$germanHolidays = 'DayOfWeek = SAT,SUN OR DayAndMonth = 1/1 OR Date = Easter-2 OR Date = Easter+1 OR DayAndMonth = 1/5 OR Date = Easter+39 OR Date = Easter+50 OR Date = Easter+60 OR DayAndMonth = 3/10 OR DayAndMonth = 1/11 OR DayAndMonth = 25/12 OR DayAndMonth = 26/12';
$holidays = ToDate::conditionalIterator('2014-01-01', '2014-12-31', $germanHolidays);
foreach ($holidays as $holiday) {
    echo $holiday->format('d.m.Y, l') . PHP_EOL;
}
Example #6
0
 /**
  *
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     return $this->date == ToDate::normalizeDate($date);
 }
 /**
  *
  * @param  \DateTime $date
  * @return boolean
  */
 public function contains(\DateTime $date)
 {
     $days = $this->date->diff(ToDate::normalizeDate($date))->days;
     return $days % $this->offsetInDays === 0;
 }