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

Breadcrumb

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

trait TimeTrait

Provides common functionality for getting the time from a time-based UUID

@psalm-immutable

Hierarchy

  • trait \Ramsey\Uuid\Rfc4122\TimeTrait
1 file declares its use of TimeTrait
UuidV6.php in vendor/ramsey/uuid/src/Nonstandard/UuidV6.php

File

vendor/ramsey/uuid/src/Rfc4122/TimeTrait.php, line 31

Namespace

Ramsey\Uuid\Rfc4122
View source
trait TimeTrait {
    
    /**
     * Returns a DateTimeInterface object representing the timestamp associated
     * with the UUID
     *
     * @return DateTimeImmutable A PHP DateTimeImmutable instance representing
     *     the timestamp of a time-based UUID
     */
    public function getDateTime() : DateTimeInterface {
        $time = $this->timeConverter
            ->convertTime($this->fields
            ->getTimestamp());
        try {
            return new DateTimeImmutable('@' . $time->getSeconds()
                ->toString() . '.' . str_pad($time->getMicroseconds()
                ->toString(), 6, '0', STR_PAD_LEFT));
        } catch (Throwable $e) {
            throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
TimeTrait::getDateTime public function Returns a DateTimeInterface object representing the timestamp associated
with the UUID

API Navigation

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