function TimeSpan::setDuration
Same name in other branches
- 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/TimeSpan.php \Drupal\Core\TypedData\Plugin\DataType\TimeSpan::setDuration()
- 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/TimeSpan.php \Drupal\Core\TypedData\Plugin\DataType\TimeSpan::setDuration()
- 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/TimeSpan.php \Drupal\Core\TypedData\Plugin\DataType\TimeSpan::setDuration()
Overrides DurationInterface::setDuration
File
-
core/
lib/ Drupal/ Core/ TypedData/ Plugin/ DataType/ TimeSpan.php, line 40
Class
- TimeSpan
- The time span data type represents durations as number of seconds.
Namespace
Drupal\Core\TypedData\Plugin\DataTypeCode
public function setDuration(\DateInterval $duration, $notify = TRUE) {
// Note that this applies the assumption of 12 month's a 30 days and
// each year having 365 days. There is no accurate conversion for time spans
// exceeding a day.
$this->value = $duration->y * 365 * 24 * 60 * 60 + $duration->m * 30 * 24 * 60 * 60 + $duration->d * 24 * 60 * 60 + $duration->h * 60 * 60 + $duration->i * 60 + $duration->s;
// Notify the parent of any changes.
if ($notify && isset($this->parent)) {
$this->parent
->onChange($this->name);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.