{"record":{"id":"6a6afa1fa2476a8c","repo":"ramsey/uuid","slug":"the-generated-time-of-s-is-larger-than-expected","errorCode":null,"errorMessage":"The generated time of '%s' is larger than expected","messagePattern":"The generated time of '(.+?)' is larger than expected","errorType":"exception","errorClass":"TimeSourceException","httpStatus":null,"severity":"error","filePath":"src/Generator/DefaultTimeGenerator.php","lineNumber":82,"sourceCode":"            try {\n                // This does not use \"stable storage\"; see RFC 9562, section 6.3.\n                $clockSeq = random_int(0, 0x3fff);\n            } catch (Throwable $exception) {\n                throw new RandomSourceException($exception->getMessage(), (int) $exception->getCode(), $exception);\n            }\n        }\n\n        $time = $this->timeProvider->getTime();\n\n        $uuidTime = $this->timeConverter->calculateTime(\n            $time->getSeconds()->toString(),\n            $time->getMicroseconds()->toString()\n        );\n\n        $timeHex = str_pad($uuidTime->toString(), 16, '0', STR_PAD_LEFT);\n\n        if (strlen($timeHex) !== 16) {\n            throw new TimeSourceException(sprintf('The generated time of \\'%s\\' is larger than expected', $timeHex));\n        }\n\n        $timeBytes = (string) hex2bin($timeHex);\n\n        return $timeBytes[4] . $timeBytes[5] . $timeBytes[6] . $timeBytes[7]\n            . $timeBytes[2] . $timeBytes[3] . $timeBytes[0] . $timeBytes[1]\n            . pack('n*', $clockSeq) . $node;\n    }\n\n    /**\n     * Uses the node provider given when constructing this instance to get the node ID (usually a MAC address)\n     *\n     * @param int | string | null $node A node value that may be used to override the node provider\n     *\n     * @return string 6-byte binary string representation of the node\n     *\n     * @throws InvalidArgumentException\n     */","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/ramsey/uuid/blob/da5b521600a707d2dd097598464bd3090de850f5/src/Generator/DefaultTimeGenerator.php#L64-L100","documentation":"DefaultTimeGenerator converts the current time into 60-bit UUID time and pads it to exactly 16 hex characters; if the converted value exceeds that width, str_pad cannot shrink it and the generator throws TimeSourceException - the wall clock (or time provider) produced a time too large for a version 1 UUID to encode.","triggerScenarios":"A system/container clock set far beyond the v1 range (post-year-5236 territory), or - far more commonly - a custom TimeProviderInterface implementation returning wrong units, e.g. microseconds passed where seconds are expected, inflating the value ~1e6x.","commonSituations":"Broken VM/container clocks or NTP misconfiguration; hand-rolled time providers with unit bugs; test doubles / FixedTimeProvider seeded with huge values; embedded boards with unset clocks defaulting to far-future epochs.","solutions":["Fix the clock: verify date/NTP inside the container or host (date -u).","Audit custom TimeProvider implementations - getTime() must return seconds plus separate microseconds.","In tests, keep FixedTimeProvider timestamps within a sane epoch range.","Catch TimeSourceException at generation boundaries and fail loudly rather than persisting anything derived from a bad clock."],"exampleFix":"// before (custom provider passing microseconds as seconds)\nreturn new Time((int) ($now * 1000000), 0); // TimeSourceException: > 16 hex chars\n\n// after\n[$usec, $sec] = explode(' ', microtime());\nreturn new Time((int) $sec, (int) ($usec * 1000000)); // seconds + microseconds","handlingStrategy":"try-catch","validationCode":"// Sanity-check the wall clock before relying on v1 generation.\n$now = time();\nif ($now < 1000000000 || $now > 2000000000) { // ~2001..2033 window\n    throw new RuntimeException('system clock is not sane; refusing to generate v1 UUIDs');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $uuid = Uuid::uuid1();\n} catch (\\Ramsey\\Uuid\\Exception\\TimeSourceException $e) {\n    // clock/time-provider produced an unrepresentable time\n    $fallback = Uuid::uuid4(); // non-time identifier that always works\n    // alert ops: clock skew or provider unit bug\n}","preventionTips":["Run NTP (or the container equivalent) and verify date -u on deploy.","Keep custom TimeProvider units straight: seconds in one field, microseconds in the other.","Bound FixedTimeProvider values in tests to realistic epochs.","Fail loudly on TimeSourceException rather than caching or persisting the bad time."],"tags":["php","ramsey-uuid","time-generator","uuid-v1","system-clock","time-provider"],"backgroundTag":"system-clock-out-of-range","analyzedSha":"da5b521600a707d2dd097598464bd3090de850f5","analyzedAt":"2026-08-21T01:35:29.252Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}