Example #1
0
 public function testMethodChaining()
 {
     $Pace = new Pace(0, 1, Pace::MIN_PER_KM);
     $this->assertEquals('3:00', $Pace->setTime(180)->value());
     $this->assertEquals('6:00', $Pace->setDistance(0.5)->value());
 }
Example #2
0
 /**
  * Compare
  * Both pace objects must have the same unit and the unit must be comparable.
  * @param \Runalyze\Activity\Pace $other
  * @param boolean $raw [optional]
  * @throws \InvalidArgumentException
  * @return string
  */
 public function compareTo(Pace $other, $raw = false)
 {
     if ($this->Unit != $other->unit()) {
         throw new \InvalidArgumentException('Pace objects must have the same unit.');
     }
     if ($this->secondsPerKm() == 0 || $other->secondsPerKm() == 0) {
         return '';
     }
     switch ($this->Unit) {
         case self::MIN_PER_KM:
         case self::MIN_PER_100M:
         case self::MIN_PER_500M:
             $first = new Duration($this->value());
             $second = new Duration($other->value());
             $string = Duration::format(abs($first->seconds() - $second->seconds()));
             return $this->formatComparison($string, $first->seconds() <= $second->seconds(), $raw);
         case self::KM_PER_H:
         case self::M_PER_S:
             $value = abs((double) str_replace(',', '.', $this->value()) - (double) str_replace(',', '.', $other->value()));
             $string = number_format($value, 1, ',', '.');
             return $this->formatComparison($string, $other->secondsPerKm() >= $this->secondsPerKm(), $raw);
     }
     throw new \InvalidArgumentException('Pace unit ' . $this->Unit . ' cannot be compared.');
 }