public function addTo(Temporal $temporal, $amount) { switch ($this) { case IsoFields::WEEK_BASED_YEARS(): return $temporal->with(IsoFields::WEEK_BASED_YEAR(), Math::addExact($temporal->get(IsoFields::WEEK_BASED_YEAR()), $amount)); case IsoFields::QUARTER_YEARS(): // no overflow (256 is multiple of 4) return $temporal->plus($amount / 256, ChronoUnit::YEARS())->plus($amount % 256 * 3, ChronoUnit::MONTHS()); default: throw new IllegalStateException("Unreachable"); } }
public function getRangeUnit() { return IsoFields::QUARTER_YEARS(); }
/** * @dataProvider data_quartersBetween */ public function test_quarters_between_until(LocalDate $start, Temporal $end, $expected) { $this->assertEquals($start->until($end, IsoFields::QUARTER_YEARS()), $expected); }