{"record":{"id":"b28d68eeec8fb92d","repo":"ramsey/uuid","slug":"not-a-time-based-uuid-b28d68","errorCode":null,"errorMessage":"Not a time-based UUID","messagePattern":"Not a time-based UUID","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/Lazy/LazyUuidFromString.php","lineNumber":394,"sourceCode":"        assert($fields instanceof \\Ramsey\\Uuid\\Rfc4122\\FieldsInterface);\n\n        return $instance->getNumberConverter()->fromHex($fields->getTimeMid()->toString());\n    }\n\n    /**\n     * @deprecated Use {@see UuidInterface::getFields()} to get a {@see FieldsInterface} instance. If it is a\n     *     {@see Rfc4122FieldsInterface} instance, you may call {@see Rfc4122FieldsInterface::getTimestamp()} and use\n     *     the arbitrary-precision math library of your choice to convert it to a string integer.\n     */\n    public function getTimestamp(): string\n    {\n        $instance = ($this->unwrapped ?? $this->unwrap());\n\n        $fields = $instance->getFields();\n        assert($fields instanceof \\Ramsey\\Uuid\\Rfc4122\\FieldsInterface);\n\n        if ($fields->getVersion() !== 1) {\n            throw new UnsupportedOperationException('Not a time-based UUID');\n        }\n\n        return $instance->getNumberConverter()->fromHex($fields->getTimestamp()->toString());\n    }\n\n    public function toUuidV1(): UuidV1\n    {\n        $instance = ($this->unwrapped ?? $this->unwrap());\n\n        if ($instance instanceof UuidV1) {\n            return $instance;\n        }\n\n        assert($instance instanceof UuidV6);\n\n        return $instance->toUuidV1();\n    }\n","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Lazy/LazyUuidFromString.php#L376-L412","documentation":"Uuid::fromString() returns a LazyUuidFromString that unwraps to the concrete UUID on demand. Its deprecated getTimestamp() asserts the fields implement Rfc4122FieldsInterface and then requires version 1; any other version (2, 3, 4, 5, 6, 7, 8, nil, max) throws UnsupportedOperationException because only Gregorian time-based UUIDs carry an RFC timestamp.","triggerScenarios":"Calling getTimestamp() on the result of Uuid::fromString() or on a UUID obtained from external input whose version is not 1 — e.g. Uuid::fromString('0f4b0fd0-0f4b-4ef0-9f3f-0242ac110002')->getTimestamp() (version 4). Note version 6/7 timestamps live on getDateTime()/fields instead.","commonSituations":"Log/DB parsing code that assumes all incoming UUIDs are v1 (e.g. legacy primary keys migrated to v4/v7); refactoring that feeds arbitrary UUID strings into timestamp extraction; version changes upstream in another service's ID generation.","solutions":["Branch on version first: if ($uuid->getFields()->getVersion() === 1) { ... } before calling getTimestamp()","Follow the deprecation: use $uuid->getFields() (Rfc4122FieldsInterface) and its getTimestamp() with your own math library","If extracting time from v6/v7 UUIDs, use getDateTime() on those classes instead of getTimestamp()"],"exampleFix":"// before\n$ts = \\Ramsey\\Uuid\\Uuid::fromString($userInput)->getTimestamp();\n\n// after\n$uuid = \\Ramsey\\Uuid\\Uuid::fromString($userInput);\n$fields = $uuid->getFields();\nif (!$fields instanceof \\Ramsey\\Uuid\\Rfc4122\\FieldsInterface || $fields->getVersion() !== 1) {\n    throw new InvalidArgumentException('Expected a time-based (v1) UUID');\n}\n$ts = $uuid->getTimestamp();","handlingStrategy":"validation","validationCode":"$uuid = \\Ramsey\\Uuid\\Uuid::fromString($input);\n$fields = $uuid->getFields();\nif ($fields instanceof \\Ramsey\\Uuid\\Rfc4122\\FieldsInterface && $fields->getVersion() === 1) {\n    $ts = $uuid->getTimestamp();\n}","typeGuard":"function isTimeBasedV1(\\Ramsey\\Uuid\\UuidInterface $uuid): bool\n{\n    $f = $uuid->getFields();\n    return $f instanceof \\Ramsey\\Uuid\\Rfc4122\\FieldsInterface && $f->getVersion() === 1;\n}","tryCatchPattern":"try {\n    $ts = $uuid->getTimestamp();\n} catch (\\Ramsey\\Uuid\\Exception\\UnsupportedOperationException $e) {\n    // not a version 1 UUID; skip timestamp extraction\n}","preventionTips":["Branch on getFields()->getVersion() before version-specific accessors","Treat UUID strings from external systems as unknown-version until inspected","For v6/v7 use getDateTime() instead of getTimestamp()"],"tags":["php","ramsey-uuid","timestamp","uuid-version","deprecated-api","lazy-loading"],"backgroundTag":"wrong-uuid-version-for-operation","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}