public function test_appendTextMapIncomplete()
 {
     $map = [1, "JNY"];
     $this->builder->appendText3(ChronoField::MONTH_OF_YEAR(), $map);
     $f = $this->builder->toFormatter();
     $dt = LocalDateTime::of(2010, 2, 1, 0, 0);
     $this->assertEquals($f->format($dt), "2");
 }
 public function test_parse_decoratedEmpty_lenient()
 {
     $this->builder->parseLenient()->padNext2(4, '-')->optionalStart()->appendValue(ChronoField::DAY_OF_MONTH())->optionalEnd();
     $parsed = $this->builder->toFormatter()->parseUnresolved("----", $this->pos);
     $this->assertEquals($this->pos->getIndex(), 4);
     $this->assertEquals($this->pos->getErrorIndex(), -1);
     $this->assertNotNull($parsed);
 }
 /**
  * @dataProvider data_print
  */
 public function test_print_pattern_x_($offsetPattern, $noOffset, LocalDateTime $ldt, ZoneId $zone, $expected)
 {
     $pattern = null;
     $zero = null;
     if ($offsetPattern === "+HHmm" && $noOffset === "Z") {
         $pattern = "x";
         $zero = "+00";
     } else {
         if ($offsetPattern === "+HHMM" && $noOffset === "Z") {
             $pattern = "xx";
             $zero = "+0000";
         } else {
             if ($offsetPattern === "+HH:MM" && $noOffset === "Z") {
                 $pattern = "xxx";
                 $zero = "+00:00";
             } else {
                 if ($offsetPattern === "+HHMMss" && $noOffset === "Z") {
                     $pattern = "xxxx";
                     $zero = "+0000";
                 } else {
                     if ($offsetPattern === "+HH:MM:ss" && $noOffset === "Z") {
                         $pattern = "xxxxx";
                         $zero = "+00:00";
                     }
                 }
             }
         }
     }
     if ($pattern != null) {
         $zdt = $ldt->atZone($zone);
         $this->builder->appendPattern($pattern);
         $output = $this->builder->toFormatter()->format($zdt);
         $this->assertEquals($output, $expected === "Z" ? $zero : $expected);
     }
 }
 public function test_padOptional()
 {
     $this->builder->appendValue(ChronoField::MONTH_OF_YEAR())->appendLiteral(':')->padNext(5)->optionalStart()->appendValue(ChronoField::DAY_OF_MONTH())->optionalEnd()->appendLiteral(':')->appendValue(ChronoField::YEAR());
     $this->assertEquals($this->builder->toFormatter()->format(LocalDate::of(2013, 2, 1)), "2:    1:2013");
     $this->assertEquals($this->builder->toFormatter()->format(YearMonth::of(2013, 2)), "2:     :2013");
 }
Ejemplo n.º 5
0
 /**
  * @dataProvider provider_printAdjacent
  */
 public function test_printAdjacent($pattern, $text, $year, $month, $day)
 {
     $builder = new DateTimeFormatterBuilder();
     $builder->appendPattern($pattern);
     $dtf = $builder->toFormatter();
     $ld = LocalDate::of($year, $month, $day);
     $actual = $dtf->format($ld);
     $this->assertEquals($text, $actual, "formatter output: " . $dtf);
 }
 /**
  * @dataProvider data_combine
  */
 public function test_derive($field1, $value1, $field2, $value2, $field3, $value3, $field4, $value4, $query, $expectedVal)
 {
     $str = "";
     $dtfb = new DateTimeFormatterBuilder();
     $dtfb->appendValue($field1)->appendLiteral('-');
     $str .= $value1 . "-";
     if ($field2 != null) {
         $dtfb->appendValue($field2)->appendLiteral('-');
         $str .= $value2 . "-";
     }
     if ($field3 != null) {
         $dtfb->appendValue($field3)->appendLiteral('-');
         $str .= $value3 . "-";
     }
     if ($field4 != null) {
         $dtfb->appendValue($field4)->appendLiteral('-');
         $str .= $value4 . "-";
     }
     $parsed = $dtfb->toFormatter()->parse($str);
     if ($query == LocalDate::class) {
         if ($expectedVal != null) {
             $this->assertEquals($parsed->query(LocalDate::fromQuery()), $expectedVal);
         } else {
             try {
                 $parsed->query(LocalDate::fromQuery());
                 $this->fail();
             } catch (DateTimeException $ex) {
                 // expected
             }
         }
     } else {
         throw new IllegalArgumentException();
     }
 }
 /**
  * @dataProvider data_parseSuccess
  */
 public function test_parseSuccess_caseInsensitive($text, $expectedIndex, $expectedErrorIndex, $expected)
 {
     $this->builder->parseCaseInsensitive()->appendZoneId();
     $lcText = strtolower($text);
     $parsed = $this->builder->toFormatter()->parseUnresolved($lcText, $this->pos);
     $this->assertEquals($this->pos->getErrorIndex(), $expectedErrorIndex, "Incorrect error index parsing: " . $lcText);
     $this->assertEquals($this->pos->getIndex(), $expectedIndex, "Incorrect index parsing: " . $lcText);
     if ($expected !== null) {
         $zid = $parsed->query(TemporalQueries::zoneId());
         $this->assertEquals($parsed->query(TemporalQueries::zoneId()), $expected, "Incorrect zoneId parsing: " . $lcText);
         $this->assertEquals($parsed->query(TemporalQueries::offset()), null, "Incorrect offset parsing: " . $lcText);
         $this->assertEquals($parsed->query(TemporalQueries::zone()), $expected, "Incorrect zone parsing: " . $lcText);
     } else {
         $this->assertEquals($parsed, null);
     }
 }
 /**
  * @dataProvider dataValid
  */
 public function test_appendPattern_valid($input, $expected)
 {
     $this->builder->appendPattern($input);
     $f = $this->builder->toFormatter();
     $this->assertEquals($f->__toString(), $expected);
 }