public function parse(DateTimeParseContext $context, $parseText, $position) { $length = strlen($parseText); if ($position < 0 || $position > $length) { throw new \OutOfRangeException(); } $style = $context->isStrict() ? $this->textStyle : null; $chrono = $context->getEffectiveChronology(); $it = null; if ($chrono === null || $chrono == IsoChronology::INSTANCE()) { $it = $this->provider->getTextIterator($this->field, $style, $context->getLocale()); } else { $it = $this->provider->getTextIterator2($chrono, $this->field, $style, $context->getLocale()); } if ($it !== null) { foreach ($it as $key => $value) { // fix numeric indices $key = strval($key); if ($context->subSequenceEquals($key, 0, $parseText, $position, strlen($key))) { return $context->setParsedField($this->field, $value, $position, $position + strlen($key)); } } if ($context->isStrict()) { return ~$position; } } return $this->numberPrinterParser()->parse($context, $parseText, $position); }
public function parse(DateTimeParseContext $context, $text, $position) { // simple looping parser to find the chronology if ($position < 0 || $position > strlen($text)) { throw new IndexOutOfBoundsException(); } $chronos = AbstractChronology::getAvailableChronologies(); $bestMatch = null; $matchLen = -1; foreach ($chronos as $chrono) { if ($this->textStyle === null) { $name = $chrono->getId(); } else { $name = $this->getChronologyName($chrono, $context->getLocale()); } $nameLen = strlen($name); if ($nameLen > $matchLen && $context->subSequenceEquals($text, $position, $name, 0, $nameLen)) { $bestMatch = $chrono; $matchLen = $nameLen; } } if ($bestMatch === null) { return ~$position; } $context->setParsed($bestMatch); return $position + $matchLen; }