/** * ZoneTextPrinterParser constructor. * @param TextStyle $textStyle * @param ZoneId[] $preferredZones */ public function __construct(TextStyle $textStyle, $preferredZones) { parent::__construct(TemporalQueries::zone(), "ZoneText(" . $textStyle . ")"); $this->textStyle = $textStyle; if ($preferredZones !== null && count($preferredZones) !== 0) { $this->preferredZones = []; foreach ($preferredZones as $id) { $this->preferredZones[] = $id->getId(); } } }
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)]]; }
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]]; }
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)]]; }
/** * 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; }
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]]; }
function data_query() { return [[self::TEST_11_30_59_500_PONE(), TemporalQueries::chronology(), null], [self::TEST_11_30_59_500_PONE(), TemporalQueries::zoneId(), null], [self::TEST_11_30_59_500_PONE(), TemporalQueries::precision(), CU::NANOS()], [self::TEST_11_30_59_500_PONE(), TemporalQueries::zone(), self::OFFSET_PONE()], [self::TEST_11_30_59_500_PONE(), TemporalQueries::offset(), self::OFFSET_PONE()], [self::TEST_11_30_59_500_PONE(), TemporalQueries::localDate(), null], [self::TEST_11_30_59_500_PONE(), TemporalQueries::localTime(), LocalTime::of(11, 30, 59, 500)]]; }
/** * 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); }
/** * @dataProvider data_parseSuccess */ public function test_parseSuccess_caseInsensitive($text, $expectedIndex, $expectedErrorIndex, $expected) { $this->builder->parseCaseInsensitive()->appendZoneId(); $lcText = strtolower($text); $parsed = $this->builder->toFormatter()->parseUnresolved($lcText, $this->pos); $this->assertEquals($this->pos->getErrorIndex(), $expectedErrorIndex, "Incorrect error index parsing: " . $lcText); $this->assertEquals($this->pos->getIndex(), $expectedIndex, "Incorrect index parsing: " . $lcText); if ($expected !== null) { $zid = $parsed->query(TemporalQueries::zoneId()); $this->assertEquals($parsed->query(TemporalQueries::zoneId()), $expected, "Incorrect zoneId parsing: " . $lcText); $this->assertEquals($parsed->query(TemporalQueries::offset()), null, "Incorrect offset parsing: " . $lcText); $this->assertEquals($parsed->query(TemporalQueries::zone()), $expected, "Incorrect zone parsing: " . $lcText); } else { $this->assertEquals($parsed, null); } }
private function parse(DateTimeFormatter $fmt, $zid, $expected, $text, Locale $locale, TextStyle $style, $ci) { if ($ci) { $text = $text->toUpperCase(); } /** @var ZoneId $ret */ $ret = $fmt->parseQuery($text, TemporalQueries::zone())->getId(); // TBD: need an excluding list // assertEquals(...); if ($ret->equals($expected) || $ret->equals($zid) || $ret->equals(ZoneName::toZid($zid)) || $ret->equals($expected->replace("UTC", "UCT"))) { return; } echo printf("[%-5s %s %s %16s] %24s -> %s(%s)%n", $locale->__toString(), $ci ? "ci" : " ", $style == TextStyle::FULL() ? " full" : "short", $zid, $text, $ret, $expected); }
function data_query() { return [[self::$TEST_2008, TemporalQueries::chronology(), IsoChronology::INSTANCE()], [self::$TEST_2008, TemporalQueries::zoneId(), null], [self::$TEST_2008, TemporalQueries::precision(), ChronoUnit::YEARS()], [self::$TEST_2008, TemporalQueries::zone(), null], [self::$TEST_2008, TemporalQueries::offset(), null], [self::$TEST_2008, TemporalQueries::localDate(), null], [self::$TEST_2008, TemporalQueries::localTime(), null]]; }
function data_query() { return [[self::TEST_123040987654321(), TemporalQueries::chronology(), null], [self::TEST_123040987654321(), TemporalQueries::zoneId(), null], [self::TEST_123040987654321(), TemporalQueries::precision(), CU::NANOS()], [self::TEST_123040987654321(), TemporalQueries::zone(), null], [self::TEST_123040987654321(), TemporalQueries::offset(), null], [self::TEST_123040987654321(), TemporalQueries::localDate(), null], [self::TEST_123040987654321(), TemporalQueries::localTime(), self::TEST_123040987654321()]]; }
function data_query() { return [[Month::JUNE(), TemporalQueries::chronology(), IsoChronology::INSTANCE()], [Month::JUNE(), TemporalQueries::zoneId(), null], [Month::JUNE(), TemporalQueries::precision(), ChronoUnit::MONTHS()], [Month::JUNE(), TemporalQueries::zone(), null], [Month::JUNE(), TemporalQueries::offset(), null], [Month::JUNE(), TemporalQueries::localDate(), null], [Month::JUNE(), TemporalQueries::localTime(), null]]; }
/** * 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); }
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); }
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()); }
/** * 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); }
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]]; }
/** * Appends the time-zone ID, such as 'Europe/Paris' or '+02:00', to * the formatter, using the best available zone ID. * <p> * This appends an instruction to format/parse the best available * zone or offset ID to the builder. * The zone ID is obtained in a lenient manner that first attempts to * find a true zone ID, such as that on {@code ZonedDateTime}, and * then attempts to find an offset, such as that on {@code OffsetDateTime}. * <p> * During formatting, the zone is obtained using a mechanism equivalent * to querying the temporal with {@link TemporalQueries#zone()}. * It will be printed using the result of {@link ZoneId#getId()}. * If the zone cannot be obtained then an exception is thrown unless the * section of the formatter is optional. * <p> * During parsing, the text must match a known zone or offset. * There are two types of zone ID, offset-based, such as '+01:30' and * region-based, such as 'Europe/London'. These are parsed differently. * If the parse starts with '+', '-', 'UT', 'UTC' or 'GMT', then the parser * expects an offset-based zone and will not match region-based zones. * The offset ID, such as '+02:30', may be at the start of the parse, * or prefixed by 'UT', 'UTC' or 'GMT'. The offset ID parsing is * equivalent to using {@link #appendOffset(String, String)} using the * arguments 'HH:MM:ss' and the no offset string '0'. * If the parse starts with 'UT', 'UTC' or 'GMT', and the parser cannot * match a following offset ID, then {@link ZoneOffset#UTC} is selected. * In all other cases, the list of known region-based zones is used to * find the longest available match. If no match is found, and the parse * starts with 'Z', then {@code ZoneOffset.UTC} is selected. * The parser uses the {@linkplain #parseCaseInsensitive() case sensitive} setting. * <p> * For example, the following will parse: * <pre> * "Europe/London" -- ZoneId.of("Europe/London") * "Z" -- ZoneOffset.UTC * "UT" -- ZoneId.of("UT") * "UTC" -- ZoneId.of("UTC") * "GMT" -- ZoneId.of("GMT") * "+01:30" -- ZoneOffset.of("+01:30") * "UT+01:30" -- ZoneOffset.of("UT+01:30") * "UTC+01:30" -- ZoneOffset.of("UTC+01:30") * "GMT+01:30" -- ZoneOffset.of("GMT+01:30") * </pre> * <p> * Note that this method is identical to {@code appendZoneId()} except * in the mechanism used to obtain the zone. * * @return DateTimeFormatterBuilder this, for chaining, not null * @see #appendZoneId() */ public function appendZoneOrOffsetId() { $this->appendInternal(new ZoneIdPrinterParser(TemporalQueries::zone(), "ZoneOrOffsetId()")); return $this; }