/** * Gets the formatter to use. * <p> * The formatter will be the most appropriate to use for the date and time style in the locale. * For example, some locales will use the month name while others will use the number. * * @param Locale $locale the locale to use, not null * @param Chronology $chrono the chronology to use, not null * @return DateTimeFormatter the formatter, not null * @throws IllegalArgumentException if the formatter cannot be found */ private function formatter(Locale $locale, Chronology $chrono) { $key = $chrono->getId() . '|' . $locale . '|' . $this->dateStyle . '|' . $this->timeStyle; $formatter = @self::$FORMATTER_CACHE[$key]; if ($formatter === null) { $pattern = DateTimeFormatterBuilder::getLocalizedDateTimePattern($this->dateStyle, $this->timeStyle, $chrono, $locale); $formatter = (new DateTimeFormatterBuilder())->appendPattern($pattern)->toFormatter2($locale); $old = self::$FORMATTER_CACHE[$key] = $formatter; if ($old !== null) { $formatter = $old; } } return $formatter; }
/** * Returns the chronology name of the given chrono in the given locale * if available, or the chronology Id otherwise. The regular ResourceBundle * search path is used for looking up the chronology name. * * @param Chronology $chrono the chronology, not null * @param Locale $locale the locale, not null * @return string the chronology name of chrono in locale, or the id if no name is available * @throws NullPointerException if chrono or locale is null */ private function getChronologyName(Chronology $chrono, Locale $locale) { $key = "calendarname." . $chrono->getCalendarType(); $name = DateTimeTextProvider::getLocalizedResource($key, $locale); return $name != null ? $name : $chrono->getId(); }
/** * Casts the {@code Temporal} to {@code ChronoLocalDate} ensuring it bas the specified chronology. * * @param Chronology $chrono the chronology to check for, not null * @param Temporal $temporal a date-time to cast, not null * @return static the date-time checked and cast to {@code ChronoLocalDate}, not null * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDate * or the chronology is not equal this Chronology */ static function ensureValid(Chronology $chrono, Temporal $temporal) { /** @var ChronoLocalDate $other */ $other = $temporal; if ($chrono->equals($other->getChronology()) === false) { throw new ClassCastException("Chronology mismatch, expected: " . $chrono->getId() . ", actual: " . $other->getChronology()->getId()); } return $other; }
/** * Compares this chronology to another chronology. * <p> * The comparison order first by the chronology ID string, then by any * additional information specific to the subclass. * It is "consistent with equals", as defined by {@link Comparable}. * * @implSpec * This implementation compares the chronology ID. * Subclasses must compare any additional state that they store. * * @param Chronology $other the other chronology to compare to, not null * @return int the comparator value, negative if less, positive if greater */ public function compareTo(Chronology $other) { return strcmp($this->getId(), $other->getId()); }
/** * Casts the {@code Temporal} to {@code ChronoZonedDateTimeImpl} ensuring it bas the specified chronology. * * @param Chronology $chrono the chronology to check for, not null * @param Temporal $temporal a date-time to cast, not null * @return ChronoZonedDateTimeImpl the date-time checked and cast to {@code ChronoZonedDateTimeImpl}, not null * @throws ClassCastException if the date-time cannot be cast to ChronoZonedDateTimeImpl * or the chronology is not equal this Chronology */ static function ensureValid(Chronology $chrono, Temporal $temporal) { $other = $temporal; // TODO cast if ($chrono->equals($other->getChronology()) === false) { throw new ClassCastException("Chronology mismatch, required: " . $chrono->getId() . ", actual: " . $other->getChronology()->getId()); } return $other; }