/**
  * @dataProvider data_query
  */
 public function test_queryFrom(TemporalAccessor $temporal, TemporalQuery $query, $expected)
 {
     $this->assertEquals($query->queryFrom($temporal), $expected);
 }
Esempio n. 2
0
 /**
  * Queries this date-time using the specified query.
  * <p>
  * This queries this date-time using the specified query strategy object.
  * The {@code TemporalQuery} object defines the logic to be used to
  * obtain the result. Read the documentation of the query to understand
  * what the result of this method will be.
  * <p>
  * The result of this method is obtained by invoking the
  * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
  * specified query passing {@code this} as the argument.
  *
  * @param <R> the type of the result
  * @param TemporalQuery $query the query to invoke, not null
  * @return mixed the query result, null may be returned (defined by the query)
  * @throws DateTimeException if unable to query (defined by the query)
  * @throws ArithmeticException if numeric overflow occurs (defined by the query)
  */
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::offset() || $query == TemporalQueries::zone()) {
         return $this->getOffset();
     } else {
         if ($query == TemporalQueries::zoneId()) {
             return null;
         } else {
             if ($query == TemporalQueries::localDate()) {
                 return $this->toLocalDate();
             } else {
                 if ($query == TemporalQueries::localTime()) {
                     return $this->toLocalTime();
                 } else {
                     if ($query == TemporalQueries::chronology()) {
                         return IsoChronology::INSTANCE();
                     } else {
                         if ($query == TemporalQueries::precision()) {
                             return ChronoUnit::NANOS();
                         }
                     }
                 }
             }
         }
     }
     // inline TemporalAccessor.super.query(query) as an optimization
     // non-JDK classes are not permitted to make this optimization
     return $query->queryFrom($this);
 }
Esempio n. 3
0
 /**
  * Queries this offset using the specified query.
  * <p>
  * This queries this offset using the specified query strategy object.
  * The {@code TemporalQuery} object defines the logic to be used to
  * obtain the result. Read the documentation of the query to understand
  * what the result of this method will be.
  * <p>
  * The result of this method is obtained by invoking the
  * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
  * specified query passing {@code this} as the argument.
  *
  * @param <R> the type of the result
  * @param  $query TemporalQuery the query to invoke, not null
  * @return mixed the query result, null may be returned (defined by the query)
  * @throws DateTimeException if unable to query (defined by the query)
  * @throws ArithmeticException if numeric overflow occurs (defined by the query)
  */
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::offset() || $query == TemporalQueries::zone()) {
         return $this;
     }
     // inlined from \Celest\Temporal\AbstractTemporalAccessor::query
     if ($query == TemporalQueries::zoneId() || $query == TemporalQueries::chronology() || $query == TemporalQueries::precision()) {
         return null;
     }
     return $query->queryFrom($this);
 }
Esempio n. 4
0
 /**
  * Queries this instant using the specified query.
  * <p>
  * This queries this instant using the specified query strategy object.
  * The {@code TemporalQuery} object defines the logic to be used to
  * obtain the result. Read the documentation of the query to understand
  * what the result of this method will be.
  * <p>
  * The result of this method is obtained by invoking the
  * {@link TemporalQuery#queryFrom(TemporalAccessor)} method on the
  * specified query passing {@code this} as the argument.
  *
  * @param <R> the type of the result
  * @param query TemporalQuery the query to invoke, not null
  * @return mixed the query result, null may be returned (defined by the query)
  * @throws DateTimeException if unable to query (defined by the query)
  * @throws ArithmeticException if numeric overflow occurs (defined by the query)
  */
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::precision()) {
         return ChronoUnit::NANOS();
     }
     // inline TemporalAccessor.super.query(query) as an optimization
     if ($query == TemporalQueries::chronology() || $query == TemporalQueries::zoneId() || $query == TemporalQueries::zone() || $query == TemporalQueries::offset() || $query == TemporalQueries::localDate() || $query == TemporalQueries::localTime()) {
         return null;
     }
     return $query->queryFrom($this);
 }
Esempio n. 5
0
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::zoneId()) {
         return $this->zone;
     } else {
         if ($query == TemporalQueries::chronology()) {
             return $this->chrono;
         } else {
             if ($query == TemporalQueries::localDate()) {
                 return $this->date != null ? LocalDate::from($this->date) : null;
             } else {
                 if ($query == TemporalQueries::localTime()) {
                     return $this->time;
                 } else {
                     if ($query == TemporalQueries::zone() || $query == TemporalQueries::offset()) {
                         return $query->queryFrom($this);
                     } else {
                         if ($query == TemporalQueries::precision()) {
                             return null;
                             // not a complete date/time
                         }
                     }
                 }
             }
         }
     }
     // inline TemporalAccessor.super.query(query) as an optimization
     // non-JDK classes are not permitted to make this optimization
     return $query->queryFrom($this);
 }