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

Breadcrumb

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

function GenericTimeConverter::calculateTime

Overrides TimeConverterInterface::calculateTime

File

vendor/ramsey/uuid/src/Converter/Time/GenericTimeConverter.php, line 57

Class

GenericTimeConverter
GenericTimeConverter uses the provided calculator to calculate and convert time values

Namespace

Ramsey\Uuid\Converter\Time

Code

public function calculateTime(string $seconds, string $microseconds) : Hexadecimal {
    $timestamp = new Time($seconds, $microseconds);
    // Convert the seconds into a count of 100-nanosecond intervals.
    $sec = $this->calculator
        ->multiply($timestamp->getSeconds(), new IntegerObject(self::SECOND_INTERVALS));
    // Convert the microseconds into a count of 100-nanosecond intervals.
    $usec = $this->calculator
        ->multiply($timestamp->getMicroseconds(), new IntegerObject(self::MICROSECOND_INTERVALS));
    // Combine the seconds and microseconds intervals and add the count of
    // 100-nanosecond intervals from the Gregorian calendar epoch to the
    // Unix epoch. This gives us the correct count of 100-nanosecond
    // intervals since the Gregorian calendar epoch for the given seconds
    // and microseconds.
    
    /** @var IntegerObject $uuidTime */
    $uuidTime = $this->calculator
        ->add($sec, $usec, new IntegerObject(self::GREGORIAN_TO_UNIX_INTERVALS));
    $uuidTimeHex = str_pad($this->calculator
        ->toHexadecimal($uuidTime)
        ->toString(), 16, '0', STR_PAD_LEFT);
    return new Hexadecimal($uuidTimeHex);
}

API Navigation

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