diff options
author | Mario <mario@mariovavti.com> | 2022-10-11 18:29:06 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2022-10-11 18:29:06 +0000 |
commit | ccd826f63a7a4c7e442fab8a70d9c4c84808b417 (patch) | |
tree | fbbde69114acba764cf6b735433c53e099fd19c5 /vendor/ramsey/uuid/src/Rfc4122/UuidV2.php | |
parent | 5e5f0aa955d86743a14531bed98501b59140ab1f (diff) | |
download | volse-hubzilla-ccd826f63a7a4c7e442fab8a70d9c4c84808b417.tar.gz volse-hubzilla-ccd826f63a7a4c7e442fab8a70d9c4c84808b417.tar.bz2 volse-hubzilla-ccd826f63a7a4c7e442fab8a70d9c4c84808b417.zip |
Revert "update composer libs"
This reverts commit 5e5f0aa955d86743a14531bed98501b59140ab1f.
Diffstat (limited to 'vendor/ramsey/uuid/src/Rfc4122/UuidV2.php')
-rw-r--r-- | vendor/ramsey/uuid/src/Rfc4122/UuidV2.php | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php index c8ccbe422..74906f050 100644 --- a/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php +++ b/vendor/ramsey/uuid/src/Rfc4122/UuidV2.php @@ -14,33 +14,28 @@ declare(strict_types=1); namespace Ramsey\Uuid\Rfc4122; +use DateTimeImmutable; +use DateTimeInterface; use Ramsey\Uuid\Codec\CodecInterface; use Ramsey\Uuid\Converter\NumberConverterInterface; use Ramsey\Uuid\Converter\TimeConverterInterface; +use Ramsey\Uuid\Exception\DateTimeException; use Ramsey\Uuid\Exception\InvalidArgumentException; use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface; use Ramsey\Uuid\Type\Integer as IntegerObject; use Ramsey\Uuid\Uuid; +use Throwable; use function hexdec; +use function str_pad; + +use const STR_PAD_LEFT; /** * DCE Security version, or version 2, UUIDs include local domain identifier, * local ID for the specified domain, and node values that are combined into a * 128-bit unsigned integer * - * It is important to note that a version 2 UUID suffers from some loss of - * fidelity of the timestamp, due to replacing the time_low field with the - * local identifier. When constructing the timestamp value for date - * purposes, we replace the local identifier bits with zeros. As a result, - * the timestamp can be off by a range of 0 to 429.4967295 seconds (or 7 - * minutes, 9 seconds, and 496730 microseconds). - * - * Astute observers might note this value directly corresponds to 2^32 - 1, - * or 0xffffffff. The local identifier is 32-bits, and we have set each of - * these bits to 0, so the maximum range of timestamp drift is 0x00000000 - * to 0xffffffff (counted in 100-nanosecond intervals). - * * @link https://publications.opengroup.org/c311 DCE 1.1: Authentication and Security Services * @link https://publications.opengroup.org/c706 DCE 1.1: Remote Procedure Call * @link https://pubs.opengroup.org/onlinepubs/9696989899/chap5.htm#tagcjh_08_02_01_01 DCE 1.1: Auth & Sec, ยง5.2.1.1 @@ -52,8 +47,6 @@ use function hexdec; */ final class UuidV2 extends Uuid implements UuidInterface { - use TimeTrait; - /** * Creates a version 2 (DCE Security) UUID * @@ -82,6 +75,41 @@ final class UuidV2 extends Uuid implements UuidInterface } /** + * Returns a DateTimeInterface object representing the timestamp associated + * with the UUID + * + * It is important to note that a version 2 UUID suffers from some loss of + * fidelity of the timestamp, due to replacing the time_low field with the + * local identifier. When constructing the timestamp value for date + * purposes, we replace the local identifier bits with zeros. As a result, + * the timestamp can be off by a range of 0 to 429.4967295 seconds (or 7 + * minutes, 9 seconds, and 496730 microseconds). + * + * Astute observers might note this value directly corresponds to 2^32 - 1, + * or 0xffffffff. The local identifier is 32-bits, and we have set each of + * these bits to 0, so the maximum range of timestamp drift is 0x00000000 + * to 0xffffffff (counted in 100-nanosecond intervals). + * + * @return DateTimeImmutable A PHP DateTimeImmutable instance representing + * the timestamp of a version 2 UUID + */ + public function getDateTime(): DateTimeInterface + { + $time = $this->timeConverter->convertTime($this->fields->getTimestamp()); + + try { + return new DateTimeImmutable( + '@' + . $time->getSeconds()->toString() + . '.' + . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT) + ); + } catch (Throwable $e) { + throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e); + } + } + + /** * Returns the local domain used to create this version 2 UUID */ public function getLocalDomain(): int |