示例#1
0
 public function testFromString()
 {
     $Time = new Duration("1:17:21");
     $this->assertEquals(1 * 3600 + 17 * 60 + 21, $Time->seconds());
     $this->assertEquals(17 * 60 + 21, $Time->fromString("17:21")->seconds());
     $this->assertEquals(3 * 60 + 54.2, $Time->fromString("3:54,2")->seconds());
     $this->assertEquals(12, $Time->fromString("0:12")->seconds());
     $this->assertEquals(10.05, $Time->fromString("10.05")->seconds());
 }
示例#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.');
 }