Exemple #1
0
 public static function fromTime($time, $minDuration = null, $diff = null)
 {
     if ($minDuration === null && $diff === null) {
         $duration = new Duration();
         $duration->setValue(self::SIXTY_FOURTH);
         $duration->setDotted(false);
         $duration->setDoubleDotted(false);
         $duration->getDivision()->setEnters(3);
         $duration->getDivision()->setTimes(2);
         return self::fromTime($time, $duration);
     } else {
         if ($diff === null) {
             return self::fromTime($time, $minDuration, 10);
         }
     }
     $duration = clone $minDuration;
     $tmpDuration = new Duration();
     $tmpDuration->setValue(self::WHOLE);
     $tmpDuration->setDotted(true);
     $finish = false;
     while (!$finish) {
         $tmpTime = $tmpDuration->getTime();
         if ($tmpTime - $diff <= $time) {
             if (abs($tmpTime - $time) < abs($duration->getTime() - $time)) {
                 $duration = clone $tmpDuration;
             }
         }
         if ($tmpDuration->isDotted()) {
             $tmpDuration->setDotted(false);
         } else {
             if ($tmpDuration->getDivision()->isEqual(DivisionType::normal())) {
                 $tmpDuration->getDivision()->setEnters(3);
                 $tmpDuration->getDivision()->setTimes(2);
             } else {
                 $tmpDuration->setValue($tmpDuration->getValue() * 2);
                 $tmpDuration->setDotted(true);
                 $tmpDuration->getDivision()->setEnters(1);
                 $tmpDuration->getDivision()->setTimes(1);
             }
         }
         if ($tmpDuration->getValue() > self::SIXTY_FOURTH) {
             $finish = true;
         }
     }
     return $duration;
 }