function GPBUtil::parseDuration
2 calls to GPBUtil::parseDuration()
- Message::convertJsonValueToProtoValue in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php - Message::mergeFromJsonArray in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ GPBUtil.php, line 504
Class
Namespace
Google\Protobuf\InternalCode
public static function parseDuration($value) {
if (strlen($value) < 2 || substr($value, -1) !== "s") {
throw new GPBDecodeException("Missing s after duration string");
}
$number = substr($value, 0, -1);
if (bccomp($number, "315576000001") != -1) {
throw new GPBDecodeException("Duration number too large.");
}
if (bccomp($number, "-315576000001") != 1) {
throw new GPBDecodeException("Duration number too small.");
}
$pos = strrpos($number, ".");
if ($pos !== false) {
$seconds = substr($number, 0, $pos);
if (bccomp($seconds, 0) < 0) {
$nanos = bcmul("0" . substr($number, $pos), -1000000000);
}
else {
$nanos = bcmul("0" . substr($number, $pos), 1000000000);
}
}
else {
$seconds = $number;
$nanos = 0;
}
$duration = new Duration();
$duration->setSeconds($seconds);
$duration->setNanos($nanos);
return $duration;
}