/** * Gets the printerParser to use based on the field and the locale. * * @param Locale $locale the locale to use, not null * @return DateTimePrinterParser the formatter, not null * @throws IllegalArgumentException if the formatter cannot be found */ private function printerParser(Locale $locale) { $weekDef = WeekFields::ofLocale($locale); $field = null; switch ($this->chr) { case 'Y': $field = $weekDef->weekBasedYear(); if ($this->count === 2) { return new ReducedPrinterParser($field, 2, 2, 0, ReducedPrinterParser::BASE_DATE(), 0); } else { return new NumberPrinterParser($field, $this->count, 19, $this->count < 4 ? SignStyle::NORMAL() : SignStyle::EXCEEDS_PAD(), -1); } case 'e': case 'c': $field = $weekDef->dayOfWeek(); break; case 'w': $field = $weekDef->weekOfWeekBasedYear(); break; case 'W': $field = $weekDef->weekOfMonth(); break; default: throw new IllegalStateException("unreachable"); } return new NumberPrinterParser($field, $this->count == 2 ? 2 : 1, 2, SignStyle::NOT_NEGATIVE()); }
private function parseField($cur, $count, TemporalField $field) { $standalone = false; switch ($cur) { case 'u': case 'y': if ($count === 2) { $this->appendValueReduced2($field, 2, 2, ReducedPrinterParser::BASE_DATE()); } else { if ($count < 4) { $this->appendValue3($field, $count, 19, SignStyle::NORMAL()); } else { $this->appendValue3($field, $count, 19, SignStyle::EXCEEDS_PAD()); } } break; /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case 'c': if ($count === 2) { throw new IllegalArgumentException("Invalid pattern \"cc\""); } /*fallthrough*/ /*fallthrough*/ case 'L': /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case 'q': $standalone = true; /*fallthrough*/ /*fallthrough*/ case 'M': case 'Q': case 'E': case 'e': switch ($count) { case 1: case 2: if ($cur == 'c' || $cur == 'e') { $this->appendInternal(new WeekBasedFieldPrinterParser($cur, $count)); } else { if ($cur == 'E') { $this->appendText2($field, TextStyle::SHORT()); } else { if ($count === 1) { $this->appendValue($field); } else { $this->appendValue2($field, 2); } } } break; case 3: $this->appendText2($field, $standalone ? TextStyle::SHORT_STANDALONE() : TextStyle::SHORT()); break; case 4: $this->appendText2($field, $standalone ? TextStyle::FULL_STANDALONE() : TextStyle::FULL()); break; case 5: $this->appendText2($field, $standalone ? TextStyle::NARROW_STANDALONE() : TextStyle::NARROW()); break; default: throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'a': if ($count === 1) { $this->appendText2($field, TextStyle::SHORT()); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'G': switch ($count) { case 1: case 2: case 3: $this->appendText2($field, TextStyle::SHORT()); break; case 4: $this->appendText2($field, TextStyle::FULL()); break; case 5: $this->appendText2($field, TextStyle::NARROW()); break; default: throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'S': $this->appendFraction(ChronoField::NANO_OF_SECOND(), $count, $count, false); break; case 'F': if ($count == 1) { $this->appendValue($field); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'd': case 'h': case 'H': case 'k': case 'K': case 'm': case 's': if ($count === 1) { $this->appendValue($field); } else { if ($count === 2) { $this->appendValue2($field, $count); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } } break; case 'D': if ($count == 1) { $this->appendValue($field); } else { if ($count <= 3) { $this->appendValue2($field, $count); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } } break; default: if ($count == 1) { $this->appendValue($field); } else { $this->appendValue2($field, $count); } break; } }