private function run($argv)
 {
     $ids = ZoneRulesProvider::getAvailableZoneIds();
     $start = Instant::now();
     foreach ($ids as $id) {
         TZDBZoneRulesProvider::getRules($id, false);
     }
     $end = Instant::now();
     echo 'First run: ', ChronoUnit::MILLIS()->between($start, $end), "ms, count: ", count($ids), "\n";
 }
 public function test_ParseText()
 {
     $this->markTestIncomplete('ZoneTextPrinterParser, Localized Zone Names');
     $locales = [Locale::ENGLISH(), Locale::JAPANESE(), Locale::FRENCH()];
     $zids = ZoneRulesProvider::getAvailableZoneIds();
     foreach ($locales as $locale) {
         $this->parseText($zids, $locale, TextStyle::FULL(), false);
         $this->parseText($zids, $locale, TextStyle::FULL(), true);
         $this->parseText($zids, $locale, TextStyle::SHORT(), false);
         $this->parseText($zids, $locale, TextStyle::SHORT(), true);
     }
 }
Ejemplo n.º 3
0
 protected function getTree(DateTimeParseContext $context)
 {
     // prepare parse tree
     $regionIds = ZoneRulesProvider::getAvailableZoneIds();
     $regionIdsSize = count($regionIds);
     $cached = $context->isCaseSensitive() ? self::$cachedPrefixTree : self::$cachedPrefixTreeCI;
     if ($cached == null || $cached->getKey() != $regionIdsSize) {
         $cached = $context->isCaseSensitive() ? self::$cachedPrefixTree : self::$cachedPrefixTreeCI;
         if ($cached == null || $cached->getKey() != $regionIdsSize) {
             $cached = new SimpleImmutableEntry($regionIdsSize, PrefixTree::newTree($regionIds, $context));
             if ($context->isCaseSensitive()) {
                 self::$cachedPrefixTree = $cached;
             } else {
                 self::$cachedPrefixTreeCI = $cached;
             }
         }
     }
     return $cached->getValue();
 }
Ejemplo n.º 4
0
 /**
  * Gets the set of available zone IDs.
  * <p>
  * This set includes the string form of all available region-based IDs.
  * Offset-based zone IDs are not included in the returned set.
  * The ID can be passed to {@link #of(String)} to create a {@code ZoneId}.
  * <p>
  * The set of zone IDs can increase over time, although in a typical application
  * the set of IDs is fixed. Each call to this method is thread-safe.
  *
  * @return String[] a modifiable copy of the set of zone IDs, not null
  */
 public static function getAvailableZoneIds()
 {
     return ZoneRulesProvider::getAvailableZoneIds();
 }
 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;
 }
Ejemplo n.º 6
0
 /**
  * @return ZoneRules
  */
 public function getRules()
 {
     // additional query for group provider when null allows for possibility
     // that the provider was updated after the ZoneId was created
     return $this->rules !== null ? $this->rules : ZoneRulesProvider::getRules($this->id, false);
 }