function GPBUtil::formatDuration
2 calls to GPBUtil::formatDuration()
- Message::jsonByteSize in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php - @ignore
- Message::serializeToJsonStream in vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ Message.php - @ignore
File
-
vendor/
google/ protobuf/ src/ Google/ Protobuf/ Internal/ GPBUtil.php, line 534
Class
Namespace
Google\Protobuf\InternalCode
public static function formatDuration($value) {
if (bccomp($value->getSeconds(), '315576000001') != -1) {
throw new GPBDecodeException('Duration number too large.');
}
if (bccomp($value->getSeconds(), '-315576000001') != 1) {
throw new GPBDecodeException('Duration number too small.');
}
$nanos = $value->getNanos();
if ($nanos === 0) {
return (string) $value->getSeconds();
}
if ($nanos % 1000000 === 0) {
$digits = 3;
}
elseif ($nanos % 1000 === 0) {
$digits = 6;
}
else {
$digits = 9;
}
$nanos = bcdiv($nanos, '1000000000', $digits);
return bcadd($value->getSeconds(), $nanos, $digits);
}