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

Breadcrumb

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

function UnixTimeConverter::calculateTime

Overrides TimeConverterInterface::calculateTime

File

vendor/ramsey/uuid/src/Converter/Time/UnixTimeConverter.php, line 43

Class

UnixTimeConverter
UnixTimeConverter converts Unix Epoch timestamps to/from hexadecimal values consisting of milliseconds elapsed since the Unix Epoch

Namespace

Ramsey\Uuid\Converter\Time

Code

public function calculateTime(string $seconds, string $microseconds) : Hexadecimal {
    $timestamp = new Time($seconds, $microseconds);
    // Convert the seconds into milliseconds.
    $sec = $this->calculator
        ->multiply($timestamp->getSeconds(), new IntegerObject(self::MILLISECONDS));
    // Convert the microseconds into milliseconds; the scale is zero because
    // we need to discard the fractional part.
    $usec = $this->calculator
        ->divide(RoundingMode::DOWN, 0, $timestamp->getMicroseconds(), new IntegerObject(self::MILLISECONDS));
    
    /** @var IntegerObject $unixTime */
    $unixTime = $this->calculator
        ->add($sec, $usec);
    $unixTimeHex = str_pad($this->calculator
        ->toHexadecimal($unixTime)
        ->toString(), 12, '0', STR_PAD_LEFT);
    return new Hexadecimal($unixTimeHex);
}

API Navigation

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