public function dateFrom(TemporalAccessor $temporal) { if ($temporal instanceof ThaiBuddhistDate) { return $temporal; } return ThaiBuddhistDate::ofIsoDate(LocalDate::from($temporal)); }
public function test_reducedWithLateChronoChange() { $date = ThaiBuddhistDate::of(2543, 1, 1); $df = (new DateTimeFormatterBuilder())->appendValueReduced2(ChronoField::YEAR(), 2, 2, LocalDate::of(2000, 1, 1))->appendLiteral(" ")->appendChronologyId()->toFormatter(); $expected = $date->get(ChronoField::YEAR()); $input = $df->format($date); $pos = new ParsePosition(0); $parsed = $df->parseUnresolved($input, $pos); $this->assertEquals($pos->getIndex(), strlen($input), "Input not parsed completely"); $this->assertEquals($pos->getErrorIndex(), -1, "Error index should be -1 (no-error)"); $actual = $parsed->get(ChronoField::YEAR()); $this->assertEquals($expected, $actual, sprintf("Wrong date parsed, chrono: %s, input: %s", $parsed->query(TemporalQueries::chronology()), $input)); }