3 namespace Drupal\Core\TypedData\Plugin\DataType;
5 use Drupal\Core\TypedData\Type\DurationInterface;
8 * The duration ISO8601 data type.
10 * The plain value of this data type is a ISO8601 duration string.
13 * id = "duration_iso8601",
14 * label = @Translation("Duration")
17 class DurationIso8601 extends StringData implements DurationInterface {
22 public function getDuration() {
24 // @todo: Add support for negative intervals on top of the DateInterval
26 return new \DateInterval($this->value);
33 public function setDuration(\DateInterval $duration, $notify = TRUE) {
34 // Generate an ISO 8601 formatted string as supported by
35 // DateInterval::__construct() and setValue().
36 $this->value = $duration->format('%rP%yY%mM%dDT%hH%mM%sS');
37 // Notify the parent of any changes.
38 if ($notify && isset($this->parent)) {
39 $this->parent->onChange($this->name);