[Uid] Fix time to float conversion
This commit is contained in:
parent
8449d8a328
commit
9680a27246
@ -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);
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user