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

Breadcrumb

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

function PhpTimeConverter::calculateTime

Overrides TimeConverterInterface::calculateTime

File

vendor/ramsey/uuid/src/Converter/Time/PhpTimeConverter.php, line 82

Class

PhpTimeConverter
PhpTimeConverter uses built-in PHP functions and standard math operations available to the PHP programming language to provide facilities for converting parts of time into representations that may be used in UUIDs

Namespace

Ramsey\Uuid\Converter\Time

Code

public function calculateTime(string $seconds, string $microseconds) : Hexadecimal {
    $seconds = new IntegerObject($seconds);
    $microseconds = new IntegerObject($microseconds);
    // Calculate the count of 100-nanosecond intervals since the Gregorian
    // calendar epoch for the given seconds and microseconds.
    $uuidTime = (int) $seconds->toString() * self::SECOND_INTERVALS + (int) $microseconds->toString() * self::MICROSECOND_INTERVALS + self::GREGORIAN_TO_UNIX_INTERVALS;
    // Check to see whether we've overflowed the max/min integer size.
    // If so, we will default to a different time converter.
    
    /** @psalm-suppress RedundantCondition */
    if (!is_int($uuidTime)) {
        return $this->fallbackConverter
            ->calculateTime($seconds->toString(), $microseconds->toString());
    }
    return new Hexadecimal(str_pad(dechex($uuidTime), 16, '0', STR_PAD_LEFT));
}

API Navigation

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