예제 #1
0
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::zoneId()) {
         return ZoneId::of("Europe/Paris");
     }
     return parent::query($query);
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::precision()) {
         return ChronoUnit::ERAS();
     }
     return parent::query($query);
 }
예제 #3
0
 public function format(DateTimePrintContext $context, &$buf)
 {
     $chrono = $context->getValue(TemporalQueries::chronology());
     if ($chrono == null) {
         return false;
     }
     if ($this->textStyle == null) {
         $buf .= $chrono->getId();
     } else {
         $buf .= $this->getChronologyName($chrono, $context->getLocale());
     }
     return true;
 }
 public function format(DateTimePrintContext $context, &$buf)
 {
     /** @var ZoneID $zone */
     $zone = $context->getValue(TemporalQueries::zoneId());
     if ($zone === null) {
         return false;
     }
     $zname = $zone->getId();
     if (!$zone instanceof ZoneOffset) {
         $dt = $context->getTemporal();
         $name = $this->getDisplayName($zname, $dt->isSupported(ChronoField::INSTANT_SECONDS()) ? $zone->getRules()->isDaylightSavings(Instant::from($dt)) ? self::$DST : self::$STD : self::$GENERIC, $context->getLocale());
         if ($name !== null) {
             $zname = $name;
         }
     }
     $buf .= $zname;
     return true;
 }
예제 #5
0
 public function format(DateTimePrintContext $context, &$buf)
 {
     $value = $context->getValueField($this->field);
     if ($value === null) {
         return false;
     }
     $text = null;
     $chrono = $context->getTemporal()->query(TemporalQueries::chronology());
     if ($chrono === null || $chrono == IsoChronology::INSTANCE()) {
         $text = $this->provider->getText($this->field, $value, $this->textStyle, $context->getLocale());
     } else {
         $text = $this->provider->getText2($chrono, $this->field, $value, $this->textStyle, $context->getLocale());
     }
     if ($text === null) {
         return $this->numberPrinterParser()->format($context, $buf);
     }
     $buf .= $text;
     return true;
 }
예제 #6
0
 /**
  * Queries this year using the specified query.
  * <p>
  * This queries this year 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::chronology()) {
         return IsoChronology::INSTANCE();
     } else {
         if ($query == TemporalQueries::precision()) {
             return ChronoUnit::YEARS();
         }
     }
     return parent::query($query);
 }
예제 #7
0
 function data_query()
 {
     return [[self::TEST_2008_06(), TemporalQueries::chronology(), IsoChronology::INSTANCE()], [self::TEST_2008_06(), TemporalQueries::zoneId(), null], [self::TEST_2008_06(), TemporalQueries::precision(), CU::MONTHS()], [self::TEST_2008_06(), TemporalQueries::zone(), null], [self::TEST_2008_06(), TemporalQueries::offset(), null], [self::TEST_2008_06(), TemporalQueries::localDate(), null], [self::TEST_2008_06(), TemporalQueries::localTime(), null]];
 }
예제 #8
0
 public static function from(TemporalAccessor $temporal)
 {
     $obj = $temporal->query(TemporalQueries::chronology());
     return $obj !== null ? $obj : IsoChronology::INSTANCE();
 }
 function data_query()
 {
     return [[self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::chronology(), IsoChronology::INSTANCE()], [self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::zoneId(), null], [self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::precision(), CU::NANOS()], [self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::zone(), self::OFFSET_PONE()], [self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::offset(), self::OFFSET_PONE()], [self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::localDate(), LocalDate::of(2008, 6, 30)], [self::TEST_2008_6_30_11_30_59_000000500(), TemporalQueries::localTime(), LocalTime::of(11, 30, 59, 500)]];
 }
예제 #10
0
 public function test_basicTest_query()
 {
     foreach ($this->samples() as $sample) {
         $this->assertEquals($sample->query(TemporalQueries::fromCallable(function () {
             return "foo";
         })), "foo");
     }
 }
예제 #11
0
 /**
  * @dataProvider provider_parseDigitsAdjacentLenient
  */
 public function test_parseDigitsAdjacentLenient($input, $parseLen, $parseMonth, $parsedDay)
 {
     $this->setStrict(false);
     $pos = new ParsePosition(0);
     $f = $this->builder->appendValue3(ChronoField::MONTH_OF_YEAR(), 1, 2, SignStyle::NORMAL())->appendValue2(ChronoField::DAY_OF_MONTH(), 2)->toFormatter2($this->locale)->withDecimalStyle($this->decimalStyle);
     $parsed = $f->parseUnresolved($input, $pos);
     if ($pos->getErrorIndex() !== -1) {
         $this->assertEquals($pos->getErrorIndex(), $parseLen);
     } else {
         $this->assertEquals($pos->getIndex(), $parseLen);
         $this->assertEquals($parsed->getLong(ChronoField::MONTH_OF_YEAR()), $parseMonth);
         $this->assertEquals($parsed->getLong(ChronoField::DAY_OF_MONTH()), $parsedDay);
         $this->assertEquals($parsed->query(TemporalQueries::chronology()), null);
         $this->assertEquals($parsed->query(TemporalQueries::zoneId()), null);
     }
 }
예제 #12
0
 /**
  * Queries this date using the specified query.
  * <p>
  * This queries this date 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::localDate()) {
         return $this;
     }
     return parent::query($query);
 }
예제 #13
0
    }
    /** @var TemporalQuery */
    private static $LOCAL_DATE;
    /**
     * A query for {@code LocalTime} returning null if not found.
     * <p>
     * This returns a {@code TemporalQuery} that can be used to query a temporal
     * object for the local time. The query will return null if the temporal
     * object cannot supply a local time.
     * <p>
     * The query implementation examines the {@link ChronoField#NANO_OF_DAY NANO_OF_DAY}
     * field and uses it to create a {@code LocalTime}.
     * <p>
     * The method {@link ZoneOffset#from(TemporalAccessor)} can be used as a
     * {@code TemporalQuery} via a method reference, {@code LocalTime::from}.
     * This query and {@code LocalTime::from} will return the same result if the
     * temporal object contains a time. If the temporal object does not contain
     * a time, then the method reference will throw an exception, whereas this
     * query will return null.
     *
     * @return TemporalQuery a query that can obtain the time of a temporal, not null
     */
    public static function localTime()
    {
        return self::$LOCAL_TIME;
    }
    /** @var TemporalQuery */
    private static $LOCAL_TIME;
}
TemporalQueries::init();
예제 #14
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);
 }
예제 #15
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);
 }
예제 #16
0
 /**
  * Queries this month-day using the specified query.
  * <p>
  * This queries this month-day 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::chronology()) {
         return IsoChronology::INSTANCE();
     }
     return parent::query($query);
 }
 /**
  * @dataProvider data_print_localized
  */
 public function test_print_localized(TextStyle $style, LocalDateTime $ldt, ZoneOffset $offset, $expected)
 {
     $odt = OffsetDateTime::ofDateTime($ldt, $offset);
     $zdt = $ldt->atZone($offset);
     $f = (new DateTimeFormatterBuilder())->appendLocalizedOffset($style)->toFormatter();
     $this->assertEquals($f->format($odt), $expected);
     $this->assertEquals($f->format($zdt), $expected);
     $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset);
     if ($style == TextStyle::FULL()) {
         $f = (new DateTimeFormatterBuilder())->appendPattern("ZZZZ")->toFormatter();
         $this->assertEquals($f->format($odt), $expected);
         $this->assertEquals($f->format($zdt), $expected);
         $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset);
         $f = (new DateTimeFormatterBuilder())->appendPattern("OOOO")->toFormatter();
         $this->assertEquals($f->format($odt), $expected);
         $this->assertEquals($f->format($zdt), $expected);
         $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset);
     }
     if ($style == TextStyle::SHORT()) {
         $f = (new DateTimeFormatterBuilder())->appendPattern("O")->toFormatter();
         $this->assertEquals($f->format($odt), $expected);
         $this->assertEquals($f->format($zdt), $expected);
         $this->assertEquals($f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from'])), $offset);
     }
 }
 /**
  * @dataProvider data_offsetPatterns
  */
 public function test_appendOffset_parse($pattern, $h, $m, $s, $expected)
 {
     $this->builder->appendOffset($pattern, "Z");
     $f = $this->builder->toFormatter();
     $parsed = $f->parseQuery($expected, TemporalQueries::fromCallable([ZoneOffset::class, 'from']));
     $this->assertEquals($f->format($parsed), $expected);
 }
예제 #19
0
 function data_query()
 {
     return [[self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::chronology(), IsoChronology::INSTANCE()], [self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::zoneId(), null], [self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::precision(), CU::NANOS()], [self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::zone(), null], [self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::offset(), null], [self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::localDate(), LocalDate::of(2007, 7, 15)], [self::TEST_200707_15_12_30_40_987654321(), TemporalQueries::localTime(), LocalTime::of(12, 30, 40, 987654321)]];
 }
 public function test_fieldResolvesToChronoZonedDateTime_overrideZone_matches()
 {
     $zdt = ZonedDateTime::of(2010, 6, 30, 12, 30, 0, 0, self::EUROPE_PARIS());
     $f = (new DateTimeFormatterBuilder())->appendValue(new ResolvingField($zdt))->toFormatter();
     $f = $f->withZone(self::EUROPE_PARIS());
     $this->assertEquals($f->parseQuery("1234567890", TemporalQueries::fromCallable([ZonedDateTime::class, 'from'])), $zdt);
 }
예제 #21
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);
 }
예제 #22
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);
 }
예제 #23
0
 public function test_query_zone()
 {
     $this->assertEquals($this->TEST_DATE_TIME->query(TemporalQueries::zone()), $this->TEST_DATE_TIME->getZone());
     $this->assertEquals(TemporalQueries::zone()->queryFrom($this->TEST_DATE_TIME), $this->TEST_DATE_TIME->getZone());
 }
예제 #24
0
 public function query(TemporalQuery $query)
 {
     if ($query == TemporalQueries::localDate()) {
         return LocalDate::of(2012, 6, 30);
     }
     throw new UnsupportedOperationException();
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function test_parseBest_String_oneRule()
 {
     $test = $this->fmt->withLocale(Locale::ENGLISH())->withDecimalStyle(DecimalStyle::STANDARD());
     $test->parseBest("30", TemporalQueries::fromCallable([LocalDate::class, 'from']));
 }
예제 #26
0
 function data_query()
 {
     return [[DayOfWeek::FRIDAY(), TemporalQueries::chronology(), null], [DayOfWeek::FRIDAY(), TemporalQueries::zoneId(), null], [DayOfWeek::FRIDAY(), TemporalQueries::precision(), ChronoUnit::DAYS()], [DayOfWeek::FRIDAY(), TemporalQueries::zone(), null], [DayOfWeek::FRIDAY(), TemporalQueries::offset(), null], [DayOfWeek::FRIDAY(), TemporalQueries::localDate(), null], [DayOfWeek::FRIDAY(), TemporalQueries::localTime(), null]];
 }
 /**
  * @dataProvider data_success
  */
 public function test_parse_success($s, $caseSensitive, $text, $pos, $expectedPos)
 {
     $this->setCaseSensitive($caseSensitive);
     $ppos = new ParsePosition($pos);
     $parsed = $this->getFormatterString($s)->parseUnresolved($text, $ppos);
     if ($ppos->getErrorIndex() != -1) {
         $this->assertEquals($ppos->getIndex(), $expectedPos);
     } else {
         $this->assertEquals($ppos->getIndex(), $expectedPos);
         $this->assertEquals($parsed->isSupported(ChronoField::YEAR()), false);
         $this->assertEquals($parsed->query(TemporalQueries::chronology()), null);
         $this->assertEquals($parsed->query(TemporalQueries::zoneId()), null);
     }
 }
예제 #28
0
 private static function adjust(TemporalAccessor $temporal, DateTimeFormatter $formatter)
 {
     // normal case first (early return is an optimization)
     $overrideChrono = $formatter->getChronology();
     $overrideZone = $formatter->getZone();
     if ($overrideChrono == null && $overrideZone == null) {
         return $temporal;
     }
     // ensure minimal change (early return is an optimization)
     $temporalChrono = $temporal->query(TemporalQueries::chronology());
     $temporalZone = $temporal->query(TemporalQueries::zoneId());
     if ($temporalChrono !== null && $temporalChrono->equals($overrideChrono)) {
         $overrideChrono = null;
     }
     if ($temporalZone !== null && $temporalZone->equals($overrideZone)) {
         $overrideZone = null;
     }
     if ($overrideChrono === null && $overrideZone === null) {
         return $temporal;
     }
     // make adjustment
     $effectiveChrono = $overrideChrono != null ? $overrideChrono : $temporalChrono;
     if ($overrideZone != null) {
         // if have zone and instant, calculation is simple, defaulting chrono if necessary
         if ($temporal->isSupported(ChronoField::INSTANT_SECONDS())) {
             $chrono = $effectiveChrono != null ? $effectiveChrono : IsoChronology::INSTANCE();
             return $chrono->zonedDateTime(Instant::from($temporal), $overrideZone);
         }
         // block changing zone on OffsetTime, and similar problem cases
         if ($overrideZone->normalized() instanceof ZoneOffset && $temporal->isSupported(ChronoField::OFFSET_SECONDS()) && $temporal->get(ChronoField::OFFSET_SECONDS()) != $overrideZone->getRules()->getOffset(Instant::EPOCH())->getTotalSeconds()) {
             throw new DateTimeException("Unable to apply override zone '" . $overrideZone . "' because the temporal object being formatted has a different offset but" . " does not represent an instant: " . $temporal);
         }
     }
     $effectiveZone = $overrideZone !== null ? $overrideZone : $temporalZone;
     $effectiveDate = null;
     if ($overrideChrono !== null) {
         if ($temporal->isSupported(ChronoField::EPOCH_DAY())) {
             $effectiveDate = $effectiveChrono->dateFrom($temporal);
         } else {
             // check for date fields other than epoch-day, ignoring case of converting null to ISO
             if (!($overrideChrono == IsoChronology::INSTANCE() && $temporalChrono === null)) {
                 foreach (ChronoField::values() as $f) {
                     if ($f->isDateBased() && $temporal->isSupported($f)) {
                         throw new DateTimeException("Unable to apply override chronology '" . $overrideChrono . "' because the temporal object being formatted contains date fields but" . " does not represent a whole date: " . $temporal);
                     }
                 }
             }
             $effectiveDate = null;
         }
     } else {
         $effectiveDate = null;
     }
     // combine available data
     // this is a non-standard temporal that is almost a pure delegate
     // this better handles map-like underlying temporal instances
     return new Test($effectiveDate, $temporal, $effectiveZone, $effectiveChrono);
 }
예제 #29
0
 public function data_query()
 {
     return [[ZoneOffset::UTC(), TemporalQueries::chronology(), null], [ZoneOffset::UTC(), TemporalQueries::zoneId(), null], [ZoneOffset::UTC(), TemporalQueries::precision(), null], [ZoneOffset::UTC(), TemporalQueries::zone(), ZoneOffset::UTC()], [ZoneOffset::UTC(), TemporalQueries::offset(), ZoneOffset::UTC()], [ZoneOffset::UTC(), TemporalQueries::localDate(), null], [ZoneOffset::UTC(), TemporalQueries::localTime(), null]];
 }
예제 #30
0
 /**
  * Obtains an instance of {@code ZoneId} from a temporal object.
  * <p>
  * This obtains a zone based on the specified temporal.
  * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
  * which this factory converts to an instance of {@code ZoneId}.
  * <p>
  * A {@code TemporalAccessor} represents some form of date and time information.
  * This factory converts the arbitrary temporal object to an instance of {@code ZoneId}.
  * <p>
  * The conversion will try to obtain the zone in a way that favours region-based
  * zones over offset-based zones using {@link TemporalQueries#zone()}.
  * <p>
  * This method matches the signature of the functional interface {@link TemporalQuery}
  * allowing it to be used as a query via method reference, {@code ZoneId::from}.
  *
  * @param TemporalAccessor $temporal the temporal object to convert, not null
  * @return ZoneId the zone ID, not null
  * @throws DateTimeException if unable to convert to a {@code ZoneId}
  */
 public static function from(TemporalAccessor $temporal)
 {
     $obj = $temporal->query(TemporalQueries::zone());
     if ($obj == null) {
         throw new DateTimeException("Unable to obtain ZoneId from TemporalAccessor: " . $temporal . " of type " . get_class($temporal));
     }
     return $obj;
 }