/**
  * Converts a fraction from 0 to 1 for this field to a value.
  * <p>
  * The fractional value must be between 0 (inclusive) and 1 (exclusive).
  * It can only be returned if the {@link java.time.temporal.TemporalField#range() value range} is fixed.
  * The value is obtained by calculation from the field range and a rounding
  * mode of {@link RoundingMode#FLOOR FLOOR}.
  * The calculation is inaccurate if the values do not run continuously from smallest to largest.
  * <p>
  * For example, the fractional second-of-minute of 0.25 would be converted to 15,
  * assuming the standard definition of 60 seconds in a minute.
  *
  * @param mixed $fraction TODO the fraction to convert, not null
  * @return int the value of the field, valid for this rule
  * @throws DateTimeException if the value cannot be converted
  */
 private function convertFromFraction($fraction)
 {
     $range = $this->field->range();
     $minBD = gmp_init($range->getMinimum());
     $rangeBD = gmp_add(gmp_sub($range->getMaximum(), $minBD), 1);
     $valueBD = gmp_add(gmp_div(gmp_mul($fraction, $rangeBD), 1000000000), $minBD);
     return gmp_intval($valueBD);
 }
 /**
  * @inheritdoc
  */
 public function range(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         if ($field == ChronoField::INSTANT_SECONDS() || $field == ChronoField::OFFSET_SECONDS()) {
             return $field->range();
         }
         return $this->toLocalDateTime()->range($field);
     }
     return $field->rangeRefinedBy($this);
 }
示例#3
0
 /**
  * Gets the range of valid values for the specified field.
  * <p>
  * The range object expresses the minimum and maximum valid values for a field.
  * This date is used to enhance the accuracy of the returned range.
  * If it is not possible to return the range, because the field is not supported
  * or for some other reason, an exception is thrown.
  * <p>
  * If the field is a {@link ChronoField} then the query is implemented here.
  * The {@link #isSupported(TemporalField) supported fields} will return
  * appropriate range instances.
  * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
  * <p>
  * If the field is not a {@code ChronoField}, then the result of this method
  * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
  * passing {@code this} as the argument.
  * Whether the range can be obtained is determined by the field.
  *
  * @param TemporalField $field the field to query the range for, not null
  * @return ValueRange the range of valid values for the field, not null
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 public function range(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         /** @var ChronoField $f */
         $f = $field;
         if ($f->isDateBased()) {
             switch ($f) {
                 case ChronoField::DAY_OF_MONTH():
                     return ValueRange::of(1, $this->lengthOfMonth());
                 case ChronoField::DAY_OF_YEAR():
                     return ValueRange::of(1, $this->lengthOfYear());
                 case ChronoField::ALIGNED_WEEK_OF_MONTH():
                     return ValueRange::of(1, $this->getMonth() == Month::FEBRUARY() && $this->isLeapYear() == false ? 4 : 5);
                 case ChronoField::YEAR_OF_ERA():
                     return $this->getYear() <= 0 ? ValueRange::of(1, Year::MAX_VALUE + 1) : ValueRange::of(1, Year::MAX_VALUE);
             }
             return $field->range();
         }
         throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
     }
     return $field->rangeRefinedBy($this);
 }
示例#4
0
 /**
  * Gets the range of valid values for the specified field.
  * <p>
  * The range object expresses the minimum and maximum valid values for a field.
  * This month-day is used to enhance the accuracy of the returned range.
  * If it is not possible to return the range, because the field is not supported
  * or for some other reason, an exception is thrown.
  * <p>
  * If the field is a {@link ChronoField} then the query is implemented here.
  * The {@link #isSupported(TemporalField) supported fields} will return
  * appropriate range instances.
  * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
  * <p>
  * If the field is not a {@code ChronoField}, then the result of this method
  * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
  * passing {@code this} as the argument.
  * Whether the range can be obtained is determined by the field.
  *
  * @param TemporalField $field the field to query the range for, not null
  * @return ValueRange the range of valid values for the field, not null
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 public function range(TemporalField $field)
 {
     if ($field == ChronoField::MONTH_OF_YEAR()) {
         return $field->range();
     } else {
         if ($field == ChronoField::DAY_OF_MONTH()) {
             return ValueRange::ofVariable(1, $this->getMonth()->minLength(), $this->getMonth()->maxLength());
         }
     }
     return parent::range($field);
 }
示例#5
0
 /**
  * Gets the range of valid values for the specified field.
  * <p>
  * The range object expresses the minimum and maximum valid values for a field.
  * This day-of-week is used to enhance the accuracy of the returned range.
  * If it is not possible to return the range, because the field is not supported
  * or for some other reason, an exception is thrown.
  * <p>
  * If the field is {@link ChronoField#DAY_OF_WEEK DAY_OF_WEEK} then the
  * range of the day-of-week, from 1 to 7, will be returned.
  * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
  * <p>
  * If the field is not a {@code ChronoField}, then the result of this method
  * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
  * passing {@code this} as the argument.
  * Whether the range can be obtained is determined by the field.
  *
  * @param TemporalField $field the field to query the range for, not null
  * @return ValueRange the range of valid values for the field, not null
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 public function range(TemporalField $field)
 {
     if ($field == ChronoField::DAY_OF_WEEK()) {
         return $field->range();
     }
     return parent::range($field);
 }
示例#6
0
 /**
  * Gets the range of valid values for the specified field.
  * <p>
  * The range object expresses the minimum and maximum valid values for a field.
  * This month is used to enhance the accuracy of the returned range.
  * If it is not possible to return the range, because the field is not supported
  * or for some other reason, an exception is thrown.
  * <p>
  * If the field is {@link ChronoField#MONTH_OF_YEAR MONTH_OF_YEAR} then the
  * range of the month-of-year, from 1 to 12, will be returned.
  * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
  * <p>
  * If the field is not a {@code ChronoField}, then the result of this method
  * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
  * passing {@code this} as the argument.
  * Whether the range can be obtained is determined by the field.
  *
  * @param TemporalField $field the field to query the range for, not null
  * @return ValueRange the range of valid values for the field, not null
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 public function range(TemporalField $field)
 {
     if ($field == ChronoField::MONTH_OF_YEAR()) {
         return $field->range();
     }
     return parent::range($field);
 }
示例#7
0
 /**
  * Gets the range of valid values for the specified field.
  * <p>
  * The range object expresses the minimum and maximum valid values for a field.
  * This time is used to enhance the accuracy of the returned range.
  * If it is not possible to return the range, because the field is not supported
  * or for some other reason, an exception is thrown.
  * <p>
  * If the field is a {@link ChronoField} then the query is implemented here.
  * The {@link #isSupported(TemporalField) supported fields} will return
  * appropriate range instances.
  * All other {@code ChronoField} instances will throw an {@code UnsupportedTemporalTypeException}.
  * <p>
  * If the field is not a {@code ChronoField}, then the result of this method
  * is obtained by invoking {@code TemporalField.rangeRefinedBy(TemporalAccessor)}
  * passing {@code this} as the argument.
  * Whether the range can be obtained is determined by the field.
  *
  * @param TemporalField $field the field to query the range for, not null
  * @return ValueRange the range of valid values for the field, not null
  * @throws DateTimeException if the range for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  */
 public function range(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         if ($field == ChronoField::OFFSET_SECONDS()) {
             return $field->range();
         }
         return $this->time->range($field);
     }
     return $field->rangeRefinedBy($this);
 }