Пример #1
0
 /**
  * Gets the value of the specified field from this date-time as an {@code int}.
  * <p>
  * This queries this date-time for the value of the specified field.
  * The returned value will always be within the valid range of values for the field.
  * If it is not possible to return the value, 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 valid
  * values based on this date-time, except {@code NANO_OF_DAY}, {@code MICRO_OF_DAY},
  * {@code EPOCH_DAY}, {@code PROLEPTIC_MONTH} and {@code INSTANT_SECONDS} which are too
  * large to fit in an {@code int} and throw a {@code DateTimeException}.
  * 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.getFrom(TemporalAccessor)}
  * passing {@code this} as the argument. Whether the value can be obtained,
  * and what the value represents, is determined by the field.
  *
  * @param TemporalField $field the field to get, not null
  * @return int the value for the field
  * @throws DateTimeException if a value for the field cannot be obtained or
  *         the value is outside the range of valid values for the field
  * @throws UnsupportedTemporalTypeException if the field is not supported or
  *         the range of values exceeds an {@code int}
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function get(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         switch ($field) {
             case ChronoField::INSTANT_SECONDS():
                 throw new UnsupportedTemporalTypeException("Invalid field 'InstantSeconds' for get() method, use getLong() instead");
             case ChronoField::OFFSET_SECONDS():
                 return $this->getOffset()->getTotalSeconds();
         }
         return $this->dateTime->get($field);
     }
     return parent::get($field);
 }
 /**
  * @inheritdoc
  */
 public function minus($amountToSubtract, TemporalUnit $unit)
 {
     return ChronoLocalDateImpl::ensureValid($this->getChronology(), parent::minus($amountToSubtract, $unit));
 }
Пример #3
0
 /**
  * Gets the value of the specified field from this time as an {@code int}.
  * <p>
  * This queries this time for the value of the specified field.
  * The returned value will always be within the valid range of values for the field.
  * If it is not possible to return the value, 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 valid
  * values based on this time, except {@code NANO_OF_DAY} and {@code MICRO_OF_DAY}
  * which are too large to fit in an {@code int} and throw a {@code DateTimeException}.
  * 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.getFrom(TemporalAccessor)}
  * passing {@code this} as the argument. Whether the value can be obtained,
  * and what the value represents, is determined by the field.
  *
  * @param TemporalField $field the field to get, not null
  * @return int the value for the field
  * @throws DateTimeException if a value for the field cannot be obtained or
  *         the value is outside the range of valid values for the field
  * @throws UnsupportedTemporalTypeException if the field is not supported or
  *         the range of values exceeds an {@code int}
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function get(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         return $this->get0($field);
     }
     return parent::get($field);
 }
Пример #4
0
 /**
  * Gets the value of the specified field from this time as an {@code int}.
  * <p>
  * This queries this time for the value of the specified field.
  * The returned value will always be within the valid range of values for the field.
  * If it is not possible to return the value, 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 valid
  * values based on this time, except {@code NANO_OF_DAY} and {@code MICRO_OF_DAY}
  * which are too large to fit in an {@code int} and throw a {@code DateTimeException}.
  * 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.getFrom(TemporalAccessor)}
  * passing {@code this} as the argument. Whether the value can be obtained,
  * and what the value represents, is determined by the field.
  *
  * @param TemporalField $field the field to get, not null
  * @return int the value for the field
  * @throws DateTimeException if a value for the field cannot be obtained or
  *         the value is outside the range of valid values for the field
  * @throws UnsupportedTemporalTypeException if the field is not supported or
  *         the range of values exceeds an {@code int}
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function get(TemporalField $field)
 {
     return parent::get($field);
 }