From 9680a27246e0ee1b3d0ee1133201d68acb847d7b Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Wed, 27 Jan 2021 17:14:37 +0100 Subject: [PATCH] [Uid] Fix time to float conversion --- src/Symfony/Component/Uid/BinaryUtil.php | 2 +- src/Symfony/Component/Uid/Tests/UuidTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Uid/BinaryUtil.php b/src/Symfony/Component/Uid/BinaryUtil.php index 32e7e0dff3..bbba6b9c18 100644 --- a/src/Symfony/Component/Uid/BinaryUtil.php +++ b/src/Symfony/Component/Uid/BinaryUtil.php @@ -124,7 +124,7 @@ class BinaryUtil $time = self::add($time, self::TIME_OFFSET_COM2); if ($time >= self::TIME_OFFSET_COM2) { - $time = -1 * self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10); + $time = -1 * (self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10) + 1); } else { $time[0] = $time[0] & "\x7F"; $time = self::toBase($time, self::BASE10); diff --git a/src/Symfony/Component/Uid/Tests/UuidTest.php b/src/Symfony/Component/Uid/Tests/UuidTest.php index 5369477d3c..6b5b27f3b5 100644 --- a/src/Symfony/Component/Uid/Tests/UuidTest.php +++ b/src/Symfony/Component/Uid/Tests/UuidTest.php @@ -199,4 +199,13 @@ class UuidTest extends TestCase { $this->assertInstanceOf(CustomUuid::class, CustomUuid::fromString(self::A_UUID_V4)); } + + public function testGetTime() + { + $this->assertSame(103072857660.6847, ((new UuidV1('ffffffff-ffff-1fff-a456-426655440000'))->getTime())); + $this->assertSame(0.0000001, ((new UuidV1('13814001-1dd2-11b2-a456-426655440000'))->getTime())); + $this->assertSame(0.0, (new UuidV1('13814000-1dd2-11b2-a456-426655440000'))->getTime()); + $this->assertSame(-0.0000001, (new UuidV1('13813fff-1dd2-11b2-a456-426655440000'))->getTime()); + $this->assertSame(-12219292800.0, ((new UuidV1('00000000-0000-1000-a456-426655440000'))->getTime())); + } }