/**
  * 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());
 }
 /**
  * Constructor.
  *
  * @param TemporalField $field the field to format, validated not null
  * @param int $minWidth the minimum field width, from 1 to 10
  * @param int $maxWidth the maximum field width, from 1 to 10
  * @param int $baseValue the base value
  * @param ChronoLocalDate|null $baseDate the base date
  * @param int $subsequentWidth the subsequentWidth for this instance
  * @throws DateTimeException
  * @throws IllegalArgumentException
  */
 public function __construct(TemporalField $field, $minWidth, $maxWidth, $baseValue, $baseDate, $subsequentWidth = 0)
 {
     parent::__construct($field, $minWidth, $maxWidth, SignStyle::NOT_NEGATIVE(), $subsequentWidth);
     $this->baseValue = $baseValue;
     $this->baseDate = $baseDate;
     if ($minWidth < 1 || $minWidth > 10) {
         throw new IllegalArgumentException("The minWidth must be from 1 to 10 inclusive but was " . $minWidth);
     }
     if ($maxWidth < 1 || $maxWidth > 10) {
         throw new IllegalArgumentException("The maxWidth must be from 1 to 10 inclusive but was " . $minWidth);
     }
     if ($maxWidth < $minWidth) {
         throw new IllegalArgumentException("Maximum width must exceed or equal the minimum width but " . $maxWidth . " < " . $minWidth);
     }
     if ($baseDate === null) {
         if ($field->range()->isValidValue($baseValue) === false) {
             throw new IllegalArgumentException("The base value must be within the range of the field");
         }
         if ($baseValue + self::$EXCEED_POINTS[$maxWidth] > Integer::MAX_VALUE) {
             throw new DateTimeException("Unable to add printer-parser as the range exceeds the capacity of an int");
         }
     }
 }
 public function setUp()
 {
     $this->fmt = (new DateTimeFormatterBuilder())->appendLiteral2("ONE")->appendValue3(CF::DAY_OF_MONTH(), 1, 2, SignStyle::NOT_NEGATIVE())->toFormatter();
 }
 public function test_toString3()
 {
     $this->assertEquals($this->getFormatterWidth(ChronoField::HOUR_OF_DAY(), 1, 2, SignStyle::NOT_NEGATIVE())->__toString(), "Value(HourOfDay,1,2,NOT_NEGATIVE)");
 }
 public function __toString()
 {
     if ($this->minWidth == 1 && $this->maxWidth == 19 && $this->signStyle == SignStyle::NORMAL()) {
         return "Value(" . $this->field . ")";
     }
     if ($this->minWidth == $this->maxWidth && $this->signStyle == SignStyle::NOT_NEGATIVE()) {
         return "Value(" . $this->field . "," . $this->minWidth . ")";
     }
     return "Value(" . $this->field . "," . $this->minWidth . "," . $this->maxWidth . "," . $this->signStyle . ")";
 }
 public function data_signStyle()
 {
     return [[LocalDate::of(0, 10, 2), SignStyle::ALWAYS(), null, "+00"], [LocalDate::of(2001, 10, 2), SignStyle::ALWAYS(), null, "+2001"], [LocalDate::of(-2001, 10, 2), SignStyle::ALWAYS(), null, "-2001"], [LocalDate::of(2001, 10, 2), SignStyle::NORMAL(), null, "2001"], [LocalDate::of(-2001, 10, 2), SignStyle::NORMAL(), null, "-2001"], [LocalDate::of(2001, 10, 2), SignStyle::NEVER(), null, "2001"], [LocalDate::of(-2001, 10, 2), SignStyle::NEVER(), null, "2001"], [LocalDate::of(2001, 10, 2), SignStyle::NOT_NEGATIVE(), null, "2001"], [LocalDate::of(-2001, 10, 2), SignStyle::NOT_NEGATIVE(), DateTimeException::class, ""], [LocalDate::of(0, 10, 2), SignStyle::EXCEEDS_PAD(), null, "00"], [LocalDate::of(1, 10, 2), SignStyle::EXCEEDS_PAD(), null, "01"], [LocalDate::of(-1, 10, 2), SignStyle::EXCEEDS_PAD(), null, "-01"], [LocalDate::of(20001, 10, 2), SignStyle::ALWAYS(), DateTimeException::class, ""], [LocalDate::of(20001, 10, 2), SignStyle::NORMAL(), DateTimeException::class, ""], [LocalDate::of(20001, 10, 2), SignStyle::NEVER(), DateTimeException::class, ""], [LocalDate::of(20001, 10, 2), SignStyle::EXCEEDS_PAD(), DateTimeException::class, ""], [LocalDate::of(20001, 10, 2), SignStyle::NOT_NEGATIVE(), DateTimeException::class, ""]];
 }
 public static function RFC_1123_DATE_TIME()
 {
     // manually code maps to ensure correct data always used
     // (locale data can be changed by application code)
     $dow = [1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"];
     $moy = [1 => "Jan", 2 => "Feb", 3 => "Mar", 4 => "Apr", 5 => "May", 6 => "Jun", 7 => "Jul", 8 => "Aug", 9 => "Sep", 10 => "Oct", 11 => "Nov", 12 => "Dec"];
     return self::$RFC_1123_DATE_TIME = (new DateTimeFormatterBuilder())->parseCaseInsensitive()->parseLenient()->optionalStart()->appendText3(ChronoField::DAY_OF_WEEK(), $dow)->appendLiteral2(", ")->optionalEnd()->appendValue3(ChronoField::DAY_OF_MONTH(), 1, 2, SignStyle::NOT_NEGATIVE())->appendLiteral(' ')->appendText3(ChronoField::MONTH_OF_YEAR(), $moy)->appendLiteral(' ')->appendValue2(ChronoField::YEAR(), 4)->appendLiteral(' ')->appendValue2(ChronoField::HOUR_OF_DAY(), 2)->appendLiteral(':')->appendValue2(ChronoField::MINUTE_OF_HOUR(), 2)->optionalStart()->appendLiteral(':')->appendValue2(ChronoField::SECOND_OF_MINUTE(), 2)->optionalEnd()->appendLiteral(' ')->appendOffset("+HHMM", "GMT")->toFormatter3(ResolverStyle::SMART(), IsoChronology::INSTANCE());
 }
 public function test_withLocale_same()
 {
     $base = (new DateTimeFormatterBuilder())->appendLiteral2("ONE")->appendValue3(ChronoField::DAY_OF_MONTH(), 1, 2, SignStyle::NOT_NEGATIVE())->toFormatter2(Locale::ENGLISH())->withDecimalStyle(DecimalStyle::STANDARD());
     $test = $base->withLocale(Locale::ENGLISH());
     $this->assertSame($test, $base);
 }
 public function provider_parseDigitsLenient()
 {
     return [["5", 1, 2, SignStyle::NEVER(), 1, 5], ["5", 2, 2, SignStyle::NEVER(), 1, 5], ["54", 1, 3, SignStyle::NEVER(), 2, 54], ["54", 2, 3, SignStyle::NEVER(), 2, 54], ["54", 3, 3, SignStyle::NEVER(), 2, 54], ["543", 1, 3, SignStyle::NEVER(), 3, 543], ["543", 2, 3, SignStyle::NEVER(), 3, 543], ["543", 3, 3, SignStyle::NEVER(), 3, 543], ["5432", 1, 3, SignStyle::NEVER(), 4, 5432], ["5432", 2, 3, SignStyle::NEVER(), 4, 5432], ["5432", 3, 3, SignStyle::NEVER(), 4, 5432], ["5AAA", 2, 3, SignStyle::NEVER(), 1, 5], ["5", 1, 2, SignStyle::NOT_NEGATIVE(), 1, 5], ["5", 2, 2, SignStyle::NOT_NEGATIVE(), 1, 5], ["54", 1, 3, SignStyle::NOT_NEGATIVE(), 2, 54], ["54", 2, 3, SignStyle::NOT_NEGATIVE(), 2, 54], ["54", 3, 3, SignStyle::NOT_NEGATIVE(), 2, 54], ["543", 1, 3, SignStyle::NOT_NEGATIVE(), 3, 543], ["543", 2, 3, SignStyle::NOT_NEGATIVE(), 3, 543], ["543", 3, 3, SignStyle::NOT_NEGATIVE(), 3, 543], ["5432", 1, 3, SignStyle::NOT_NEGATIVE(), 4, 5432], ["5432", 2, 3, SignStyle::NOT_NEGATIVE(), 4, 5432], ["5432", 3, 3, SignStyle::NOT_NEGATIVE(), 4, 5432], ["5AAA", 2, 3, SignStyle::NOT_NEGATIVE(), 1, 5], ["5", 1, 2, SignStyle::NORMAL(), 1, 5], ["5", 2, 2, SignStyle::NORMAL(), 1, 5], ["54", 1, 3, SignStyle::NORMAL(), 2, 54], ["54", 2, 3, SignStyle::NORMAL(), 2, 54], ["54", 3, 3, SignStyle::NORMAL(), 2, 54], ["543", 1, 3, SignStyle::NORMAL(), 3, 543], ["543", 2, 3, SignStyle::NORMAL(), 3, 543], ["543", 3, 3, SignStyle::NORMAL(), 3, 543], ["5432", 1, 3, SignStyle::NORMAL(), 4, 5432], ["5432", 2, 3, SignStyle::NORMAL(), 4, 5432], ["5432", 3, 3, SignStyle::NORMAL(), 4, 5432], ["5AAA", 2, 3, SignStyle::NORMAL(), 1, 5], ["5", 1, 2, SignStyle::ALWAYS(), 1, 5], ["5", 2, 2, SignStyle::ALWAYS(), 1, 5], ["54", 1, 3, SignStyle::ALWAYS(), 2, 54], ["54", 2, 3, SignStyle::ALWAYS(), 2, 54], ["54", 3, 3, SignStyle::ALWAYS(), 2, 54], ["543", 1, 3, SignStyle::ALWAYS(), 3, 543], ["543", 2, 3, SignStyle::ALWAYS(), 3, 543], ["543", 3, 3, SignStyle::ALWAYS(), 3, 543], ["5432", 1, 3, SignStyle::ALWAYS(), 4, 5432], ["5432", 2, 3, SignStyle::ALWAYS(), 4, 5432], ["5432", 3, 3, SignStyle::ALWAYS(), 4, 5432], ["5AAA", 2, 3, SignStyle::ALWAYS(), 1, 5], ["5", 1, 2, SignStyle::EXCEEDS_PAD(), 1, 5], ["5", 2, 2, SignStyle::EXCEEDS_PAD(), 1, 5], ["54", 1, 3, SignStyle::EXCEEDS_PAD(), 2, 54], ["54", 2, 3, SignStyle::EXCEEDS_PAD(), 2, 54], ["54", 3, 3, SignStyle::EXCEEDS_PAD(), 2, 54], ["543", 1, 3, SignStyle::EXCEEDS_PAD(), 3, 543], ["543", 2, 3, SignStyle::EXCEEDS_PAD(), 3, 543], ["543", 3, 3, SignStyle::EXCEEDS_PAD(), 3, 543], ["5432", 1, 3, SignStyle::EXCEEDS_PAD(), 4, 5432], ["5432", 2, 3, SignStyle::EXCEEDS_PAD(), 4, 5432], ["5432", 3, 3, SignStyle::EXCEEDS_PAD(), 4, 5432], ["5AAA", 2, 3, SignStyle::EXCEEDS_PAD(), 1, 5]];
 }
 /**
  * Appends a fixed or variable width printer-parser handling adjacent value mode.
  * If a PrinterParser is not active then the new PrinterParser becomes
  * the active PrinterParser.
  * Otherwise, the active PrinterParser is modified depending on the new PrinterParser.
  * If the new PrinterParser is fixed width and has sign style {@code NOT_NEGATIVE}
  * then its width is added to the active PP and
  * the new PrinterParser is forced to be fixed width.
  * If the new PrinterParser is variable width, the active PrinterParser is changed
  * to be fixed width and the new PrinterParser becomes the active PP.
  *
  * @param NumberPrinterParser $pp the printer-parser, not null
  * @return DateTimeFormatterBuilder this, for chaining, not null
  */
 private function appendValue4(NumberPrinterParser $pp)
 {
     if ($this->active->valueParserIndex >= 0) {
         $activeValueParser = $this->active->valueParserIndex;
         // adjacent parsing mode, update setting in previous parsers
         $basePP = $this->active->printerParsers[$activeValueParser];
         if ($pp->minWidth == $pp->maxWidth && $pp->signStyle == SignStyle::NOT_NEGATIVE()) {
             // Append the width to the subsequentWidth of the active parser
             $basePP = $basePP->withSubsequentWidth($pp->maxWidth);
             // Append the new parser as a fixed width
             $this->appendInternal($pp->withFixedWidth());
             // Retain the previous active parser
             $this->active->valueParserIndex = $activeValueParser;
         } else {
             // Modify the active parser to be fixed width
             $basePP = $basePP->withFixedWidth();
             // The new parser becomes the mew active parser
             $this->active->valueParserIndex = $this->appendInternal($pp);
         }
         // Replace the modified parser with the updated one
         $this->active->printerParsers[$activeValueParser] = $basePP;
     } else {
         // The new Parser becomes the active parser
         $this->active->valueParserIndex = $this->appendInternal($pp);
     }
     return $this;
 }