Example #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;
     }
 }
Example #2
0
 public function __sleep()
 {
     $sleep = parent::__sleep();
     $sleep[] = 'selected';
     $sleep[] = 'outside';
     return $sleep;
 }
Example #3
0
 public static function makeDatesListByRange(DateRange $range, IntervalUnit $unit, $hash = true)
 {
     $date = $unit->truncate($range->getStart());
     if ('Date' == get_class($range->getStart())) {
         $date = Date::create($date->toStamp());
     }
     $dates = [];
     do {
         if ($hash) {
             $dates[$date->toString()] = $date;
         } else {
             $dates[] = $date;
         }
         $date = $date->spawn('+ 1' . $unit->getName());
     } while ($range->getEnd()->toStamp() >= $date->toStamp());
     return $dates;
 }
Example #4
0
 public function countInRange(DateRange $range, $overlappedBounds = true)
 {
     $range = $range->toTimestampRange();
     $start = $this->truncate($range->getStart(), !$overlappedBounds);
     $end = $this->truncate($range->getEnd(), $overlappedBounds);
     if ($this->seconds) {
         $result = ($end->toStamp() - $start->toStamp()) / $this->seconds;
     } elseif ($this->days) {
         $epochStartTruncated = Date::create('1970-01-05');
         $startDifference = Date::dayDifference($epochStartTruncated, Date::create($start->toDate()));
         $endDifference = Date::dayDifference($epochStartTruncated, Date::create($end->toDate()));
         $result = ($endDifference - $startDifference) / $this->days;
     } elseif ($this->months) {
         $startMonthsCount = $start->getYear() * 12 + ($start->getMonth() - 1);
         $endMonthsCount = $end->getYear() * 12 + ($end->getMonth() - 1);
         $result = ($endMonthsCount - $startMonthsCount) / $this->months;
     }
     Assert::isEqual($result, (int) $result, 'floating point mistake, arguments: ' . $this->name . ', ' . $start->toStamp() . ', ' . $end->toStamp() . ', ' . 'result: ' . var_export($result, true));
     return (int) $result;
 }
Example #5
0
 public static function getHumanDay(Date $date, $wordDayNeed = true)
 {
     $today = Date::makeToday();
     $tomorrow = $today->spawn('+1 day');
     if ($date->toDate() == $today->toDate() && $wordDayNeed == true) {
         return 'сегодня';
     } elseif ($date->toDate() == $tomorrow->toDate() && $wordDayNeed == true) {
         return 'завтра';
     } else {
         return (int) $date->getDay() . ' ' . RussianTextUtils::getMonthInGenitiveCase($date->getMonth());
     }
 }
Example #6
0
 public function isOneDay()
 {
     return !$this->isOpen() && $this->start->toDate() == $this->end->toDate();
 }
Example #7
0
 public function getDayStartStamp()
 {
     if (!$this->getHour() && !$this->getMinute() && !$this->getSecond()) {
         return $this->dateTime->getTimestamp();
     } else {
         return parent::getDayStartStamp();
     }
 }
 /**
  * @throws WrongArgumentException
  * @return CalendarMonthWeekly
  **/
 public function setSelected(Date $day)
 {
     if (!isset($this->days[$day->toDate()])) {
         throw new WrongArgumentException($day->toDate() . ' not in calendar');
     }
     $this->days[$day->toDate()]->setSelected(true);
     return $this;
 }
Example #9
0
 protected function checkRanges(Date $date)
 {
     return (!$this->min || $this->min->toStamp() <= $date->toStamp()) && (!$this->max || $this->max->toStamp() >= $date->toStamp());
 }