Пример #1
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;
 }