/** * @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()); } }
/** * Format the date/time value (timestamp) as a string * * @param mixed $timestamp Unix timestamp to format * * @return string The formatted value * * @see http://www.php.net/manual/en/intldateformatter.format.php * * @throws NotImplementedException If one of the formatting characters is not implemented */ public function format($timestamp) { // intl allows timestamps to be passed as arrays - we don't if (is_array($timestamp)) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported'); } if (!is_int($timestamp)) { // behave like the intl extension StubIntl::setErrorCode(StubIntl::U_ILLEGAL_ARGUMENT_ERROR); return false; } $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId()); $formatted = $transformer->format($this->createDateTime($timestamp)); return $formatted; }
/** * Format the date/time value (timestamp) as a string * * @param mixed $timestamp Unix timestamp to format * * @return string The formatted value * * @see http://www.php.net/manual/en/intldateformatter.format.php * * @throws NotImplementedException If one of the formatting characters is not implemented */ public function format($timestamp) { // intl allows timestamps to be passed as arrays - we don't if (is_array($timestamp)) { $message = version_compare(\PHP_VERSION, '5.3.4', '>=') ? 'Only integer unix timestamps and DateTime objects are supported' : 'Only integer unix timestamps are supported'; throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, $message); } // behave like the intl extension $argumentError = null; if (version_compare(\PHP_VERSION, '5.3.4', '<') && !is_int($timestamp)) { $argumentError = 'datefmt_format: takes either an array or an integer timestamp value '; } elseif (version_compare(\PHP_VERSION, '5.3.4', '>=') && !is_int($timestamp) && !$timestamp instanceof \DateTime) { $argumentError = 'datefmt_format: takes either an array or an integer timestamp value or a DateTime object'; if (version_compare(\PHP_VERSION, '5.5.0-dev', '>=') && !is_int($timestamp)) { $argumentError = sprintf('datefmt_format: string \'%s\' is not numeric, which would be required for it to be a valid date', $timestamp); } } if (null !== $argumentError) { StubIntl::setError(StubIntl::U_ILLEGAL_ARGUMENT_ERROR, $argumentError); $this->errorCode = StubIntl::getErrorCode(); $this->errorMessage = StubIntl::getErrorMessage(); return false; } // As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances if (version_compare(\PHP_VERSION, '5.3.4', '>=') && $timestamp instanceof \DateTime) { $timestamp = $timestamp->getTimestamp(); } $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId()); $formatted = $transformer->format($this->createDateTime($timestamp)); // behave like the intl extension StubIntl::setError(StubIntl::U_ZERO_ERROR); $this->errorCode = StubIntl::getErrorCode(); $this->errorMessage = StubIntl::getErrorMessage(); return $formatted; }
/** * Format the date/time value (timestamp) as a string * * @param mixed $timestamp Unix timestamp to format * * @return string The formatted value * * @see http://www.php.net/manual/en/intldateformatter.format.php * * @throws NotImplementedException If one of the formatting characters is not implemented */ public function format($timestamp) { // intl allows timestamps to be passed as arrays - we don't if (is_array($timestamp)) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported'); } // behave like the intl extension if (!is_int($timestamp) && version_compare(\PHP_VERSION, '5.3.4', '<')) { StubIntl::setErrorCode(StubIntl::U_ILLEGAL_ARGUMENT_ERROR); return false; } // As of PHP 5.3.4, IntlDateFormatter::format() accepts DateTime instances if ($timestamp instanceof \DateTime && version_compare(\PHP_VERSION, '5.3.4', '>=')) { $timestamp = $timestamp->getTimestamp(); } $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId()); $formatted = $transformer->format($this->createDateTime($timestamp)); return $formatted; }
/** * Format the date/time value (timestamp) as a string * * @param mixed $timestamp Unix timestamp to format * @return string The formatted value * @see http://www.php.net/manual/en/intldateformatter.format.php * @throws NotImplementedException If one of the formatting characters is not implemented */ public function format($timestamp) { if (!is_int($timestamp)) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'timestamp', $timestamp, 'Only integer unix timestamps are supported'); } $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId()); $formatted = $transformer->format($this->createDateTime($timestamp)); return $formatted; }