Exemplo n.º 1
0
 public function overlap(DayTime $b)
 {
     // Seconds from commencement of the week;
     $selfMinutes = $this->getDay() * self::MINUTES_IN_DAY + $this->getHour() * self::MINUTES_IN_HOUR + $this->getMinute();
     $bMinutes = $b->getDay() * self::MINUTES_IN_DAY + $b->getHour() * self::MINUTES_IN_HOUR + $b->getMinute();
     if ($selfMinutes > $bMinutes) {
         // I start before the other does
         return min($bMinutes + $b->getDuration(), $selfMinutes + $this->getDuration()) - $selfMinutes;
     }
     // Does this DayTime end overlap with the $b period?
     if ($selfMinutes + $this->getDuration() < $bMinutes) {
         // No overlap - return 0;
         return 0;
     }
     $selfEnd = $selfMinutes + $this->getDuration();
     $bEnd = $bMinutes + $b->getDuration();
     if ($selfEnd < $bEnd) {
         // I end before $b ends
         return $bMinutes + ($bEnd - $selfEnd);
     }
     return $b->getDuration();
 }
Exemplo n.º 2
0
 public static function getWeekdayDate($which, $weekday, $month, $year = null)
 {
     if ($month instanceof DayTime) {
         $year = $month->getYear();
         $month = $month->getMonth();
     }
     $which = min(5, max(1, (int) $which)) - 1;
     $wdOf1st = (int) date("N", strtotime("{$year}-{$month}-01"));
     $firstWd = 1 + ($weekday + 7 - $wdOf1st) % 7;
     if ($which <= 3) {
         return $which * 7 + $firstWd;
     } else {
         if ($which * 7 + $firstWd <= DayTime::daysInMonth($month, $year)) {
             return $which * 7 + $firstWd;
         } else {
             return $firstWd + 7 * 3;
         }
     }
 }