From f239d6c806d5cd2c006fbd40db8ed2a375a14f9a Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Thu, 26 Jun 2025 21:21:05 -0500 Subject: [PATCH] Default to microtime() instead of DateTimeImmutable --- src/Generator/UnixTimeGenerator.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Generator/UnixTimeGenerator.php b/src/Generator/UnixTimeGenerator.php index 024ed51..a2615f1 100644 --- a/src/Generator/UnixTimeGenerator.php +++ b/src/Generator/UnixTimeGenerator.php @@ -15,7 +15,6 @@ declare(strict_types=1); namespace Ramsey\Uuid\Generator; use Brick\Math\BigInteger; -use DateTimeImmutable; use DateTimeInterface; use Ramsey\Uuid\Type\Hexadecimal; @@ -68,7 +67,12 @@ class UnixTimeGenerator implements TimeGeneratorInterface */ public function generate($node = null, ?int $clockSeq = null, ?DateTimeInterface $dateTime = null): string { - $time = ($dateTime ?? new DateTimeImmutable('now'))->format('Uv'); + if ($dateTime === null) { + $time = microtime(false); + $time = substr($time, 11) . substr($time, 2, 3); + } else { + $time = $dateTime->format('Uv'); + } if ($time > self::$time || ($dateTime !== null && $time !== self::$time)) { $this->randomize($time);