Esempio n. 1
0
 public function test_factory_parse_formatter_nullFormatter()
 {
     TestHelper::assertNullException($this, function () {
         LocalDate::parseWith("ANY", null);
     });
 }
Esempio n. 2
0
 /**
  * @dataProvider data_parseLenientWeek
  */
 public function test_parse_parseLenientWeek_LENIENT($str, LocalDate $expected, $smart)
 {
     $f = (new DateTimeFormatterBuilder())->appendValue(IsoFields::WEEK_BASED_YEAR())->appendLiteral(':')->appendValue(IsoFields::WEEK_OF_WEEK_BASED_YEAR())->appendLiteral(':')->appendValue(CF::DAY_OF_WEEK())->toFormatter()->withResolverStyle(ResolverStyle::LENIENT());
     $parsed = LocalDate::parseWith($str, $f);
     $this->assertEquals($parsed, $expected);
 }
 /**
  * @dataProvider provider_patternLocalWeekBasedYearDate
  */
 public function test_parse_WeekBasedYear($pattern, $text, $pos, $expectedPos, LocalDate $expectedValue)
 {
     $ppos = new ParsePosition($pos);
     $b = (new DateTimeFormatterBuilder())->appendPattern($pattern);
     $dtf = $b->toFormatter2($this->locale);
     $parsed = $dtf->parseUnresolved($text, $ppos);
     if ($ppos->getErrorIndex() != -1) {
         $this->assertEquals($ppos->getErrorIndex(), $expectedPos);
     } else {
         $weekDef = WeekFields::ofLocale($this->locale);
         $this->assertEquals($ppos->getIndex(), $expectedPos, "Incorrect ending parse position");
         $this->assertEquals($parsed->isSupported($weekDef->dayOfWeek()), strpos($pattern, 'e') >= 0);
         $this->assertEquals($parsed->isSupported($weekDef->weekOfWeekBasedYear()), strpos($pattern, 'w') >= 0);
         $this->assertEquals($parsed->isSupported($weekDef->weekBasedYear()), strpos($pattern, 'Y') >= 0);
         // ensure combination resolves into a date
         $result = LocalDate::parseWith($text, $dtf);
         $this->assertEquals($result, $expectedValue, "LocalDate incorrect for " . $pattern . ", {$weekDef}: " . $weekDef);
     }
 }
 /**
  * @dataProvider data_weekFields
  * @group long
  */
 public function test_parse_resolve_localizedWoWBYDow_lenient(DayOfWeek $firstDayOfWeek, $minDays)
 {
     $date = LocalDate::of(2012, 12, 31);
     $week = WeekFields::of($firstDayOfWeek, $minDays);
     $dowField = $week->dayOfWeek();
     $wowbyField = $week->weekOfWeekBasedYear();
     $yowbyField = $week->weekBasedYear();
     for ($i = 1; $i <= 60; $i++) {
         $f = (new DateTimeFormatterBuilder())->appendValue($yowbyField)->appendLiteral(':')->appendValue($wowbyField)->appendLiteral(':')->appendValue($dowField)->toFormatter()->withResolverStyle(ResolverStyle::LENIENT());
         $wowby = $date->get($wowbyField);
         $dow = $date->get($dowField);
         for ($j = $wowby - 60; $j < $wowby + 60; $j++) {
             $str = $date->get($yowbyField) . ":" . $j . ":" . $dow;
             $parsed = LocalDate::parseWith($str, $f);
             $this->assertEquals($parsed, $date->plusWeeks($j - $wowby), " ::" . $str . ": :" . $i . "::" . $j);
         }
         $date = $date->plusDays(1);
     }
 }
 /**
  * @dataProvider data_samples
  */
 public function test_samples_parse_LENIENT(TemporalField $field, LocalDate $date, $value)
 {
     $f = (new DateTimeFormatterBuilder())->appendValue($field)->toFormatter()->withResolverStyle(ResolverStyle::LENIENT());
     $parsed = LocalDate::parseWith(strval($value), $f);
     $this->assertEquals($parsed, $date);
 }