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;
 }
 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)
 {
     $length = strlen($text);
     if ($position > $length || $position < 0) {
         throw new \OutOfRangeException();
     }
     if ($context->subSequenceEquals($text, $position, $this->literal, 0, strlen($this->literal)) == false) {
         return ~$position;
     }
     return $position + strlen($this->literal);
 }
 public function parse(DateTimeParseContext $context, $text, $position)
 {
     $pos = $position;
     $end = $pos + strlen($text);
     $gmtText = "GMT";
     // TODO: get localized version of 'GMT'
     if ($gmtText !== null) {
         if (!$context->subSequenceEquals($text, $pos, $gmtText, 0, strlen($gmtText))) {
             return ~$position;
         }
         $pos += strlen($gmtText);
     }
     // parse normal plus/minus offset
     if ($pos == $end) {
         return $context->setParsedField(ChronoField::OFFSET_SECONDS(), 0, $position, $pos);
     }
     $sign = $text[$pos];
     // IOOBE if invalid position
     if ($sign == '+') {
         $negative = 1;
     } else {
         if ($sign == '-') {
             $negative = -1;
         } else {
             return $context->setParsedField(ChronoField::OFFSET_SECONDS(), 0, $position, $pos);
         }
     }
     $pos++;
     $m = 0;
     $s = 0;
     if ($this->style == TextStyle::FULL()) {
         $h1 = $this->getDigit($text, $pos++);
         $h2 = $this->getDigit($text, $pos++);
         if ($h1 < 0 || $h2 < 0 || $text[$pos++] !== ':') {
             return ~$position;
         }
         $h = $h1 * 10 + $h2;
         $m1 = $this->getDigit($text, $pos++);
         $m2 = $this->getDigit($text, $pos++);
         if ($m1 < 0 || $m2 < 0) {
             return ~$position;
         }
         $m = $m1 * 10 + $m2;
         if ($pos + 2 < $end && $text[$pos] === ':') {
             $s1 = $this->getDigit($text, $pos + 1);
             $s2 = $this->getDigit($text, $pos + 2);
             if ($s1 >= 0 && $s2 >= 0) {
                 $s = $s1 * 10 + $s2;
                 $pos += 3;
             }
         }
     } else {
         $h = $this->getDigit($text, $pos++);
         if ($h < 0) {
             return ~$position;
         }
         if ($pos < $end) {
             $h2 = $this->getDigit($text, $pos);
             if ($h2 >= 0) {
                 $h = $h * 10 + $h2;
                 $pos++;
             }
             if ($pos + 2 < $end && $text[$pos] === ':') {
                 if ($pos + 2 < $end && $text[$pos] === ':') {
                     $m1 = $this->getDigit($text, $pos + 1);
                     $m2 = $this->getDigit($text, $pos + 2);
                     if ($m1 >= 0 && $m2 >= 0) {
                         $m = $m1 * 10 + $m2;
                         $pos += 3;
                         if ($pos + 2 < $end && $text[$pos] === ':') {
                             $s1 = $this->getDigit($text, $pos + 1);
                             $s2 = $this->getDigit($text, $pos + 2);
                             if ($s1 >= 0 && $s2 >= 0) {
                                 $s = $s1 * 10 + $s2;
                                 $pos += 3;
                             }
                         }
                     }
                 }
             }
         }
     }
     $offsetSecs = $negative * ($h * 3600 + $m * 60 + $s);
     return $context->setParsedField(ChronoField::OFFSET_SECONDS(), $offsetSecs, $position, $pos);
 }
 public function parse(DateTimeParseContext $context, $text, $position)
 {
     $length = strlen($text);
     $noOffsetLen = strlen($this->noOffsetText);
     if ($noOffsetLen === 0) {
         if ($position === $length) {
             return $context->setParsedField(ChronoField::OFFSET_SECONDS(), 0, $position, $position);
         }
     } else {
         if ($position === $length) {
             return ~$position;
         }
         if ($context->subSequenceEquals($text, $position, $this->noOffsetText, 0, $noOffsetLen)) {
             return $context->setParsedField(ChronoField::OFFSET_SECONDS(), 0, $position, $position + $noOffsetLen);
         }
     }
     // parse normal plus/minus offset
     $sign = $text[$position];
     // IOOBE if invalid position
     if ($sign === '+' || $sign === '-') {
         // starts
         $negative = $sign === '-' ? -1 : 1;
         $array = [0, 0, 0, 0];
         $array[0] = $position + 1;
         if (($this->parseNumber($array, 1, $text, true) || $this->parseNumber($array, 2, $text, $this->type >= 3) || $this->parseNumber($array, 3, $text, false)) === false) {
             // success
             $offsetSecs = $negative * ($array[1] * 3600 + $array[2] * 60 + $array[3]);
             return $context->setParsedField(ChronoField::OFFSET_SECONDS(), $offsetSecs, $position, $array[0]);
         }
     }
     // handle special case of empty no offset text
     if ($noOffsetLen === 0) {
         return $context->setParsedField(ChronoField::OFFSET_SECONDS(), 0, $position, $position + $noOffsetLen);
     }
     return ~$position;
 }