class FormattedDateDiff
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/Datetime/FormattedDateDiff.php \Drupal\Core\Datetime\FormattedDateDiff
- 10 core/lib/Drupal/Core/Datetime/FormattedDateDiff.php \Drupal\Core\Datetime\FormattedDateDiff
- 9 core/lib/Drupal/Core/Datetime/FormattedDateDiff.php \Drupal\Core\Datetime\FormattedDateDiff
- 8.9.x core/lib/Drupal/Core/Datetime/FormattedDateDiff.php \Drupal\Core\Datetime\FormattedDateDiff
Contains a formatted time difference.
Hierarchy
- class \Drupal\Core\Datetime\FormattedDateDiff implements \Drupal\Core\Render\RenderableInterface, \Drupal\Core\Cache\CacheableDependencyInterface uses \Drupal\Core\Cache\UnchangingCacheableDependencyTrait
Expanded class hierarchy of FormattedDateDiff
1 file declares its use of FormattedDateDiff
- DateTest.php in core/
tests/ Drupal/ Tests/ Core/ Datetime/ DateTest.php
File
-
core/
lib/ Drupal/ Core/ Datetime/ FormattedDateDiff.php, line 12
Namespace
Drupal\Core\DatetimeView source
class FormattedDateDiff implements RenderableInterface, CacheableDependencyInterface {
use UnchangingCacheableDependencyTrait;
/**
* Creates a new FormattedDateDiff instance.
*
* @param string $string
* The formatted time difference.
* @param int $maxAge
* The maximum time in seconds that this string may be cached.
*/
public function __construct(protected $string, protected $maxAge) {
}
/**
* @return string
* The actual formatted time difference.
*/
public function getString() {
return $this->string;
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return $this->maxAge;
}
/**
* {@inheritdoc}
*/
public function toRenderable() {
return [
'#markup' => $this->string,
'#cache' => [
'max-age' => $this->maxAge,
],
];
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
|---|---|---|---|---|---|
| FormattedDateDiff::getCacheMaxAge | public | function | Overrides UnchangingCacheableDependencyTrait::getCacheMaxAge | ||
| FormattedDateDiff::getString | public | function | |||
| FormattedDateDiff::toRenderable | public | function | Overrides RenderableInterface::toRenderable | ||
| FormattedDateDiff::__construct | public | function | Creates a new FormattedDateDiff instance. | ||
| UnchangingCacheableDependencyTrait::getCacheContexts | public | function | 1 | ||
| UnchangingCacheableDependencyTrait::getCacheTags | public | function | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.