protected function getTree(DateTimeParseContext $context) { if ($this->textStyle == TextStyle::NARROW()) { return parent::getTree($context); } $locale = $context->getLocale(); $isCaseSensitive = $context->isCaseSensitive(); $regionIds = ZoneRulesProvider::getAvailableZoneIds(); $regionIdsSize = $regionIds->size(); $cached = $isCaseSensitive ? self::$cachedTree : self::$cachedTreeCI; $entry = null; $tree = null; $zoneStrings = null; if (($entry = $cached->get($locale)) == null || ($entry->getKey() != $regionIdsSize || ($tree = $entry->getValue()->get()) == null)) { $tree = PrefixTree::newTree($context); $zoneStrings = TimeZoneNameUtility::getZoneStrings($locale); foreach ($zoneStrings as $names) { $zid = $names[0]; if (!$regionIds->contains($zid)) { continue; } $tree->add($zid, $zid); // don't convert zid -> metazone $zid = ZoneName::toZid($zid, $locale); $i = $this->textStyle == TextStyle::FULL() ? 1 : 2; for (; $i < count($names); $i += 2) { $tree->add($names[$i], $zid); } } // if we have a set of preferred zones, need a copy and // add the preferred zones again to overwrite if (self::$preferredZones != null) { foreach ($zoneStrings as $names) { $zid = $names[0]; if (!self::$preferredZones->contains($zid) || !$regionIds->contains($zid)) { continue; } $i = $this->textStyle == TextStyle::FULL() ? 1 : 2; for (; $i < count($names); $i += 2) { $tree->add($names[$i], $zid); } } } $cached->put($locale, new SimpleImmutableEntry($regionIdsSize, $tree)); } return $tree; }
function provider_japaneseEra() { return [[ChronoField::ERA(), TextStyle::FULL(), 2, "Heisei"], [ChronoField::ERA(), TextStyle::SHORT(), 2, "Heisei"], [ChronoField::ERA(), TextStyle::NARROW(), 2, "H"]]; }
/** * @expectedException \Celest\IllegalArgumentException */ public function test_print_pattern_localzed_narrow() { $this->builder->appendLocalizedOffset(TextStyle::NARROW()); }
function provider_text() { return [[ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 1, "Monday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 2, "Tuesday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 3, "Wednesday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 4, "Thursday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 5, "Friday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 6, "Saturday"], [ChronoField::DAY_OF_WEEK(), TextStyle::FULL(), 7, "Sunday"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 1, "Mon"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 2, "Tue"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 3, "Wed"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 4, "Thu"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 5, "Fri"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 6, "Sat"], [ChronoField::DAY_OF_WEEK(), TextStyle::SHORT(), 7, "Sun"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 1, "January"], [ChronoField::MONTH_OF_YEAR(), TextStyle::FULL(), 12, "December"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 1, "Jan"], [ChronoField::MONTH_OF_YEAR(), TextStyle::SHORT(), 12, "Dec"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 1, "1st quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 2, "2nd quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 3, "3rd quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::FULL(), 4, "4th quarter"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 1, "Q1"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 2, "Q2"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 3, "Q3"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::SHORT(), 4, "Q4"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 1, "1"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 2, "2"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 3, "3"], [IsoFields::QUARTER_OF_YEAR(), TextStyle::NARROW(), 4, "4"]]; }
private function parseField($cur, $count, TemporalField $field) { $standalone = false; switch ($cur) { case 'u': case 'y': if ($count === 2) { $this->appendValueReduced2($field, 2, 2, ReducedPrinterParser::BASE_DATE()); } else { if ($count < 4) { $this->appendValue3($field, $count, 19, SignStyle::NORMAL()); } else { $this->appendValue3($field, $count, 19, SignStyle::EXCEEDS_PAD()); } } break; /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case 'c': if ($count === 2) { throw new IllegalArgumentException("Invalid pattern \"cc\""); } /*fallthrough*/ /*fallthrough*/ case 'L': /** @noinspection PhpMissingBreakStatementInspection */ /** @noinspection PhpMissingBreakStatementInspection */ case 'q': $standalone = true; /*fallthrough*/ /*fallthrough*/ case 'M': case 'Q': case 'E': case 'e': switch ($count) { case 1: case 2: if ($cur == 'c' || $cur == 'e') { $this->appendInternal(new WeekBasedFieldPrinterParser($cur, $count)); } else { if ($cur == 'E') { $this->appendText2($field, TextStyle::SHORT()); } else { if ($count === 1) { $this->appendValue($field); } else { $this->appendValue2($field, 2); } } } break; case 3: $this->appendText2($field, $standalone ? TextStyle::SHORT_STANDALONE() : TextStyle::SHORT()); break; case 4: $this->appendText2($field, $standalone ? TextStyle::FULL_STANDALONE() : TextStyle::FULL()); break; case 5: $this->appendText2($field, $standalone ? TextStyle::NARROW_STANDALONE() : TextStyle::NARROW()); break; default: throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'a': if ($count === 1) { $this->appendText2($field, TextStyle::SHORT()); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'G': switch ($count) { case 1: case 2: case 3: $this->appendText2($field, TextStyle::SHORT()); break; case 4: $this->appendText2($field, TextStyle::FULL()); break; case 5: $this->appendText2($field, TextStyle::NARROW()); break; default: throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'S': $this->appendFraction(ChronoField::NANO_OF_SECOND(), $count, $count, false); break; case 'F': if ($count == 1) { $this->appendValue($field); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } break; case 'd': case 'h': case 'H': case 'k': case 'K': case 'm': case 's': if ($count === 1) { $this->appendValue($field); } else { if ($count === 2) { $this->appendValue2($field, $count); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } } break; case 'D': if ($count == 1) { $this->appendValue($field); } else { if ($count <= 3) { $this->appendValue2($field, $count); } else { throw new IllegalArgumentException("Too many pattern letters: " . $cur); } } break; default: if ($count == 1) { $this->appendValue($field); } else { $this->appendValue2($field, $count); } break; } }