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

Breadcrumb

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

function GenericTimeConverter::convertTime

Overrides TimeConverterInterface::convertTime

File

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

Class

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

Namespace

Ramsey\Uuid\Converter\Time

Code

public function convertTime(Hexadecimal $uuidTimestamp) : Time {
    // From the total, subtract the number of 100-nanosecond intervals from
    // the Gregorian calendar epoch to the Unix epoch. This gives us the
    // number of 100-nanosecond intervals from the Unix epoch, which also
    // includes the microtime.
    $epochNanoseconds = $this->calculator
        ->subtract($this->calculator
        ->toInteger($uuidTimestamp), new IntegerObject(self::GREGORIAN_TO_UNIX_INTERVALS));
    // Convert the 100-nanosecond intervals into seconds and microseconds.
    $unixTimestamp = $this->calculator
        ->divide(RoundingMode::HALF_UP, 6, $epochNanoseconds, new IntegerObject(self::SECOND_INTERVALS));
    $split = explode('.', (string) $unixTimestamp, 2);
    return new Time($split[0], $split[1] ?? 0);
}

API Navigation

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