/**
  * 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());
 }
Exemple #5
0
 /**
  * @param ChronoLocalDate|null $cld
  * @throws DateTimeException
  */
 private function updateCheckConflict1($cld)
 {
     if ($this->date != null) {
         if ($cld != null && $this->date->equals($cld) == false) {
             throw new DateTimeException("Conflict found: Fields resolved to two different dates: " . $this->date . " " . $cld);
         }
     } else {
         if ($cld != null) {
             if ($this->chrono->equals($cld->getChronology()) == false) {
                 throw new DateTimeException("ChronoLocalDate must use the effective parsed chronology: " . $this->chrono);
             }
             $this->date = $cld;
         }
     }
 }
 /**
  * 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;
 }
 private function resolveWoY(FieldValues $fieldValues, Chronology $chrono, $year, $woy, $localDow, ResolverStyle $resolverStyle)
 {
     $date = $chrono->date($year, 1, 1);
     if ($resolverStyle == ResolverStyle::LENIENT()) {
         $weeks = Math::subtractExact($woy, $this->localizedWeekOfYear($date));
         $days = $localDow - $this->localizedDayOfWeek($date);
         // safe from overflow
         $date = $date->plus(Math::addExact(Math::multiplyExact($weeks, 7), $days), ChronoUnit::DAYS());
     } else {
         $womInt = $this->range->checkValidIntValue($woy, $this);
         // validate
         $weeks = (int) ($womInt - $this->localizedWeekOfYear($date));
         // safe from overflow
         $days = $localDow - $this->localizedDayOfWeek($date);
         // safe from overflow
         $date = $date->plus($weeks * 7 + $days, ChronoUnit::DAYS());
         if ($resolverStyle == ResolverStyle::STRICT() && $date->getLong(CF::YEAR()) !== $year) {
             throw new DateTimeException("Strict mode rejected resolved date as it is in a different year");
         }
     }
     $fieldValues->remove($this);
     $fieldValues->remove(CF::YEAR());
     $fieldValues->remove(CF::DAY_OF_WEEK());
     return $date;
 }