/**
  * 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());
 }
 /**
  * @dataProvider provider_patternLocalWeekBasedYearDate
  */
 public function test_print_WeekBasedYear($pattern, $expectedText, LocalDate $date)
 {
     $dtf = DateTimeFormatter::ofPatternLocale($pattern, $this->locale);
     $result = $dtf->format($date);
     $weekDef = WeekFields::ofLocale($this->locale);
     $this->assertEquals($result, $expectedText, "Incorrect formatting for " - $pattern - ", weekDef: " . $weekDef);
 }
 /**
  * @dataProvider provider_patternLocalWeekBasedYearDate
  */
 public function test_parse_WeekBasedYear($pattern, $text, $pos, $expectedPos, LocalDate $expectedValue)
 {
     $ppos = new ParsePosition($pos);
     $b = (new DateTimeFormatterBuilder())->appendPattern($pattern);
     $dtf = $b->toFormatter2($this->locale);
     $parsed = $dtf->parseUnresolved($text, $ppos);
     if ($ppos->getErrorIndex() != -1) {
         $this->assertEquals($ppos->getErrorIndex(), $expectedPos);
     } else {
         $weekDef = WeekFields::ofLocale($this->locale);
         $this->assertEquals($ppos->getIndex(), $expectedPos, "Incorrect ending parse position");
         $this->assertEquals($parsed->isSupported($weekDef->dayOfWeek()), strpos($pattern, 'e') >= 0);
         $this->assertEquals($parsed->isSupported($weekDef->weekOfWeekBasedYear()), strpos($pattern, 'w') >= 0);
         $this->assertEquals($parsed->isSupported($weekDef->weekBasedYear()), strpos($pattern, 'Y') >= 0);
         // ensure combination resolves into a date
         $result = LocalDate::parseWith($text, $dtf);
         $this->assertEquals($result, $expectedValue, "LocalDate incorrect for " . $pattern . ", {$weekDef}: " . $weekDef);
     }
 }