/** * Compares this time to another time. * <p> * The comparison is based on the time-line position of the local times within a day. * It is "consistent with equals", as defined by {@link Comparable}. * * @param LocalTime $other the other time to compare to, not null * @return int the comparator value, negative if less, positive if greater * @throws NullPointerException if {@code other} is null */ public function compareTo(LocalTime $other) { $cmp = Integer::compare($this->hour, $other->hour); if ($cmp == 0) { $cmp = Integer::compare($this->minute, $other->minute); if ($cmp == 0) { $cmp = Integer::compare($this->second, $other->second); if ($cmp == 0) { $cmp = Integer::compare($this->nano, $other->nano); } } } return $cmp; }
/** * Outputs this year as a {@code String}. * * @return string a string representation of this year, not null */ public function __toString() { return Integer::toString($this->year); }
private static function parseFraction($text, $parsed, $negate) { // regex limits to [0-9]{0,9} if ($parsed === null || strlen($parsed) === 0) { return 0; } try { $parsed = substr($parsed . "000000000", 0, 9); return Integer::parseInt($parsed) * $negate; } catch (\Exception $ex) { throw new DateTimeParseException("Text cannot be parsed to a Duration: fraction", $text, 0, $ex); } }
private static function parseNumber($text, $str, $negate) { if ($str === null) { return 0; } $val = Integer::parseInt($str); try { return Math::multiplyExact($val, $negate); } catch (ArithmeticException $ex) { throw new DateTimeParseException("Text cannot be parsed to a Period", $text, 0, $ex); } }