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

Breadcrumb

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

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

GPBUtil

Namespace

Google\Protobuf\Internal

Code

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

API Navigation

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