{"record":{"id":"e7c279d442f01868","repo":"ramsey/uuid","slug":"not-a-time-based-uuid","errorCode":null,"errorMessage":"Not a time-based UUID","messagePattern":"Not a time-based UUID","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/DeprecatedUuidMethodsTrait.php","lineNumber":120,"sourceCode":"     * @deprecated This method will be removed in 5.0.0. There is no alternative recommendation, so plan accordingly.\n     */\n    public function getNumberConverter(): NumberConverterInterface\n    {\n        return $this->numberConverter;\n    }\n\n    /**\n     * @deprecated In ramsey/uuid version 5.0.0, this will be removed. It is available at {@see UuidV1::getDateTime()}.\n     *\n     * @return DateTimeImmutable An immutable instance of DateTimeInterface\n     *\n     * @throws UnsupportedOperationException if UUID is not time-based\n     * @throws DateTimeException if DateTime throws an exception/error\n     */\n    public function getDateTime(): DateTimeInterface\n    {\n        if ($this->fields->getVersion() !== 1) {\n            throw new UnsupportedOperationException('Not a time-based UUID');\n        }\n\n        $time = $this->timeConverter->convertTime($this->fields->getTimestamp());\n\n        try {\n            return new DateTimeImmutable(\n                '@'\n                . $time->getSeconds()->toString()\n                . '.'\n                . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT)\n            );\n        } catch (Throwable $e) {\n            throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);\n        }\n    }\n\n    /**\n     * @deprecated Use {@see UuidInterface::getFields()} to get a {@see \\Ramsey\\Uuid\\Fields\\FieldsInterface} instance.","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/DeprecatedUuidMethodsTrait.php#L102-L138","documentation":"Deprecated Uuid::getDateTime() (removed in ramsey/uuid 5.0; replaced by UuidV1::getDateTime()) converts the 60-bit timestamp of a time-based UUID into a DateTimeImmutable. If the UUID's version nibble is not 1 it throws UnsupportedOperationException, because only v1 UUIDs carry an extractable Gregorian timestamp.","triggerScenarios":"Uuid::uuid4()->getDateTime(); any generic UuidInterface handle (e.g. a decoded value or a primary key) where getDateTime() is called but the version is 2/3/4/5/6/7.","commonSituations":"Codebase migrated from v1 keys to v4 keys while keeping getDateTime() calls for created-at style logic; generic code that assumes every UUID is time-based; upgrading ramsey/uuid versions where the call now throws on non-v1 instances.","solutions":["Branch on the concrete class: if ($uuid instanceof \\Ramsey\\Uuid\\Rfc4122\\UuidV1) { $uuid->getDateTime(); } and skip/derive otherwise.","Generate v1 (Uuid::uuid1()) when you need the embedded timestamp - or better, UUIDv7 for time-ordered IDs.","Stop relying on the UUID for timestamps: store an explicit created_at column.","Complete the 5.0 migration path now: replace the deprecated trait methods with UuidV1-specific ones."],"exampleFix":"// before\n$createdAt = $uuid->getDateTime(); // throws UnsupportedOperationException on v4\n\n// after\n$createdAt = $uuid instanceof \\Ramsey\\Uuid\\Rfc4122\\UuidV1\n    ? $uuid->getDateTime()\n    : null;","handlingStrategy":"type-guard","validationCode":"if ($uuid instanceof \\Ramsey\\Uuid\\Rfc4122\\UuidV1) {\n    $createdAt = $uuid->getDateTime();\n} else {\n    $createdAt = null; // or read the stored created_at column\n}","typeGuard":"/** @psalm-assert-if-true \\Ramsey\\Uuid\\Rfc4122\\UuidV1 $uuid */\nfunction isTimeBasedUuid(UuidInterface $uuid): bool\n{\n    return $uuid instanceof \\Ramsey\\Uuid\\Rfc4122\\UuidV1;\n}","tryCatchPattern":"try {\n    $dateTime = $uuid->getDateTime();\n} catch (\\Ramsey\\Uuid\\Exception\\UnsupportedOperationException $e) {\n    $dateTime = null; // UUID carries no timestamp\n}","preventionTips":["Use instanceof UuidV1 before any timestamp extraction.","Prefer UuidV1::getDateTime() (non-deprecated) once you have narrowed the type.","Store real timestamps in a column instead of decoding them from identifiers.","If you need time-ordered IDs with modern tooling, generate Uuid::uuid7() and read its timestamp via fields."],"tags":["php","ramsey-uuid","deprecated","uuid-v1","get-date-time"],"backgroundTag":"uuid-not-time-based","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}