public function parse(DateTimeParseContext $context, $parseText, $position) { $length = strlen($parseText); if ($position < 0 || $position > $length) { throw new \OutOfRangeException(); } $style = $context->isStrict() ? $this->textStyle : null; $chrono = $context->getEffectiveChronology(); $it = null; if ($chrono === null || $chrono == IsoChronology::INSTANCE()) { $it = $this->provider->getTextIterator($this->field, $style, $context->getLocale()); } else { $it = $this->provider->getTextIterator2($chrono, $this->field, $style, $context->getLocale()); } if ($it !== null) { foreach ($it as $key => $value) { // fix numeric indices $key = strval($key); if ($context->subSequenceEquals($key, 0, $parseText, $position, strlen($key))) { return $context->setParsedField($this->field, $value, $position, $position + strlen($key)); } } if ($context->isStrict()) { return ~$position; } } return $this->numberPrinterParser()->parse($context, $parseText, $position); }
private function getDisplayName($id, $type, Locale $locale) { if ($this->textStyle == TextStyle::NARROW()) { return null; } $names = DateTimeTextProvider::getZoneNames($id, $locale); switch ($type) { case self::$STD: return $names[$this->textStyle->zoneNameStyleIndex() . 'g']; case self::$DST: return $names[$this->textStyle->zoneNameStyleIndex() . 'd']; } return $names[$this->textStyle->zoneNameStyleIndex() . 's']; }
public function getDisplayName(Locale $locale) { if ($this->displayNameKey === null) { return $this->name; } $name = DateTimeTextProvider::tryField('week', $locale); return $name !== null ? $name : $this->displayNameKey; }
public function getDisplayName(Locale $locale) { $name = DateTimeTextProvider::tryField('week', $locale); return $name !== null ? $name : $this->__toString(); }
public function getDisplayName(Locale $locale) { if ($this->rangeUnit == ChronoUnit::YEARS()) { // only have values for week-of-year $name = DateTimeTextProvider::tryField('week', $locale); if ($name !== null) { return $name; } } return $this->name; }
/** * Appends the text of a date-time field to the formatter. * <p> * The text of the field will be output during a format. * The value must be within the valid range of the field. * If the value cannot be obtained then an exception will be thrown. * If the field has no textual representation, then the numeric value will be used. * <p> * The value will be printed as per the normal format of an integer value. * Only negative numbers will be signed. No padding will be added. * * @param TemporalField $field the field to append, not null * @param TextStyle $textStyle the text style to use, not null * @return DateTimeFormatterBuilder this, for chaining, not null */ public function appendText2(TemporalField $field, TextStyle $textStyle) { $this->appendInternal(new TextPrinterParser($field, $textStyle, DateTimeTextProvider::getInstance())); return $this; }