Esempio n. 1
0
 /**
  * @return string
  */
 public function render()
 {
     if ($this->getValue() instanceof \DateTime) {
         $transformer = new FullTransformer($this->format ? $this->format : $this->container->getParameter('pedro_teixeira_grid.date.date_format'), $this->locale ? $this->locale : $this->container->getParameter('locale'));
         return $transformer->format($this->getValue());
     }
 }
Esempio n. 2
0
 /**
  * @param string|array $value
  */
 public function execute($value)
 {
     $transformer = new FullTransformer($this->container->getParameter('pedro_teixeira_grid.date.date_format'), $this->container->getParameter('locale'));
     $date = new \DateTime();
     $transformer->parse($date, $value);
     $queryBuilder = $this->getQueryBuilder();
     $where = $this->getQueryBuilder()->expr()->like($this->getIndex(), ":{$this->getIndexClean()}");
     if ($this->getWhere() == 'OR') {
         $queryBuilder->orWhere($where);
     } else {
         $queryBuilder->andWhere($where);
     }
     $queryBuilder->setParameter($this->getIndexClean(), $date->format('Y-m-d') . '%');
 }
Esempio n. 3
0
 /**
  * @param array $value
  *
  * @throws \Exception
  */
 public function execute($value)
 {
     if (!is_array($value) || count($value) != 2) {
         throw new \Exception('Value for date range comparison should have to values');
     }
     $queryBuilder = $this->getQueryBuilder();
     if (!empty($value[0])) {
         $transformer = new FullTransformer($this->container->getParameter('pedro_teixeira_grid.date.date_format'), $this->container->getParameter('locale'));
         $date = new \DateTime();
         $transformer->parse($date, $value[0]);
         $queryBuilder->andWhere($queryBuilder->expr()->gte($this->getIndex(), ":{$this->getIndexClean()}_1"))->setParameter(":{$this->getIndexClean()}_1", $date->format('Y-m-d') . ' 00:00:00');
     }
     if (!empty($value[1])) {
         $transformer = new FullTransformer($this->container->getParameter('pedro_teixeira_grid.date.date_format'), $this->container->getParameter('locale'));
         $date = new \DateTime();
         $transformer->parse($date, $value[1]);
         $queryBuilder->andWhere($queryBuilder->expr()->lte($this->getIndex(), ":{$this->getIndexClean()}_2"))->setParameter(":{$this->getIndexClean()}_2", $date->format('Y-m-d') . ' 23:59:59');
     }
 }
 /**
  * Parse string to a timestamp value
  *
  * @param  string   $value      String to convert to a time value
  * @param  int      $position   Position at which to start the parsing in $value (zero-based).
  *                              If no error occurs before $value is consumed, $parse_pos will
  *                              contain -1 otherwise it will contain the position at which parsing
  *                              ended. If $parse_pos > strlen($value), the parse fails immediately.
  *
  * @return string               Parsed value as a timestamp
  *
  * @see    http://www.php.net/manual/en/intldateformatter.parse.php
  *
  * @throws MethodArgumentNotImplementedException  When $position different than null, behavior not implemented
  */
 public function parse($value, &$position = null)
 {
     // We don't calculate the position when parsing the value
     if (null !== $position) {
         throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
     }
     StubIntl::setErrorCode(StubIntl::U_ZERO_ERROR);
     $dateTime = $this->createDateTime(0);
     $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
     return $transformer->parse($dateTime, $value);
 }
 /**
  * Parse string to a timestamp value
  *
  * @param string $value    String to convert to a time value
  * @param int    $position Position at which to start the parsing in $value (zero-based).
  *                              If no error occurs before $value is consumed, $parse_pos will
  *                              contain -1 otherwise it will contain the position at which parsing
  *                              ended. If $parse_pos > strlen($value), the parse fails immediately.
  *
  * @return string               Parsed value as a timestamp
  *
  * @see    http://www.php.net/manual/en/intldateformatter.parse.php
  *
  * @throws MethodArgumentNotImplementedException  When $position different than null, behavior not implemented
  */
 public function parse($value, &$position = null)
 {
     // We don't calculate the position when parsing the value
     if (null !== $position) {
         throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
     }
     $dateTime = $this->createDateTime(0);
     $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
     $timestamp = $transformer->parse($dateTime, $value);
     // behave like the intl extension. FullTransformer::parse() set the proper error
     $this->errorCode = StubIntl::getErrorCode();
     $this->errorMessage = StubIntl::getErrorMessage();
     return $timestamp;
 }
 /**
  * Parse string to a timestamp value
  *
  * @param  string   $value      String to convert to a time value
  * @param  int      $position   Position at which to start the parsing in $value (zero-based).
  *                              If no error occurs before $value is consumed, $parse_pos will
  *                              contain -1 otherwise it will contain the position at which parsing
  *                              ended. If $parse_pos > strlen($value), the parse fails immediately.
  * @return string               Parsed value as a timestamp
  * @see    http://www.php.net/manual/en/intldateformatter.parse.php
  * @throws MethodArgumentNotImplementedException  When $position different than null, behavior not implemented
  */
 public function parse($value, &$position = null)
 {
     // We don't calculate the position when parsing the value
     if (!is_null($position)) {
         throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
     }
     $dateTime = $this->createDateTime(0);
     $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
     return $transformer->parse($dateTime, $value);
 }