Пример #1
0
 public static function compare(Date $left, Date $right)
 {
     if ($left->toStamp() == $right->toStamp()) {
         return 0;
     } else {
         return $left->toStamp() > $right->toStamp() ? 1 : -1;
     }
 }
Пример #2
0
 public function __construct(Date $base, $weekStart = Timestamp::WEEKDAY_MONDAY)
 {
     $firstDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-01');
     $lastDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-' . date('t', $base->toStamp()));
     $start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
     $end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
     $this->monthRange = DateRange::create()->lazySet($firstDayOfMonth, $lastDayOfMonth);
     $this->fullRange = DateRange::create()->lazySet($start, $end);
     $rawDays = $this->fullRange->split();
     $this->fullLength = 0;
     foreach ($rawDays as $rawDay) {
         $day = CalendarDay::create($rawDay->toStamp());
         if ($this->monthRange->contains($day)) {
             $day->setOutside(false);
         } else {
             $day->setOutside(true);
         }
         $this->days[$day->toDate()] = $day;
         $weekNumber = floor($this->fullLength / 7);
         if (!isset($this->weeks[$weekNumber])) {
             $this->weeks[$weekNumber] = CalendarWeek::create();
         }
         $this->weeks[$weekNumber]->addDay($day);
         ++$this->fullLength;
     }
     ++$this->fullLength;
 }
Пример #3
0
 /**
  * result is read-only, no error checking
  * @return DateRange
  **/
 public function lightCopyOnClip(DateRange $range)
 {
     $copy = DateRange::create();
     if ($range->start && ($this->start && $range->start->toStamp() > $this->start->toStamp() || !$this->start)) {
         $copy->start = $range->start;
     } else {
         $copy->start = $this->start;
     }
     if ($range->end && ($this->end && $range->end->toStamp() < $this->end->toStamp() || !$this->end)) {
         $copy->end = $range->end;
     } else {
         $copy->end = $this->end;
     }
     return $copy;
 }
Пример #4
0
 protected function checkRanges(Date $date)
 {
     return (!$this->min || $this->min->toStamp() <= $date->toStamp()) && (!$this->max || $this->max->toStamp() >= $date->toStamp());
 }