Пример #1
0
 /**
  * @dataProvider provider_reducedWithChrono
  */
 public function test_reducedWithChronoYearOfEra(ChronoLocalDate $date)
 {
     $chrono = $date->getChronology();
     $df = (new DateTimeFormatterBuilder())->appendValueReduced2(ChronoField::YEAR_OF_ERA(), 2, 2, LocalDate::of(2000, 1, 1))->toFormatter()->withChronology($chrono);
     $expected = $date->get(ChronoField::YEAR_OF_ERA());
     $input = $df->format($date);
     $pos = new ParsePosition(0);
     $parsed = $df->parseUnresolved($input, $pos);
     $actual = $parsed->get(ChronoField::YEAR_OF_ERA());
     $this->assertEquals($actual, $expected, "Wrong date parsed, chrono: " . $chrono . ", input: " . $input);
 }
Пример #2
0
 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;
 }
 public function get(TemporalField $field)
 {
     if ($field instanceof ChronoField) {
         $f = $field;
         return $f->isTimeBased() ? $this->time->get($field) : $this->date->get($field);
     }
     return $this->range($field)->checkValidIntValue($this->getLong($field), $field);
 }