mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-25 17:45:35 +03:00
Support microtime in returned DateTimeInterface instances
Fixes #90 and supersedes #93.
This commit is contained in:
@@ -7,6 +7,7 @@ namespace Ramsey\Uuid\Test\Converter\Time;
|
||||
use Ramsey\Uuid\Converter\Time\GenericTimeConverter;
|
||||
use Ramsey\Uuid\Math\BrickMathCalculator;
|
||||
use Ramsey\Uuid\Test\TestCase;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
|
||||
class GenericTimeConverterTest extends TestCase
|
||||
{
|
||||
@@ -88,14 +89,15 @@ class GenericTimeConverterTest extends TestCase
|
||||
/**
|
||||
* @dataProvider provideConvertTime
|
||||
*/
|
||||
public function testConvertTime(string $uuidTimestamp, string $unixTimestamp): void
|
||||
public function testConvertTime(Hexadecimal $uuidTimestamp, string $unixTimestamp, string $microSeconds): void
|
||||
{
|
||||
$calculator = new BrickMathCalculator();
|
||||
$converter = new GenericTimeConverter($calculator);
|
||||
|
||||
$result = $converter->convertTime($uuidTimestamp);
|
||||
|
||||
$this->assertSame($unixTimestamp, $result);
|
||||
$this->assertSame($unixTimestamp, $result->getSeconds()->toString());
|
||||
$this->assertSame($microSeconds, $result->getMicroSeconds()->toString());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,38 +107,44 @@ class GenericTimeConverterTest extends TestCase
|
||||
{
|
||||
return [
|
||||
[
|
||||
'uuidTimestamp' => '135606608744910000',
|
||||
'uuidTimestamp' => new Hexadecimal('1e1c57dff6f8cb0'),
|
||||
'unixTimestamp' => '1341368074',
|
||||
'microSeconds' => '491000',
|
||||
],
|
||||
[
|
||||
'uuidTimestamp' => '137979051595210230',
|
||||
'uuidTimestamp' => new Hexadecimal('1ea333764c71df6'),
|
||||
'unixTimestamp' => '1578612359',
|
||||
'microSeconds' => '521023',
|
||||
],
|
||||
[
|
||||
'uuidTimestamp' => '1152921504599999990',
|
||||
'uuidTimestamp' => new Hexadecimal('fffffffff9785f6'),
|
||||
'unixTimestamp' => '103072857659',
|
||||
'microSeconds' => '999999',
|
||||
],
|
||||
|
||||
// This is the last possible time supported by v1 UUIDs. When
|
||||
// converted to a Unix timestamp, the microseconds are lost.
|
||||
// 60038-03-11 05:36:10.955161
|
||||
[
|
||||
'uuidTimestamp' => '18446744073709551610',
|
||||
'uuidTimestamp' => new Hexadecimal('fffffffffffffffa'),
|
||||
'unixTimestamp' => '1832455114570',
|
||||
'microSeconds' => '955161',
|
||||
],
|
||||
|
||||
// This is the earliest possible date supported by v1 UUIDs:
|
||||
// 1582-10-15 00:00:00.000000
|
||||
[
|
||||
'uuidTimestamp' => '0',
|
||||
'uuidTimestamp' => new Hexadecimal('000000000000'),
|
||||
'unixTimestamp' => '-12219292800',
|
||||
'microSeconds' => '0',
|
||||
],
|
||||
|
||||
// This is the Unix epoch:
|
||||
// 1970-01-01 00:00:00.000000
|
||||
[
|
||||
'uuidTimestamp' => '122192928000000000',
|
||||
'uuidTimestamp' => new Hexadecimal('1b21dd213814000'),
|
||||
'unixTimestamp' => '0',
|
||||
'microSeconds' => '0',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user