public function FrozenTime::getRequestMicroTime in Lingotek Translation 3.6.x
Same name and namespace in other branches
- 8.2 tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 4.0.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.0.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.1.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.2.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.3.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.4.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.5.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.7.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
- 3.8.x tests/modules/frozenintime/src/FrozenTime.php \Drupal\frozenintime\FrozenTime::getRequestMicroTime()
Returns the timestamp for the current request with microsecond precision.
This method should be used to obtain the current system time, with microsecond precision, at the start of the request. It will be the same value for the life of the request (even for long execution times).
If the request is not available it will fallback to the current system time with microsecond precision.
This method can replace instances of
$request_time_float = $_SERVER['REQUEST_TIME_FLOAT'];
$request_time_float = $requestStack
->getCurrentRequest()->server
->get('REQUEST_TIME_FLOAT');
$request_time_float = $request->server
->get('REQUEST_TIME_FLOAT');
and many instances of
$microtime = microtime();
$microtime = microtime(TRUE);
with
$request_time = \Drupal::time()
->getRequestMicroTime();
or the equivalent using the injected service.
Using the time service, rather than other methods, is especially important when creating tests, which require predictable timestamps.
Return value
float A Unix timestamp with a fractional portion.
Overrides TimeInterface::getRequestMicroTime
See also
\Drupal\Component\Datetime\TimeInterface::getRequestTime()
\Drupal\Component\Datetime\TimeInterface::getCurrentTime()
\Drupal\Component\Datetime\TimeInterface::getCurrentMicroTime()
File
- tests/
modules/ frozenintime/ src/ FrozenTime.php, line 26
Class
- FrozenTime
- Time implementation were time is frozen
Namespace
Drupal\frozenintimeCode
public function getRequestMicroTime() {
return static::MY_BIRTHDAY;
}