[Uid] Fix time to float conversion

This commit is contained in:
Thomas Calvet 2021-01-27 17:14:37 +01:00
parent 8449d8a328
commit 9680a27246
2 changed files with 10 additions and 1 deletions

View File

@ -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);

View File

@ -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()));
}
}