function DeprecatedUuidMethodsTrait::getDateTime
Return value
DateTimeImmutable An immutable instance of DateTimeInterface
Throws
UnsupportedOperationException if UUID is not time-based
DateTimeException if DateTime throws an exception/error
Deprecated
In ramsey/uuid version 5.0.0, this will be removed. It is available at {
See also
UuidV1::getDateTime()}.
File
-
vendor/
ramsey/ uuid/ src/ DeprecatedUuidMethodsTrait.php, line 129
Class
- DeprecatedUuidMethodsTrait
- This trait encapsulates deprecated methods for ramsey/uuid; this trait and its methods will be removed in ramsey/uuid 5.0.0.
Namespace
Ramsey\UuidCode
public function getDateTime() : DateTimeInterface {
if ($this->fields
->getVersion() !== 1) {
throw new UnsupportedOperationException('Not a time-based UUID');
}
$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);
}
}