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

Breadcrumb

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

function UnixTimeGenerator::generate

@inheritDoc

Parameters

Hexadecimal|int|string|null $node Unused in this generator:

int|null $clockSeq Unused in this generator:

DateTimeInterface $dateTime A date-time instance to use when: generating bytes

Overrides TimeGeneratorInterface::generate

File

vendor/ramsey/uuid/src/Generator/UnixTimeGenerator.php, line 72

Class

UnixTimeGenerator
UnixTimeGenerator generates bytes that combine a 48-bit timestamp in milliseconds since the Unix Epoch with 80 random bits

Namespace

Ramsey\Uuid\Generator

Code

public function generate($node = null, ?int $clockSeq = null, ?DateTimeInterface $dateTime = null) : string {
    $time = ($dateTime ?? new DateTimeImmutable('now'))->format('Uv');
    if ($time > self::$time || $dateTime !== null && $time !== self::$time) {
        $this->randomize($time);
    }
    else {
        $time = $this->increment();
    }
    if ($this->intSize >= 8) {
        $time = substr(pack('J', (int) $time), -6);
    }
    else {
        $time = str_pad(BigInteger::of($time)->toBytes(false), 6, "\x00", STR_PAD_LEFT);
    }
    
    /** @var non-empty-string */
    return $time . pack('n*', self::$rand[1], self::$rand[2], self::$rand[3], self::$rand[4], self::$rand[5]);
}

API Navigation

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