/**
  * @param string $pattern
  * @param bool $saveSymbolsOnly
  * @param IDateTimeFixer|NULL $dateTimeFixer
  */
 public function __construct($pattern, $saveSymbolsOnly = self::SAVE_SYMBOLS_ONLY, IDateTimeFixer $dateTimeFixer = NULL)
 {
     if ($saveSymbolsOnly) {
         Tools::checkPattern($pattern);
     }
     $this->pattern = $pattern;
     $this->dateTimeFixer = $dateTimeFixer !== NULL ? $dateTimeFixer : new SimplePatternParsingFixer();
 }
 /**
  * @param string $pattern
  * @return bool[]
  */
 protected function resolveTimePatternPartPresence($pattern)
 {
     if (!isset($this->symbolTypePresence[$pattern])) {
         $this->symbolTypePresence[$pattern] = [];
         foreach ($this->configuration as $symbolName => $symbolConfiguration) {
             $this->symbolTypePresence[$pattern][$symbolName] = Tools::isAnyOfSymbolsInPattern($symbolConfiguration['symbols'], $pattern);
         }
     }
     return $this->symbolTypePresence[$pattern];
 }
Exemplo n.º 3
0
 /**
  * @param string $format
  * @return string
  */
 public function format(string $format) : string
 {
     if (Tools::isAnyOfSymbolsInPattern(self::NOT_ALLOWED_FORMAT_SYMBOLS, $format)) {
         throw new LogicException(sprintf('Invalid pattern. Only [%s] symbols are allowed.', implode(', ', self::ALLOWED_FORMAT_SYMBOLS)));
     }
     return $this->toInternalDateTime()->format($format);
 }