The duration data type.
The plain value of a duration is an instance of the DateInterval class. For setting the value an instance of the DateInterval class, a ISO8601 string as supported by DateInterval::__construct, or an integer in seconds may be passed.
Expanded class hierarchy of Duration
class Duration extends TypedData implements TypedDataInterface {
/**
* The data value.
*
* @var \DateInterval
*/
protected $value;
/**
* Implements TypedDataInterface::setValue().
*/
public function setValue($value) {
if ($value instanceof DateInterval || !isset($value)) {
$this->value = $value;
}
elseif ((string) (int) $value === (string) $value) {
$this->value = new DateInterval('PT' . $value . 'S');
}
elseif (is_string($value)) {
// @todo: Add support for negative intervals on top of the DateInterval
// constructor.
$this->value = new DateInterval($value);
}
else {
throw new InvalidArgumentException("Invalid duration format given.");
}
}
/**
* Implements TypedDataInterface::getString().
*/
public function getString() {
// Generate an ISO 8601 formatted string as supported by
// DateInterval::__construct() and setValue().
return (string) $this
->getValue()
->format('%rP%yY%mM%dDT%hH%mM%sS');
}
/**
* Implements TypedDataInterface::validate().
*/
public function validate() {
// TODO: Implement validate() method.
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Duration:: |
protected | property | The data value. | |
Duration:: |
public | function |
Implements TypedDataInterface::getString(). Overrides TypedData:: |
|
Duration:: |
public | function |
Implements TypedDataInterface::setValue(). Overrides TypedData:: |
|
Duration:: |
public | function |
Implements TypedDataInterface::validate(). Overrides TypedDataInterface:: |
|
TypedData:: |
protected | property | The data definition. | |
TypedData:: |
public | function |
Implements TypedDataInterface::getDefinition(). Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Implements TypedDataInterface::getType(). Overrides TypedDataInterface:: |
|
TypedData:: |
public | function |
Implements TypedDataInterface::getValue(). Overrides TypedDataInterface:: |
7 |
TypedData:: |
public | function | Constructs a TypedData object given its definition. | 3 |