public function getLong(TemporalField $field) { if ($this->effectiveDate != null && $field->isDateBased()) { return $this->effectiveDate->getLong($field); } return $this->temporal->getLong($field); }
private function monthsUntil(ChronoLocalDate $end) { $range = $this->getChronology()->range(CF::MONTH_OF_YEAR()); if ($range->getMaximum() !== 12) { throw new \AssertionError("ChronoLocalDateImpl only supports Chronologies with 12 months per year"); } $packed1 = $this->getLong(CF::PROLEPTIC_MONTH()) * 32 + $this->get(CF::DAY_OF_MONTH()); // no overflow $packed2 = $end->getLong(CF::PROLEPTIC_MONTH()) * 32 + $end->get(CF::DAY_OF_MONTH()); // no overflow return ($packed2 - $packed1) / 32; }
/** * @param TemporalField $field * @return int * @throws UnsupportedTemporalTypeException */ public function getLong(TemporalField $field) { $value = $this->fieldValues->get($field); if ($value !== null) { return $value; } if ($this->date !== null && $this->date->isSupported($field)) { return $this->date->getLong($field); } if ($this->time !== null && $this->time->isSupported($field)) { return $this->time->getLong($field); } if ($field instanceof CF) { throw new UnsupportedTemporalTypeException("Unsupported field: " . $field); } return $field->getFrom($this); }
public function until(Temporal $endExclusive, TemporalUnit $unit) { $end = $this->getChronology()->localDateTime($endExclusive); if ($unit instanceof ChronoUnit) { if ($unit->isTimeBased()) { $amount = $end->getLong(ChronoField::EPOCH_DAY()) - $this->date->getLong(ChronoField::EPOCH_DAY()); switch ($unit) { case ChronoUnit::NANOS(): $amount = Math::multiplyExact($amount, self::NANOS_PER_DAY); break; case ChronoUnit::MICROS(): $amount = Math::multiplyExact($amount, self::MICROS_PER_DAY); break; case ChronoUnit::MILLIS(): $amount = Math::multiplyExact($amount, self::MILLIS_PER_DAY); break; case ChronoUnit::SECONDS(): $amount = Math::multiplyExact($amount, self::SECONDS_PER_DAY); break; case ChronoUnit::MINUTES(): $amount = Math::multiplyExact($amount, self::MINUTES_PER_DAY); break; case ChronoUnit::HOURS(): $amount = Math::multiplyExact($amount, self::HOURS_PER_DAY); break; case ChronoUnit::HALF_DAYS(): $amount = Math::multiplyExact($amount, 2); break; } return Math::addExact($amount, $this->time->until($end->toLocalTime(), $unit)); } $endDate = $end->toLocalDate(); if ($end->toLocalTime()->isBefore($this->time)) { $endDate = $endDate->minus(1, ChronoUnit::DAYS()); } return $this->date->until($endDate, $unit); } return $unit->between($this, $end); }