mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Add fromDateTime() to create version 1 UUIDs from DateTime instances
Fixes #28
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user