public function Date::setValue

Implements TypedDataInterface::setValue().

Overrides TypedData::setValue

File

drupal/core/lib/Drupal/Core/TypedData/Type/Date.php, line 34
Definition of Drupal\Core\TypedData\Type\Date.

Class

Date
The date data type.

Namespace

Drupal\Core\TypedData\Type

Code

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.");
    }
  }
}