예제 #1
0
파일: Moment.php 프로젝트: badpenguin/atk-8
 /**
  * @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);
 }
예제 #2
0
 /**
  * @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;
 }
예제 #3
0
 /**
  * @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);
 }