/**
  * @param \Silex\Application $app
  *
  * @return void
  */
 public function register(Application $app)
 {
     $dateFormatter = new DateFormatter(Context::getInstance(Context::CONTEXT_ZED));
     $app['dateFormatter'] = $app->share(function () use($dateFormatter) {
         return $dateFormatter;
     });
     $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) use($dateFormatter) {
         $twig->addExtension(new DateFormatterTwigExtension($dateFormatter));
         return $twig;
     }));
 }
Exemple #2
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]);
 }
Exemple #3
0
 /**
  * @param string|\Spryker\Shared\Library\Context|null $context
  *
  * @return string
  */
 public function getTimezone($context = null)
 {
     $contextInstance = Context::getInstance($context);
     if ($contextInstance->has('timezone')) {
         return $contextInstance->get('timezone');
     } else {
         return Config::get(KernelConstants::PROJECT_TIMEZONE);
     }
 }
 /**
  * @throws \Exception
  * @return array
  */
 protected function getTwigExtensions()
 {
     return [new DateFormatterTwigExtension(new DateFormatter(Context::getInstance())), new PriceTwigExtensions()];
 }
 /**
  * @param \Spryker\Zed\Kernel\Container $container
  *
  * @return \Spryker\Zed\Kernel\Container
  */
 protected function addDateFormatter(Container $container)
 {
     $container[self::DATE_FORMATTER] = function () {
         return new DateFormatter(Context::getInstance(Context::CONTEXT_ZED));
     };
     return $container;
 }