function GenericTimeConverter::calculateTime
Overrides TimeConverterInterface::calculateTime
File
-
vendor/
ramsey/ uuid/ src/ Converter/ Time/ GenericTimeConverter.php, line 57
Class
- GenericTimeConverter
- GenericTimeConverter uses the provided calculator to calculate and convert time values
Namespace
Ramsey\Uuid\Converter\TimeCode
public function calculateTime(string $seconds, string $microseconds) : Hexadecimal {
$timestamp = new Time($seconds, $microseconds);
// Convert the seconds into a count of 100-nanosecond intervals.
$sec = $this->calculator
->multiply($timestamp->getSeconds(), new IntegerObject(self::SECOND_INTERVALS));
// Convert the microseconds into a count of 100-nanosecond intervals.
$usec = $this->calculator
->multiply($timestamp->getMicroseconds(), new IntegerObject(self::MICROSECOND_INTERVALS));
// Combine the seconds and microseconds intervals and add the count of
// 100-nanosecond intervals from the Gregorian calendar epoch to the
// Unix epoch. This gives us the correct count of 100-nanosecond
// intervals since the Gregorian calendar epoch for the given seconds
// and microseconds.
/** @var IntegerObject $uuidTime */
$uuidTime = $this->calculator
->add($sec, $usec, new IntegerObject(self::GREGORIAN_TO_UNIX_INTERVALS));
$uuidTimeHex = str_pad($this->calculator
->toHexadecimal($uuidTime)
->toString(), 16, '0', STR_PAD_LEFT);
return new Hexadecimal($uuidTimeHex);
}