Ejemplo n.º 1
0
 /**
  * @param \DateTime|string $date
  * @param string $dateFormat
  * @param \DateTimeZone|null $timezone
  *
  * @throws \Spryker\Shared\Library\Exception\UnsupportedDateFormatException
  *
  * @return string|null
  */
 protected function formatDate($date, $dateFormat, DateTimeZone $timezone = null)
 {
     if (empty($date)) {
         return null;
     }
     if (!array_key_exists($dateFormat, $this->context->dateFormat)) {
         throw new UnsupportedDateFormatException(sprintf('Unsupported date format: %s', $dateFormat));
     }
     if ($timezone === null) {
         return $this->context->dateTimeConvertTo($date, $this->context->dateFormat[$dateFormat]);
     }
     if (!$date instanceof \DateTime) {
         $date = new DateTime($date, $timezone);
     } else {
         $date->setTimezone($timezone);
     }
     return $date->format($this->context->dateFormat[$dateFormat]);
 }