PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.21
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.21
1.10.25 1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 All 169 releases
woocommerce-pos / vendor / ramsey / uuid / src / Rfc4122 / UuidV1.php

UuidV1.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.21, at vendor/ramsey/uuid/src/Rfc4122/UuidV1.php

93 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/uuid library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <[email protected]>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12
13 declare(strict_types=1);
14
15 namespace Ramsey\Uuid\Rfc4122;
16
17 use DateTimeImmutable;
18 use DateTimeInterface;
19 use Ramsey\Uuid\Codec\CodecInterface;
20 use Ramsey\Uuid\Converter\NumberConverterInterface;
21 use Ramsey\Uuid\Converter\TimeConverterInterface;
22 use Ramsey\Uuid\Exception\DateTimeException;
23 use Ramsey\Uuid\Exception\InvalidArgumentException;
24 use Ramsey\Uuid\Rfc4122\FieldsInterface as Rfc4122FieldsInterface;
25 use Ramsey\Uuid\Uuid;
26 use Throwable;
27
28 use function str_pad;
29
30 use const STR_PAD_LEFT;
31
32 /**
33 * Time-based, or version 1, UUIDs include timestamp, clock sequence, and node
34 * values that are combined into a 128-bit unsigned integer
35 *
36 * @psalm-immutable
37 */
38 final class UuidV1 extends Uuid implements UuidInterface
39 {
40 /**
41 * Creates a version 1 (time-based) UUID
42 *
43 * @param Rfc4122FieldsInterface $fields The fields from which to construct a UUID
44 * @param NumberConverterInterface $numberConverter The number converter to use
45 * for converting hex values to/from integers
46 * @param CodecInterface $codec The codec to use when encoding or decoding
47 * UUID strings
48 * @param TimeConverterInterface $timeConverter The time converter to use
49 * for converting timestamps extracted from a UUID to unix timestamps
50 */
51 public function __construct(
52 Rfc4122FieldsInterface $fields,
53 NumberConverterInterface $numberConverter,
54 CodecInterface $codec,
55 TimeConverterInterface $timeConverter
56 ) {
57 if ($fields->getVersion() !== Uuid::UUID_TYPE_TIME) {
58 throw new InvalidArgumentException(
59 'Fields used to create a UuidV1 must represent a '
60 . 'version 1 (time-based) UUID'
61 );
62 }
63
64 parent::__construct($fields, $numberConverter, $codec, $timeConverter);
65 }
66
67 /**
68 * Returns a DateTimeInterface object representing the timestamp associated
69 * with the UUID
70 *
71 * The timestamp value is only meaningful in a time-based UUID, which
72 * has version type 1.
73 *
74 * @return DateTimeImmutable A PHP DateTimeImmutable instance representing
75 * the timestamp of a version 1 UUID
76 */
77 public function getDateTime(): DateTimeInterface
78 {
79 $time = $this->timeConverter->convertTime($this->fields->getTimestamp());
80
81 try {
82 return new DateTimeImmutable(
83 '@'
84 . $time->getSeconds()->toString()
85 . '.'
86 . str_pad($time->getMicroseconds()->toString(), 6, '0', STR_PAD_LEFT)
87 );
88 } catch (Throwable $e) {
89 throw new DateTimeException($e->getMessage(), (int) $e->getCode(), $e);
90 }
91 }
92 }
93