Ejemplo n.º 1
0
 public function resolve(FieldValues $fieldValues, TemporalAccessor $partialTemporal, ResolverStyle $resolverStyle)
 {
     $yearLong = $fieldValues->get(ChronoField::YEAR());
     $qoyLong = $fieldValues->get(IsoFields::QUARTER_OF_YEAR());
     if ($yearLong === null || $qoyLong === null) {
         return null;
     }
     $y = ChronoField::YEAR()->checkValidIntValue($yearLong);
     // always validate
     $doq = $fieldValues->get(IsoFields::DAY_OF_QUARTER());
     IsoFields::ensureIso($partialTemporal);
     if ($resolverStyle == ResolverStyle::LENIENT()) {
         $date = LocalDate::of($y, 1, 1)->plusMonths(Math::multiplyExact(Math::subtractExact($qoyLong, 1), 3));
         $doq = Math::subtractExact($doq, 1);
     } else {
         $qoy = IsoFields::QUARTER_OF_YEAR()->range()->checkValidIntValue($qoyLong, IsoFields::QUARTER_OF_YEAR());
         // validated
         $date = LocalDate::of($y, ($qoy - 1) * 3 + 1, 1);
         if ($doq < 1 || $doq > 90) {
             if ($resolverStyle == ResolverStyle::STRICT()) {
                 $this->rangeRefinedBy($date)->checkValidValue($doq, $this);
                 // only allow exact range
             } else {
                 // SMART
                 $this->range()->checkValidValue($doq, $this);
                 // allow 1-92 rolling into next quarter
             }
         }
         $doq--;
     }
     $fieldValues->remove($this);
     $fieldValues->remove(ChronoField::YEAR());
     $fieldValues->remove(IsoFields::QUARTER_OF_YEAR());
     return $date->plusDays($doq);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider data_parseLenientQuarter
  */
 public function test_parse_parseLenientQuarter_LENIENT($str, LocalDate $expected, $smart)
 {
     $f = (new DateTimeFormatterBuilder())->appendValue(CF::YEAR())->appendLiteral(':')->appendValue(IsoFields::QUARTER_OF_YEAR())->appendLiteral(':')->appendValue(IsoFields::DAY_OF_QUARTER())->toFormatter()->withResolverStyle(ResolverStyle::LENIENT());
     $parsed = LocalDate::parseWith($str, $f);
     $this->assertEquals($parsed, $expected);
 }
Ejemplo n.º 3
0
 public function test_nullLocaleTemporalFieldDisplayName()
 {
     TestHelper::assertNullException($this, function () {
         // Test the default method in TemporalField using the
         // IsoFields.DAY_OF_QUARTER which does not override getDisplayName
         IsoFields::DAY_OF_QUARTER()->getDisplayName(null);
     });
 }