Пример #1
0
 /**
  * Returns the matching days for a given month
  * @param $month
  * @return int
  */
 public function getDaysInMonth($month)
 {
     if ($this->start->getYear() < $this->end->getYear()) {
         return cal_days_in_month(CAL_GREGORIAN, $month, $this->start->getYear());
     }
     $localStart = null;
     $localEnd = null;
     if ($this->start->getMonth() == $month) {
         $localStart = $this->start;
     }
     if ($this->end->getMonth() == $month) {
         $localEnd = $this->end;
     }
     if ($localStart == null) {
         $localStart = SimpleDateTime::createFromFormat("Y-m-d", $this->start->getYear() . "-{$month}-01");
     }
     if ($localEnd == null) {
         $localEnd = SimpleDateTime::createFromFormat("Y-m-d", $this->start->getYear() . "-" . ($month + 1) . "-01");
     }
     $diff = new TimeSpan($localStart, $localEnd);
     return $diff->getDaysBetween();
 }
Пример #2
0
 /**
  * Tells if the span is inside another span
  */
 public function isInside(TimeSpan $span)
 {
     return $this->isBetween($span->getStart(), $span->getEnd());
 }
 public static function create()
 {
     return new self(true, 0, false, TimeSpan::fromSeconds(30), 500, 500, 10, 20, TimeSpan::fromSeconds(2), 10, 1000, 0, SystemConsumerStrategies::ROUND_ROBIN);
 }
Пример #4
0
 /**
  * TimeSpan::Subtract()
  *
  * @param mixed $timeSpan
  * @return
  */
 function Subtract($timeSpan)
 {
     if (!is_object($timeSpan)) {
         $timeSpan = new TimeSpan($timeSpan);
     }
     $newTimeSpan = new TimeSpan();
     $carry = 0;
     $newTimeSpan->p_fractions = $this->p_fractions - $timeSpan->p_fractions;
     if ($newTimeSpan->p_fractions < 0) {
         $newTimeSpan->p_fractions += 1000;
         $carry = 1;
     }
     $newTimeSpan->p_seconds = $this->p_seconds - $timeSpan->p_seconds - $carry;
     if ($newTimeSpan->p_seconds < 0) {
         $newTimeSpan->p_seconds += 60;
         $carry = 1;
     } else {
         $carry = 0;
     }
     $newTimeSpan->p_minutes = $this->p_minutes - $timeSpan->p_minutes - $carry;
     if ($newTimeSpan->p_minutes < 0) {
         $newTimeSpan->p_minutes += 60;
         $carry = 1;
     } else {
         $carry = 0;
     }
     $newTimeSpan->p_hours = $this->p_hours - $timeSpan->p_hours - $carry;
     if ($newTimeSpan->p_hours < 0) {
         $newTimeSpan->p_hours += 24;
         $carry = 1;
     } else {
         $carry = 0;
     }
     $newTimeSpan->p_days = $this->p_days - $timeSpan->p_days - $carry;
     $newTimeSpan->ComputeTotals();
     return $newTimeSpan;
 }
Пример #5
0
<?php 
require_once dirname(__FILE__) . '/TimeSpan.php';
define('DAYS_PER_LEAP_YEAR', 366);
echo "One Leap Year has <strong>" . DAYS_PER_LEAP_YEAR . "</strong> years!";
$days = 5;
$timeSpan = new TimeSpan($days);
$hours = $timeSpan->calculateHours();
$minutes = $timeSpan->calculateMinutes();
echo "<br /><br />";
echo "<strong>{$days}</strong> days have <strong>{$hours}</strong> hours and <strong>{$minutes}</strong>!";
Пример #6
0
 public function wholeValues()
 {
     $t = new TimeSpan(91865);
     $this->assertEquals(5, $t->getWholeSeconds(), 'wholeSeconds');
     $this->assertEquals(31, $t->getWholeMinutes(), 'wholeMinutes');
     $this->assertEquals(1, $t->getWholeHours(), 'wholeHours');
     $this->assertEquals(1, $t->getWholeDays(), 'wholeDays');
 }