Example #1
0
 /**
  * @inheritdoc
  */
 public function getLong(TemporalField $field)
 {
     if ($field == ChronoField::ERA()) {
         return $this->getValue();
     } else {
         if ($field instanceof ChronoField) {
             throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
         }
     }
     return $field->getFrom($this);
 }
Example #2
0
 /**
  * Gets the value of the specified field from this instant as a {@code long}.
  * <p>
  * This queries this instant for the value of the specified 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.
  * 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
  * @throws UnsupportedTemporalTypeException if the field is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function getLong(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         switch ($field) {
             case ChronoField::NANO_OF_SECOND():
                 return $this->nanos;
             case ChronoField::MICRO_OF_SECOND():
                 return Math::div($this->nanos, 1000);
             case ChronoField::MILLI_OF_SECOND():
                 return Math::div($this->nanos, 1000000);
             case ChronoField::INSTANT_SECONDS():
                 return $this->seconds;
         }
         throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
     }
     return $field->getFrom($this);
 }
Example #3
0
 /**
  * Gets the value of the specified field from this year as a {@code long}.
  * <p>
  * This queries this year for the value of the specified 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 year.
  * 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
  * @throws UnsupportedTemporalTypeException if the field is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function getLong(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         switch ($field) {
             case ChronoField::YEAR_OF_ERA():
                 return $this->year < 1 ? 1 - $this->year : $this->year;
             case ChronoField::YEAR():
                 return $this->year;
             case ChronoField::ERA():
                 return $this->year < 1 ? 0 : 1;
         }
         throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
     }
     return $field->getFrom($this);
 }
Example #4
0
 /**
  * Gets the value of the specified field from this offset as a {@code long}.
  * <p>
  * This queries this offset for the value of the specified 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 {@code OFFSET_SECONDS} field returns the value of the offset.
  * 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 $field TemporalField the field to get, not null
  * @return int the value for the field
  * @throws DateTimeException if a value for the field cannot be obtained
  * @throws UnsupportedTemporalTypeException if the field is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function getLong(TemporalField $field)
 {
     if ($field == ChronoField::OFFSET_SECONDS()) {
         return $this->totalSeconds;
     } else {
         if ($field instanceof ChronoField) {
             throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
         }
     }
     return $field->getFrom($this);
 }
Example #5
0
 /**
  * Gets the value of the specified field from this month-day as a {@code long}.
  * <p>
  * This queries this month-day for the value of the specified 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 month-day.
  * 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
  * @throws UnsupportedTemporalTypeException if the field is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function getLong(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         switch ($field) {
             // alignedDOW and alignedWOM not supported because they cannot be set in with()
             case ChronoField::DAY_OF_MONTH():
                 return $this->day;
             case ChronoField::MONTH_OF_YEAR():
                 return $this->month;
         }
         throw new UnsupportedTemporalTypeException("Unsupported field: " . $field);
     }
     return $field->getFrom($this);
 }