Example #1
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.');
 }
Example #2
0
 public function testStaticMethod()
 {
     $this->assertEquals('1d 09:13:41', Duration::format('33:13:41,4'));
 }