/** * @param null $format * @param null|FormatsInterface $formatsInterface * * @return string */ public function format($format = null, $formatsInterface = null) { // set default format if ($format === null) { $format = \DateTime::ISO8601; } // handle diverse format types if ($formatsInterface instanceof FormatsInterface) { $format = $formatsInterface->format($format); } // handle ordinals if (strpos($format, 'S') !== false) { preg_match_all('/(\\wS)/', $format, $matches); if (count($matches) >= 1) { foreach ($matches[1] as $part) { $number = $this->format(substr($part, 0, 1)); $format = str_replace($part, $this->formatOrdinal($number), $format); } } } // handle text if (strpos($format, '[') !== false) { preg_match_all('/(\\[[^\\[]*\\])/', $format, $matches); foreach ($matches[1] as $part) { // split string to add \ in front of each character (required for PHP escaping) $result = str_split(trim($part, "[]")); // join string will \ in front of each character + add back to format $format = str_replace($part, "\\" . implode("\\", $result), $format); } } return parent::format($format); }
/** * @param null $format * @param null|FormatsInterface $formatsInterface * * @return string */ public function format($format = null, $formatsInterface = null) { // set default format if ($format === null) { $format = \DateTime::ISO8601; } // handle diverse format types if ($formatsInterface instanceof FormatsInterface) { $format = $formatsInterface->format($format); } // handle ordinals if (strpos($format, 'S') !== false) { preg_match_all('/(\\wS)/', $format, $matches); if (count($matches) >= 1) { foreach ($matches[1] as $part) { $token = substr($part, 0, 1); $number = $this->format($token); $format = str_replace($part, $this->formatOrdinal($number, $token), $format); } } } // handle text if (strpos($format, '[') !== false) { preg_match_all('/\\[([^\\[]*)\\]/', $format, $matches); foreach ($matches[1] as $part) { $format = preg_replace('/\\[' . $part . '\\]/u', preg_replace('/(\\w)/u', '\\\\\\1', $part), $format); } } // prepare locale formats $format = MomentLocale::prepareSpecialLocaleTags($format); // render moment $format = parent::format($format); // render locale format $format = MomentLocale::renderSpecialLocaleTags($format); return $format; }
/** * @param null $format * @param null|FormatsInterface $formatsInterface * * @return string */ public function format($format = NULL, $formatsInterface = NULL) { // set default format if ($format === NULL) { $format = \DateTime::ISO8601; } // handle diverse format types if ($formatsInterface instanceof FormatsInterface) { $format = $formatsInterface->format($format); } return parent::format($format); }