function PhpTimeConverter::calculateTime
Overrides TimeConverterInterface::calculateTime
File
-
vendor/
ramsey/ uuid/ src/ Converter/ Time/ PhpTimeConverter.php, line 82
Class
- PhpTimeConverter
- PhpTimeConverter uses built-in PHP functions and standard math operations available to the PHP programming language to provide facilities for converting parts of time into representations that may be used in UUIDs
Namespace
Ramsey\Uuid\Converter\TimeCode
public function calculateTime(string $seconds, string $microseconds) : Hexadecimal {
$seconds = new IntegerObject($seconds);
$microseconds = new IntegerObject($microseconds);
// Calculate the count of 100-nanosecond intervals since the Gregorian
// calendar epoch for the given seconds and microseconds.
$uuidTime = (int) $seconds->toString() * self::SECOND_INTERVALS + (int) $microseconds->toString() * self::MICROSECOND_INTERVALS + self::GREGORIAN_TO_UNIX_INTERVALS;
// Check to see whether we've overflowed the max/min integer size.
// If so, we will default to a different time converter.
/** @psalm-suppress RedundantCondition */
if (!is_int($uuidTime)) {
return $this->fallbackConverter
->calculateTime($seconds->toString(), $microseconds->toString());
}
return new Hexadecimal(str_pad(dechex($uuidTime), 16, '0', STR_PAD_LEFT));
}