/**
  * 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");
         }
     }
 }
Exemplo n.º 2
0
 public function test_toString3()
 {
     $this->assertEquals($this->getFormatterWidth(ChronoField::HOUR_OF_DAY(), 1, 2, SignStyle::NOT_NEGATIVE())->__toString(), "Value(HourOfDay,1,2,NOT_NEGATIVE)");
 }
Exemplo n.º 3
0
 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 . ")";
 }
Exemplo n.º 4
0
 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, ""]];
 }
Exemplo n.º 5
0
 private static function PARSER()
 {
     if (self::$PARSER === null) {
         self::$PARSER = (new DateTimeFormatterBuilder())->appendValue3(ChronoField::YEAR(), 4, 10, SignStyle::EXCEEDS_PAD())->toFormatter();
     }
     return self::$PARSER;
 }
Exemplo n.º 6
0
 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());
 }
Exemplo n.º 7
0
 /**
  * Create and cache a number printer parser.
  * @return NumberPrinterParser the number printer parser for this field, not null
  */
 private function numberPrinterParser()
 {
     if ($this->numberPrinterParser == null) {
         $this->numberPrinterParser = new NumberPrinterParser($this->field, 1, 19, SignStyle::NORMAL());
     }
     return $this->numberPrinterParser;
 }
 public function test_appendValueReduced_subsequent_parse()
 {
     $this->builder->appendValue3(CF::MONTH_OF_YEAR(), 1, 2, SignStyle::NORMAL())->appendValueReduced(CF::YEAR(), 2, 2, 2000);
     $f = $this->builder->toFormatter();
     $this->assertEquals($f->__toString(), "Value(MonthOfYear,1,2,NORMAL)ReducedValue(Year,2,2,2000)");
     $ppos = new ParsePosition(0);
     $parsed = $f->parseUnresolved("123", $ppos);
     $this->assertNotNull($parsed, "Parse failed: " . $ppos->__toString());
     $this->assertEquals($parsed->getLong(CF::MONTH_OF_YEAR()), 1);
     $this->assertEquals($parsed->getLong(CF::YEAR()), 2023);
 }
Exemplo n.º 9
0
 public static function init()
 {
     self::$PARSER = (new DateTimeFormatterBuilder())->appendValue3(ChronoField::YEAR(), 4, 10, SignStyle::EXCEEDS_PAD())->appendLiteral('-')->appendValue2(ChronoField::MONTH_OF_YEAR(), 2)->toFormatter();
 }
 public function test_parse_decoratedStartsWithPad_number()
 {
     $this->builder->padNext2(3, '-')->appendValue3(ChronoField::MONTH_OF_YEAR(), 1, 2, SignStyle::NORMAL());
     $parsed = $this->builder->toFormatter()->parseUnresolved("--2", $this->pos);
     $this->assertEquals($this->pos->getIndex(), 3);
     $this->assertEquals($this->pos->getErrorIndex(), -1);
     $this->assertEquals($parsed->isSupported(ChronoField::MONTH_OF_YEAR()), true);
     $this->assertEquals($parsed->getLong(ChronoField::MONTH_OF_YEAR()), 2);
     // +2, not -2
 }
 /**
  * @expectedException \Celest\IllegalArgumentException
  */
 public function test_appendValue_3arg_maxWidthMinWidth()
 {
     $this->builder->appendValue3(ChronoField::DAY_OF_MONTH(), 4, 2, SignStyle::NORMAL());
 }
Exemplo n.º 12
0
 /**
  * @dataProvider provider_parseDigitsAdjacentLenient
  */
 public function test_parseDigitsAdjacentLenient($input, $parseLen, $parseMonth, $parsedDay)
 {
     $this->setStrict(false);
     $pos = new ParsePosition(0);
     $f = $this->builder->appendValue3(ChronoField::MONTH_OF_YEAR(), 1, 2, SignStyle::NORMAL())->appendValue2(ChronoField::DAY_OF_MONTH(), 2)->toFormatter2($this->locale)->withDecimalStyle($this->decimalStyle);
     $parsed = $f->parseUnresolved($input, $pos);
     if ($pos->getErrorIndex() !== -1) {
         $this->assertEquals($pos->getErrorIndex(), $parseLen);
     } else {
         $this->assertEquals($pos->getIndex(), $parseLen);
         $this->assertEquals($parsed->getLong(ChronoField::MONTH_OF_YEAR()), $parseMonth);
         $this->assertEquals($parsed->getLong(ChronoField::DAY_OF_MONTH()), $parsedDay);
         $this->assertEquals($parsed->query(TemporalQueries::chronology()), null);
         $this->assertEquals($parsed->query(TemporalQueries::zoneId()), null);
     }
 }
Exemplo n.º 13
0
            case 4:
                // EXCEEDS_PAD
                return true;
            default:
                // valid if lenient and not fixed width
                return !$strict && !$fixedWidth;
        }
    }
    function __toString()
    {
        switch ($this->ordinal) {
            case 0:
                return 'NORMAL';
            case 1:
                return 'ALWAYS';
            case 2:
                return 'NEVER';
            case 3:
                return 'NOT_NEGATIVE';
            case 4:
                return 'EXCEEDS_PAD';
        }
        return '';
    }
    function name()
    {
        return $this->__toString();
    }
}
SignStyle::init();
 public function setUp()
 {
     $this->fmt = (new DateTimeFormatterBuilder())->appendLiteral2("ONE")->appendValue3(CF::DAY_OF_MONTH(), 1, 2, SignStyle::NOT_NEGATIVE())->toFormatter();
 }
Exemplo n.º 15
0
 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 __toString()
 {
     $sb = "Localized(";
     if ($this->chr === 'Y') {
         if ($this->count == 1) {
             $sb .= "WeekBasedYear";
         } else {
             if ($this->count == 2) {
                 $sb .= "ReducedValue(WeekBasedYear,2,2,2000-01-01)";
             } else {
                 $sb .= "WeekBasedYear," . $this->count . "," . 19 . "," . ($this->count < 4 ? SignStyle::NORMAL() : SignStyle::EXCEEDS_PAD());
             }
         }
     } else {
         switch ($this->chr) {
             case 'c':
             case 'e':
                 $sb .= "DayOfWeek";
                 break;
             case 'w':
                 $sb .= "WeekOfWeekBasedYear";
                 break;
             case 'W':
                 $sb .= "WeekOfMonth";
                 break;
             default:
                 break;
         }
         $sb .= ",";
         $sb .= $this->count;
     }
     $sb .= ")";
     return $sb;
 }
 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;
     }
 }