public function eras() { return [IsoEra::BCE(), IsoEra::CE()]; }
*/ public static function of($isoEra) { switch ($isoEra) { case 0: return self::$BCE; case 1: return self::$CE; default: throw new DateTimeException("Invalid era: " . $isoEra); } } //----------------------------------------------------------------------- /** * Gets the numeric era {@code int} value. * <p> * The era BCE has the value 0, while the era CE has the value 1. * * @return int the era value, from 0 (BCE) to 1 (CE) */ public function getValue() { return $this->val; } public function __toString() { return $this->val === 0 ? 'BCE' : 'CE'; } } IsoEra::init();
public function test_with() { $base = Year::of(5); $result = $base->with(ChronoField::ERA(), 0); $ad = $base->adjust(IsoEra::of(0)); $this->assertEquals($result, $ad); $prolepticYear = IsoChronology::INSTANCE()->prolepticYear(IsoEra::of(0), 5); $this->assertEquals($result->get(ChronoField::ERA()), 0); $this->assertEquals($result->get(ChronoField::YEAR()), $prolepticYear); $this->assertEquals($result->get(ChronoField::YEAR_OF_ERA()), 5); $result = $base->with(ChronoField::YEAR(), 10); $this->assertEquals($result->get(ChronoField::ERA()), $base->get(ChronoField::ERA())); $this->assertEquals($result->get(ChronoField::YEAR()), 10); $this->assertEquals($result->get(ChronoField::YEAR_OF_ERA()), 10); $result = $base->with(ChronoField::YEAR_OF_ERA(), 20); $this->assertEquals($result->get(ChronoField::ERA()), $base->get(ChronoField::ERA())); $this->assertEquals($result->get(ChronoField::YEAR()), 20); $this->assertEquals($result->get(ChronoField::YEAR_OF_ERA()), 20); }