You are here

public function DateTimeFormatterStrategy::hydrate in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/zendframework/zend-hydrator/src/Strategy/DateTimeFormatterStrategy.php \Zend\Hydrator\Strategy\DateTimeFormatterStrategy::hydrate()

Converts date time string to DateTime instance for injecting to object

Parameters

mixed|string $value:

Return value

mixed|DateTime

Overrides StrategyInterface::hydrate

File

vendor/zendframework/zend-hydrator/src/Strategy/DateTimeFormatterStrategy.php, line 66

Class

DateTimeFormatterStrategy

Namespace

Zend\Hydrator\Strategy

Code

public function hydrate($value) {
  if ($value === '' || $value === null) {
    return;
  }
  if ($this->timezone) {
    $hydrated = DateTime::createFromFormat($this->format, $value, $this->timezone);
  }
  else {
    $hydrated = DateTime::createFromFormat($this->format, $value);
  }
  return $hydrated ?: $value;
}