Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GPBUtil.php

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

GPBUtil

Namespace

Google\Protobuf\Internal

Code

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);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal