function GenericTimeConverter::convertTime
Overrides TimeConverterInterface::convertTime
File
-
vendor/
ramsey/ uuid/ src/ Converter/ Time/ GenericTimeConverter.php, line 95
Class
- GenericTimeConverter
- GenericTimeConverter uses the provided calculator to calculate and convert time values
Namespace
Ramsey\Uuid\Converter\TimeCode
public function convertTime(Hexadecimal $uuidTimestamp) : Time {
// From the total, subtract the number of 100-nanosecond intervals from
// the Gregorian calendar epoch to the Unix epoch. This gives us the
// number of 100-nanosecond intervals from the Unix epoch, which also
// includes the microtime.
$epochNanoseconds = $this->calculator
->subtract($this->calculator
->toInteger($uuidTimestamp), new IntegerObject(self::GREGORIAN_TO_UNIX_INTERVALS));
// Convert the 100-nanosecond intervals into seconds and microseconds.
$unixTimestamp = $this->calculator
->divide(RoundingMode::HALF_UP, 6, $epochNanoseconds, new IntegerObject(self::SECOND_INTERVALS));
$split = explode('.', (string) $unixTimestamp, 2);
return new Time($split[0], $split[1] ?? 0);
}