Add fromDateTime() to create version 1 UUIDs from DateTime instances

Fixes #28
This commit is contained in:
Ben Ramsey
2020-02-03 00:48:41 -06:00
parent e269c16cd4
commit 5fa4eb4f17
13 changed files with 265 additions and 5 deletions
+12
View File
@@ -33,6 +33,7 @@ use Ramsey\Uuid\Rfc4122\UuidV2;
use Ramsey\Uuid\Rfc4122\UuidV3;
use Ramsey\Uuid\Rfc4122\UuidV4;
use Ramsey\Uuid\Rfc4122\UuidV5;
use Ramsey\Uuid\Type\Hexadecimal;
use Ramsey\Uuid\Type\Time;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidFactory;
@@ -961,6 +962,17 @@ class UuidTest extends TestCase
$this->assertTrue($uuid->equals($fromIntegerUuid));
}
public function testFromDateTime(): void
{
/** @var UuidV1 $uuid */
$uuid = Uuid::fromString('ff6f8cb0-c57d-11e1-8b21-0800200c9a66');
$dateTime = $uuid->getDateTime();
$fromDateTimeUuid = Uuid::fromDateTime($dateTime, new Hexadecimal('0800200c9a66'), 2849);
$this->assertTrue($uuid->equals($fromDateTimeUuid));
}
/**
* This test ensures that Ramsey\Uuid passes the same test cases
* as the Python UUID library.