コード例 #1
0
 public function getLong(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         switch ($field) {
             case CF::PROLEPTIC_MONTH():
                 return $this->getProlepticMonth();
             case CF::YEAR_OF_ERA():
                 $prolepticYear = $this->getProlepticYear();
                 return $prolepticYear >= 1 ? $prolepticYear : 1 - $prolepticYear;
             case CF::YEAR():
                 return $this->getProlepticYear();
             case CF::ERA():
                 return $this->getProlepticYear() >= 1 ? 1 : 0;
         }
         return $this->isoDate->getLong($field);
     }
     return $field->getFrom($this);
 }
コード例 #2
0
 /**
  * @dataProvider data_samples
  */
 public function test_samples_get(TemporalField $field, LocalDate $date, $expected)
 {
     $this->assertEquals($date->getLong($field), $expected);
 }
コード例 #3
0
 /**
  * Gets the value of the specified field from this date-time as a {@code long}.
  * <p>
  * This queries this date-time 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) {
         $f = $field;
         return $f->isTimeBased() ? $this->time->getLong($field) : $this->date->getLong($field);
     }
     return $field->getFrom($this);
 }
コード例 #4
0
 public function setFields(LocalDate $dt)
 {
     if ($dt !== null) {
         $this->fields->put(ChronoField::YEAR(), $dt->getYear());
         $this->fields->put(ChronoField::MONTH_OF_YEAR(), $dt->getMonthValue());
         $this->fields->put(ChronoField::DAY_OF_MONTH(), $dt->getDayOfMonth());
         $this->fields->put(ChronoField::DAY_OF_YEAR(), $dt->getDayOfYear());
         $this->fields->put(ChronoField::DAY_OF_WEEK(), $dt->getDayOfWeek()->getValue());
         $this->fields->put(IsoFields::WEEK_BASED_YEAR(), $dt->getLong(IsoFields::WEEK_BASED_YEAR()));
         $this->fields->put(IsoFields::WEEK_OF_WEEK_BASED_YEAR(), $dt->getLong(IsoFields::WEEK_OF_WEEK_BASED_YEAR()));
     }
 }