コード例 #1
0
 /**
  * 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");
         }
     }
 }