Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9680a27

Browse files
committed
[Uid] Fix time to float conversion
1 parent 8449d8a commit 9680a27

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Symfony/Component/Uid/BinaryUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static function timeToFloat(string $time): float
124124
$time = self::add($time, self::TIME_OFFSET_COM2);
125125

126126
if ($time >= self::TIME_OFFSET_COM2) {
127-
$time = -1 * self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10);
127+
$time = -1 * (self::toBase($time ^ "\xff\xff\xff\xff\xff\xff\xff\xff", self::BASE10) + 1);
128128
} else {
129129
$time[0] = $time[0] & "\x7F";
130130
$time = self::toBase($time, self::BASE10);

src/Symfony/Component/Uid/Tests/UuidTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,13 @@ public function testFromStringOnExtendedClassReturnsStatic()
199199
{
200200
$this->assertInstanceOf(CustomUuid::class, CustomUuid::fromString(self::A_UUID_V4));
201201
}
202+
203+
public function testGetTime()
204+
{
205+
$this->assertSame(103072857660.6847, ((new UuidV1('ffffffff-ffff-1fff-a456-426655440000'))->getTime()));
206+
$this->assertSame(0.0000001, ((new UuidV1('13814001-1dd2-11b2-a456-426655440000'))->getTime()));
207+
$this->assertSame(0.0, (new UuidV1('13814000-1dd2-11b2-a456-426655440000'))->getTime());
208+
$this->assertSame(-0.0000001, (new UuidV1('13813fff-1dd2-11b2-a456-426655440000'))->getTime());
209+
$this->assertSame(-12219292800.0, ((new UuidV1('00000000-0000-1000-a456-426655440000'))->getTime()));
210+
}
202211
}

0 commit comments

Comments
 (0)