The date data type.
The plain value of a date is an instance of the DrupalDateTime class. For setting the value any value supported by the __construct() of the DrupalDateTime class will work, including a DateTime object, a timestamp, a string date, or an array of date parts.
Expanded class hierarchy of Date
class Date extends TypedData implements TypedDataInterface {
/**
* The data value.
*
* @var DateTime
*/
protected $value;
/**
* Implements TypedDataInterface::setValue().
*/
public function setValue($value) {
// Don't try to create a date from an empty value.
// It would default to the current time.
if (!isset($value)) {
$this->value = $value;
}
else {
$this->value = $value instanceof DrupalDateTime ? $value : new DrupalDateTime($value);
if ($this->value
->hasErrors()) {
throw new InvalidArgumentException("Invalid date format given.");
}
}
}
/**
* Implements TypedDataInterface::getString().
*/
public function getString() {
return (string) $this
->getValue();
}
/**
* Implements TypedDataInterface::validate().
*/
public function validate() {
// TODO: Implement validate() method.
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Date:: |
protected | property | The data value. | |
Date:: |
public | function |
Implements TypedDataInterface::getString(). Overrides TypedData:: |
|
Date:: |
public | function |
Implements TypedDataInterface::setValue(). Overrides TypedData:: |
|
Date:: |
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 |