function UnixTimeConverter::calculateTime
Overrides TimeConverterInterface::calculateTime
File
-
vendor/
ramsey/ uuid/ src/ Converter/ Time/ UnixTimeConverter.php, line 43
Class
- UnixTimeConverter
- UnixTimeConverter converts Unix Epoch timestamps to/from hexadecimal values consisting of milliseconds elapsed since the Unix Epoch
Namespace
Ramsey\Uuid\Converter\TimeCode
public function calculateTime(string $seconds, string $microseconds) : Hexadecimal {
$timestamp = new Time($seconds, $microseconds);
// Convert the seconds into milliseconds.
$sec = $this->calculator
->multiply($timestamp->getSeconds(), new IntegerObject(self::MILLISECONDS));
// Convert the microseconds into milliseconds; the scale is zero because
// we need to discard the fractional part.
$usec = $this->calculator
->divide(RoundingMode::DOWN, 0, $timestamp->getMicroseconds(), new IntegerObject(self::MILLISECONDS));
/** @var IntegerObject $unixTime */
$unixTime = $this->calculator
->add($sec, $usec);
$unixTimeHex = str_pad($this->calculator
->toHexadecimal($unixTime)
->toString(), 12, '0', STR_PAD_LEFT);
return new Hexadecimal($unixTimeHex);
}