Default to microtime() instead of DateTimeImmutable

This commit is contained in:
Ben Ramsey
2025-06-26 21:21:05 -05:00
parent 4e0e23cc78
commit f239d6c806
+6 -2
View File
@@ -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);